You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
780 B
37 lines
780 B
import { ClientIds } from 'config/clients/types'
|
|
import { getApiUrl } from '../config/routes'
|
|
|
|
const errorLexics = {
|
|
5: '',
|
|
10: '',
|
|
}
|
|
|
|
type FailedResponse = {
|
|
error: {
|
|
code: keyof typeof errorLexics,
|
|
message?: string,
|
|
},
|
|
ok: false,
|
|
}
|
|
|
|
type SuccessResponse = {
|
|
ok: true,
|
|
}
|
|
|
|
export const changePassword = async (currentClientId: ClientIds, password: string) => {
|
|
const url = getApiUrl('/change_password')
|
|
const init: RequestInit = {
|
|
body: new URLSearchParams({
|
|
client_id: currentClientId,
|
|
password,
|
|
}),
|
|
method: 'PUT',
|
|
}
|
|
const response = await fetch(url, init)
|
|
|
|
const body: SuccessResponse | FailedResponse = await response.json()
|
|
|
|
if (body.ok) return Promise.resolve()
|
|
|
|
return Promise.reject(errorLexics[body.error.code])
|
|
}
|
|
|