From e8457d8e2cb31cc80908b37684d7886d28edebf2 Mon Sep 17 00:00:00 2001 From: Loi Phan Date: Wed, 1 Nov 2023 11:11:29 +0700 Subject: [PATCH] Fix format code style --- hotel-management/src/constants/messages.ts | 2 ++ hotel-management/src/constants/variables.ts | 5 ++++- hotel-management/src/globals/types.ts | 5 +++-- hotel-management/src/helpers/utils.ts | 23 +++++++++------------ 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/hotel-management/src/constants/messages.ts b/hotel-management/src/constants/messages.ts index 7ddb73a..0b9531e 100644 --- a/hotel-management/src/constants/messages.ts +++ b/hotel-management/src/constants/messages.ts @@ -10,6 +10,7 @@ const ADD_SUCCESS = 'Add success'; const EDIT_SUCCESS = 'Edit success'; const CONFIRM_DELETE = 'Are you sure to delete it?'; const DELETE_SUCCESS = 'Delete success'; +const REQUIRED_FIELD_ERROR = 'This is required field'; export { invalidFormatMsg, @@ -18,4 +19,5 @@ export { EDIT_SUCCESS, CONFIRM_DELETE, DELETE_SUCCESS, + REQUIRED_FIELD_ERROR, }; diff --git a/hotel-management/src/constants/variables.ts b/hotel-management/src/constants/variables.ts index 1c03d65..b3b169a 100644 --- a/hotel-management/src/constants/variables.ts +++ b/hotel-management/src/constants/variables.ts @@ -74,4 +74,7 @@ const ROOM_PAGE = { ], } -export { USER_PAGE, ROOM_PAGE }; +const VALUE = 'value'; +const ERROR = 'error'; + +export { USER_PAGE, ROOM_PAGE, VALUE, ERROR }; diff --git a/hotel-management/src/globals/types.ts b/hotel-management/src/globals/types.ts index 3937295..d7176a0 100644 --- a/hotel-management/src/globals/types.ts +++ b/hotel-management/src/globals/types.ts @@ -25,10 +25,10 @@ type TStateSchema = { }; type TKeyValue = { - [key: string]: string | undefined | boolean | number; + [key: string]: boolean | undefined | string; }; -export type Test = { +type TKeyString = { [key: string]: string; }; @@ -54,6 +54,7 @@ export type { TRoom, TStateSchema, TKeyValue, + TKeyString, TPropValues, TValidator, TResponse, diff --git a/hotel-management/src/helpers/utils.ts b/hotel-management/src/helpers/utils.ts index bdba669..af150a9 100644 --- a/hotel-management/src/helpers/utils.ts +++ b/hotel-management/src/helpers/utils.ts @@ -1,12 +1,13 @@ // Constants -import { invalidFormatMsg } from '../constants/messages'; +import { REQUIRED_FIELD_ERROR, invalidFormatMsg } from '../constants/messages'; // Types -import { TKeyValue, TPropValues, TStateSchema, Test } from '../globals/types'; - -const VALUE = 'value'; -const ERROR = 'error'; -const REQUIRED_FIELD_ERROR = 'This is required field'; +import { + TKeyString, + TKeyValue, + TPropValues, + TStateSchema, +} from '../globals/types'; const isBool = (value: unknown) => { return typeof value === 'boolean'; @@ -47,20 +48,18 @@ const addValidator = ({ validatorFunc, prop, required = true }: TValidator) => { }; }; -const getValueFromObj = (obj: T | null = null): Test => { +const getValueFromObj = (obj: T | null = null): TKeyString => { let result = {}; if (obj) { for (const key of Object.keys(obj)) { const tempValue = obj[key as keyof typeof obj]; const value: string | boolean | number = - typeof tempValue === 'boolean' || - typeof tempValue === 'string' || - typeof tempValue === 'number' + typeof tempValue === 'boolean' || typeof tempValue === 'string' ? tempValue : ''; - result = { ...result, [`${key}Value`]: value }; + result = { ...result, [`${key}Value`]: value as string }; } } @@ -112,7 +111,5 @@ export { getValueFromObj, addValidator, searchQuery, - VALUE, - ERROR, REQUIRED_FIELD_ERROR, };