|
|
|
|
@ -1,13 +1,17 @@ |
|
|
|
|
import { DATA_URL, PROCEDURES } from 'config' |
|
|
|
|
import { callApi } from 'helpers' |
|
|
|
|
import { callApiBase } from 'helpers' |
|
|
|
|
|
|
|
|
|
const proc = PROCEDURES.create_user |
|
|
|
|
|
|
|
|
|
const responseStatus = { |
|
|
|
|
FAILURE: 2, |
|
|
|
|
const statusCodes = { |
|
|
|
|
EMAIL_IN_USE: 2, |
|
|
|
|
SUCCESS: 1, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const errorMessages = { |
|
|
|
|
[statusCodes.EMAIL_IN_USE]: 'error_email_already_in_use', |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type Response = { |
|
|
|
|
_p_error: string | null, |
|
|
|
|
_p_status: 1 | 2, |
|
|
|
|
@ -32,14 +36,19 @@ export const register = async ({ |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const response: Response = await callApi({ |
|
|
|
|
config, |
|
|
|
|
url: DATA_URL, |
|
|
|
|
}) |
|
|
|
|
try { |
|
|
|
|
const response = await callApiBase({ |
|
|
|
|
config, |
|
|
|
|
url: DATA_URL, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
if (response._p_status === responseStatus.SUCCESS) { |
|
|
|
|
return Promise.resolve(response) |
|
|
|
|
} |
|
|
|
|
const { _p_status }: Response = await response.json() |
|
|
|
|
|
|
|
|
|
return Promise.reject(response._p_error) |
|
|
|
|
if (_p_status === statusCodes.SUCCESS) { |
|
|
|
|
return Promise.resolve(response) |
|
|
|
|
} |
|
|
|
|
return Promise.reject(errorMessages[_p_status]) |
|
|
|
|
} catch { |
|
|
|
|
return Promise.reject() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|