From b7ad2e40056a76d8bdcd3af00e0824ecb8dbba8c Mon Sep 17 00:00:00 2001 From: kekefreedog <70959083+kekefreedog@users.noreply.github.com> Date: Tue, 16 Jan 2024 00:59:54 +0100 Subject: [PATCH] Fix Create issue and add datetime front class --- docs/Api/SchemaApiRequest.md | 8 +-- src/Controller/ApiV2Create.php | 2 +- src/Front/Library/Utility/DateTime.ts | 74 +++++++++++++++++++++++++++ src/Front/Types/index.d.ts | 1 + src/Front/index.ts | 1 + 5 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 src/Front/Library/Utility/DateTime.ts diff --git a/docs/Api/SchemaApiRequest.md b/docs/Api/SchemaApiRequest.md index ed3f6d9..b3e2b3e 100644 --- a/docs/Api/SchemaApiRequest.md +++ b/docs/Api/SchemaApiRequest.md @@ -1,7 +1,7 @@ --- runme: id: 01HJTNJC60GAMR6TQV7XXB1C5Z - version: v2.0 + version: v2.2 --- # ___Api___ __Schema of request__ @@ -26,6 +26,7 @@ let body = { filters: [ name: "Home" ], + data: object|Array sort: "asc", options: [ limit: 1 // Limit number of item by one, @@ -44,8 +45,9 @@ Batching allow you to send multiple requests as a single transaction. By default, supported request are : `create`, `delete`, `update` -Exemple : -```json +Exemple : + +```json {"id":"01HM7MGZ911E1CACD7M8SVYH1Z"} { "requests": [ { diff --git a/src/Controller/ApiV2Create.php b/src/Controller/ApiV2Create.php index ce15a01..f4b557b 100644 --- a/src/Controller/ApiV2Create.php +++ b/src/Controller/ApiV2Create.php @@ -39,7 +39,7 @@ public static function post():void { # Declare content $content = self::Model() - ->create($_POST ?? []) + ->create(Controller::getHttpRequestData()) ; # Set response diff --git a/src/Front/Library/Utility/DateTime.ts b/src/Front/Library/Utility/DateTime.ts new file mode 100644 index 0000000..e277ddd --- /dev/null +++ b/src/Front/Library/Utility/DateTime.ts @@ -0,0 +1,74 @@ +/** + * Utility + * + * Front TS Scrips for multiple tasks + * + * @package kzarshenas/crazyphp + * @author kekefreedog + * @copyright 2022-2023 Kévin Zarshenas + */ + +/** + * Dependances + */ + +/** + * Date Time + * + * Class for manipulate time + * + * @package kzarshenas/crazyphp + * @author kekefreedog + * @copyright 2022-2023 Kévin Zarshenas + */ +export default class DateTime { + + /** Publis static methods + ****************************************************** + */ + + /** + * + * @param date + * @returns {string} + */ + public static toUTCString = (date:Date):string => { + + // Define pad + const pad = (n:number) => n < 10 ? '0' + n : n; + + // Return + return date.getUTCFullYear() + '-' + + pad(date.getUTCMonth() + 1) + '-' + // Months are 0-indexed + pad(date.getUTCDate()) + ' ' + + pad(date.getUTCHours()) + ':' + + pad(date.getUTCMinutes()) + ':' + + pad(date.getUTCSeconds()) + ' UTC' + ; + + } + + /** + * + * @param date + * @returns {string} + */ + public static toISOString = (date:Date):string => { + + // Define pad + const pad = (n:number) => n < 10 ? '0' + n : n; + + // Return + return date.getUTCFullYear() + + '-' + pad(date.getUTCMonth() + 1) + + '-' + pad(date.getUTCDate()) + + 'T' + pad(date.getUTCHours()) + + ':' + pad(date.getUTCMinutes()) + + ':' + pad(date.getUTCSeconds()) + + '.' + String((date.getUTCMilliseconds() / 1000).toFixed(3)).slice(2, 5) + + 'Z'; + ; + + } + +} \ No newline at end of file diff --git a/src/Front/Types/index.d.ts b/src/Front/Types/index.d.ts index fd852e2..56873fe 100644 --- a/src/Front/Types/index.d.ts +++ b/src/Front/Types/index.d.ts @@ -16,6 +16,7 @@ import Crazypage from "./../Library/Crazypage"; */ export {default as Componentregister} from "./../Library/Componentregister"; export {default as NavigatorClient} from "./../Library/Navigator/Client"; +export {default as UtilityDateTime} from "./../Library/Utility/DateTime"; export {default as ColorSchema} from "./../Library/Utility/ColorSchema"; export {default as UtilityProcess} from "./../Library/Utility/Process"; export {default as UtilityObjects} from "./../Library/Utility/Objects"; diff --git a/src/Front/index.ts b/src/Front/index.ts index 697ce8e..f348ed2 100644 --- a/src/Front/index.ts +++ b/src/Front/index.ts @@ -13,6 +13,7 @@ */ export {default as Componentregister} from "./Library/Componentregister"; export {default as NavigatorClient} from "./Library/Navigator/Client"; +export {default as UtilityDateTime} from "./Library/Utility/DateTime"; export {default as ColorSchema} from "./Library/Utility/ColorSchema"; export {default as UtilityProcess} from "./Library/Utility/Process"; export {default as UtilityObjects} from "./Library/Utility/Objects";