Implement add user function

This commit is contained in:
2023-10-29 13:19:01 +07:00
parent 372e6819dd
commit 4f24d9c6e2
12 changed files with 149 additions and 40 deletions
@@ -0,0 +1,29 @@
// Constants
import { BASE_URL } from '../constants/path';
import { TResponse } from '../globals/types';
type TMethodRequest = 'GET' | 'POST' | 'PUT' | 'DELETE';
export const sendRequest = async (
path: string,
body: BodyInit | null | undefined,
method: TMethodRequest = 'GET',
): Promise<TResponse> => {
const controller = new AbortController();
const signal = controller.signal;
const response = await fetch(BASE_URL + path, {
method,
body,
headers: {
// prettier-ignore
'Accept': 'application/json',
'Content-Type': 'application/json',
},
signal,
});
return {
statusCode: response.status,
msg: response.statusText,
};
};
+2 -2
View File
@@ -1,4 +1,4 @@
import { invalidFormatMessage } from '../constants/messages';
import { INVALID_FORMAT_MSG } from '../constants/messages';
import { TKeyValue, TPropValues, TStateSchema } from '../globals/types';
const VALUE = 'value';
@@ -39,7 +39,7 @@ const addValidator = ({ validatorFunc, prop, required = true }: TValidator) => {
required,
validator: {
func: validatorFunc,
error: invalidFormatMessage(prop),
error: INVALID_FORMAT_MSG(prop),
},
};
};