From 1b0b2f00104b8a43e8a545001f9f324a8faaec47 Mon Sep 17 00:00:00 2001 From: Loi Phan Date: Mon, 20 Nov 2023 09:44:10 +0700 Subject: [PATCH] Update helpers and types folder --- hotel-management/src/helpers/helper.ts | 56 +-------- hotel-management/src/helpers/sendRequest.ts | 37 ------ hotel-management/src/helpers/validators.ts | 19 +-- .../src/styles/abstracts/variables.css | 1 + hotel-management/src/types/responses.ts | 7 -- hotel-management/src/types/rooms.ts | 2 - hotel-management/src/types/supabase.ts | 110 ++++++++++++++++++ hotel-management/src/types/users.ts | 2 - 8 files changed, 114 insertions(+), 120 deletions(-) delete mode 100644 hotel-management/src/helpers/sendRequest.ts delete mode 100644 hotel-management/src/types/responses.ts create mode 100644 hotel-management/src/types/supabase.ts diff --git a/hotel-management/src/helpers/helper.ts b/hotel-management/src/helpers/helper.ts index f16cf6e..51e74f9 100644 --- a/hotel-management/src/helpers/helper.ts +++ b/hotel-management/src/helpers/helper.ts @@ -1,47 +1,3 @@ -// Constants -import { REQUIRED_FIELD_ERROR } from '../constants/formValidateMessage'; - -/** - * Create query url for search - * @param columnSearch Column want to search - * @param keySearch Keyword search - * @param sort Sort by - * @param order Order by - * @returns Return query url - */ -const searchQuery = ( - columnSearch: string, - keySearch: string, - sort: string, - order: string -) => { - const phoneParams = keySearch - ? `${columnSearch}_like=` + keySearch - : ''; - const sortParams = sort - ? '_sort=' + sort - : ''; - const orderParams = order - ? '_order=' + order - : ''; - const finalParam = [phoneParams, sortParams, orderParams]; - let query = ''; - let isFirstParam = true; - - finalParam.forEach((param) => { - if (param) { - if (isFirstParam) { - query = query.concat('', param); - isFirstParam = false; - } else { - query = query.concat('&', param); - } - } - }); - - return query; -}; - /** * Convert value to currency format with value * @param value Value need to be converted @@ -54,14 +10,4 @@ const formatCurrency = (value: number): string => { }).format(value); }; -/** - * Create error string - * @param errorCode Error code - * @param msg Message error - * @returns Return the full error string - */ -const errorMsg = (errorCode: number, msg: string) => { - return `Error code: ${errorCode}. Message: ${msg}`; -}; - -export { errorMsg, searchQuery, formatCurrency, REQUIRED_FIELD_ERROR }; +export { formatCurrency }; diff --git a/hotel-management/src/helpers/sendRequest.ts b/hotel-management/src/helpers/sendRequest.ts deleted file mode 100644 index 717f7f0..0000000 --- a/hotel-management/src/helpers/sendRequest.ts +++ /dev/null @@ -1,37 +0,0 @@ -// Constants -import { BASE_URL } from '@constant/path'; - -// Types -import { IResponse } from '@type/responses'; - -type TMethodRequest = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'; - -/** - * The send request method to the server - * @param path The path of URL - * @param body The content will push on - * @param method HTTP method - * @returns The status code and message from server - */ -export const sendRequest = async ( - path: string, - method: TMethodRequest = 'GET', - body?: BodyInit -): Promise> => { - const response = await fetch(BASE_URL + path, { - method, - body, - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - }, - }); - - const data = (await response.json()) as T; - - return { - statusCode: response.status, - msg: response.statusText, - data, - }; -}; diff --git a/hotel-management/src/helpers/validators.ts b/hotel-management/src/helpers/validators.ts index 25ecace..ae1869b 100644 --- a/hotel-management/src/helpers/validators.ts +++ b/hotel-management/src/helpers/validators.ts @@ -6,7 +6,7 @@ */ const isValidRegex = (regex: RegExp, value: string): boolean => { return regex.test(value); -} +}; /** * Check value is valid discount or not @@ -17,7 +17,6 @@ const isValidDiscount = (value: number): boolean => { return value >= 0 && value <= 100; }; - /** * Check value is valid string or not * @param value Value need to be checked @@ -27,18 +26,4 @@ const isValidString = (value: string): boolean => { return value.trim().length >= 5; }; -/** - * Check object is empty or not - * @param obj Object need to be check - * @returns A boolean indicating whether or not the argument has valid - */ -const isEmptyObj = (obj: object) => { - return Object.keys(obj).length === 0; -}; - -export { - isValidRegex, - isValidString, - isValidDiscount, - isEmptyObj, -}; +export { isValidRegex, isValidString, isValidDiscount }; diff --git a/hotel-management/src/styles/abstracts/variables.css b/hotel-management/src/styles/abstracts/variables.css index 648a503..8e38691 100644 --- a/hotel-management/src/styles/abstracts/variables.css +++ b/hotel-management/src/styles/abstracts/variables.css @@ -6,6 +6,7 @@ --secondary-btn-color: #d1d1d1; --disabled-btn-color: #7f82a6; + --danger-btn-color: #ff4f4f; --hover-background-color: #f3f4f6; --hover-dark-background-color: #d0d0d0; diff --git a/hotel-management/src/types/responses.ts b/hotel-management/src/types/responses.ts deleted file mode 100644 index 2ea9981..0000000 --- a/hotel-management/src/types/responses.ts +++ /dev/null @@ -1,7 +0,0 @@ -interface IResponse { - statusCode: number; - msg: string; - data?: T; -} - -export type { IResponse }; diff --git a/hotel-management/src/types/rooms.ts b/hotel-management/src/types/rooms.ts index 4b6cd19..63234af 100644 --- a/hotel-management/src/types/rooms.ts +++ b/hotel-management/src/types/rooms.ts @@ -2,8 +2,6 @@ interface IRoom { id: number; name: string; price: number; - discount: number; - finalPrice: number; status: boolean; } diff --git a/hotel-management/src/types/supabase.ts b/hotel-management/src/types/supabase.ts new file mode 100644 index 0000000..b5203da --- /dev/null +++ b/hotel-management/src/types/supabase.ts @@ -0,0 +1,110 @@ +export type Json = + | string + | number + | boolean + | null + | { [key: string]: Json | undefined } + | Json[] + +export interface Database { + public: { + Tables: { + bookings: { + Row: { + amount: number + endDate: string + id: number + roomId: number + startDate: string + status: boolean + userId: number + } + Insert: { + amount: number + endDate: string + id?: number + roomId: number + startDate: string + status: boolean + userId: number + } + Update: { + amount?: number + endDate?: string + id?: number + roomId?: number + startDate?: string + status?: boolean + userId?: number + } + Relationships: [ + { + foreignKeyName: "bookings_roomId_fkey" + columns: ["roomId"] + isOneToOne: false + referencedRelation: "rooms" + referencedColumns: ["id"] + }, + { + foreignKeyName: "bookings_userId_fkey" + columns: ["userId"] + isOneToOne: false + referencedRelation: "users" + referencedColumns: ["id"] + } + ] + } + rooms: { + Row: { + id: number + name: string + price: number + status: boolean + } + Insert: { + id?: number + name: string + price: number + status: boolean + } + Update: { + id?: number + name?: string + price?: number + status?: boolean + } + Relationships: [] + } + users: { + Row: { + id: number + name: string + phone: string + } + Insert: { + id?: number + name: string + phone: string + } + Update: { + id?: number + name?: string + phone?: string + } + Relationships: [] + } + } + Views: { + [_ in never]: never + } + Functions: { + [_ in never]: never + } + Enums: { + [_ in never]: never + } + CompositeTypes: { + [_ in never]: never + } + } +} diff --git a/hotel-management/src/types/users.ts b/hotel-management/src/types/users.ts index 6d4a5b2..1725420 100644 --- a/hotel-management/src/types/users.ts +++ b/hotel-management/src/types/users.ts @@ -1,9 +1,7 @@ interface IUser { id: number; name: string; - identifiedCode: string; phone: string; - roomId: number; } export type { IUser };