-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add react-query to super admin (#182)
* feat: add react-query to super admin * feat: remove unnecessary async
- Loading branch information
Showing
18 changed files
with
306 additions
and
188 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
packages/web-ui/api/requests/super-admin/admin-add-ai-model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Endpoints from '@/api/endpoints'; | ||
import { superAdminApiClient } from '@/api/superAdminApiClient'; | ||
import { SuperAdminAddAiModelRequestDto } from '@/contract/ai/super-admin-add-ai-model.request.dto.d'; | ||
import { SuperAdminAiModelResponseDto } from '@/contract/ai/super-admin-ai-model.response.dto.d'; | ||
|
||
export const adminAddAiModel = async ( | ||
values: SuperAdminAddAiModelRequestDto, | ||
superAdminEmail: string, | ||
superAdminPassword: string | ||
) => { | ||
return new Promise<SuperAdminAiModelResponseDto>(async (resolve, reject) => { | ||
const res = await superAdminApiClient({ | ||
url: Endpoints.admin.addAiModel(), | ||
options: { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
...values, | ||
}), | ||
}, | ||
superAdminEmail, | ||
superAdminPassword, | ||
}); | ||
|
||
if (!res.ok) { | ||
const { error } = JSON.parse(await res.text()); | ||
return reject(error); | ||
} | ||
|
||
resolve(await res.json()); | ||
}); | ||
}; |
28 changes: 28 additions & 0 deletions
28
packages/web-ui/api/requests/super-admin/admin-get-ai-models.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Endpoints from '@/api/endpoints'; | ||
import { superAdminApiClient } from '@/api/superAdminApiClient'; | ||
import { SuperAdminAiModelResponseDto } from '@/contract/ai/super-admin-ai-model.response.dto.d'; | ||
|
||
export const ADMIN_GET_AI_MODELS_REQ_KEY = 'admin-ai-models'; | ||
|
||
export const adminGetAiModels = async ( | ||
superAdminEmail: string, | ||
superAdminPassword: string | ||
) => { | ||
return new Promise<SuperAdminAiModelResponseDto[]>( | ||
async (resolve, reject) => { | ||
const res = await superAdminApiClient({ | ||
url: Endpoints.admin.getAiModels(), | ||
options: { method: 'GET' }, | ||
superAdminEmail, | ||
superAdminPassword, | ||
}); | ||
|
||
if (!res.ok) { | ||
const { error } = JSON.parse(await res.text()); | ||
return reject(error); | ||
} | ||
|
||
resolve(await res.json()); | ||
} | ||
); | ||
}; |
26 changes: 26 additions & 0 deletions
26
packages/web-ui/api/requests/super-admin/admin-get-all-users.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Endpoints from '@/api/endpoints'; | ||
import { superAdminApiClient } from '@/api/superAdminApiClient'; | ||
import { UserResponseDto } from '@/contract/auth/user.response.dto.d'; | ||
|
||
export const ADMIN_GET_ALL_USERS_REQ_KEY = 'admin-all-users'; | ||
|
||
export const adminGetAllUsers = async ( | ||
superAdminEmail: string, | ||
superAdminPassword: string | ||
) => { | ||
return new Promise<UserResponseDto[]>(async (resolve, reject) => { | ||
const res = await superAdminApiClient({ | ||
url: Endpoints.admin.getUsers(), | ||
options: { method: 'GET' }, | ||
superAdminEmail, | ||
superAdminPassword, | ||
}); | ||
|
||
if (!res.ok) { | ||
const { error } = JSON.parse(await res.text()); | ||
return reject(error); | ||
} | ||
|
||
resolve(await res.json()); | ||
}); | ||
}; |
33 changes: 33 additions & 0 deletions
33
packages/web-ui/api/requests/super-admin/update-user-roles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Endpoints from '@/api/endpoints'; | ||
import { superAdminApiClient } from '@/api/superAdminApiClient'; | ||
import { SuperAdminUpdateUserRoleRequestDto } from '@/contract/auth/super-admin-update-role.request.dto.d'; | ||
import { UserResponseDto } from '@/contract/auth/user.response.dto.d'; | ||
|
||
export const updateUserRoles = async ( | ||
userId: string, | ||
values: Omit<SuperAdminUpdateUserRoleRequestDto, 'userId'>, | ||
superAdminEmail: string, | ||
superAdminPassword: string | ||
) => { | ||
return new Promise<UserResponseDto>(async (resolve, reject) => { | ||
const res = await superAdminApiClient({ | ||
url: Endpoints.admin.updateUserRoles(), | ||
options: { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
userId, | ||
...values, | ||
}), | ||
}, | ||
superAdminEmail, | ||
superAdminPassword, | ||
}); | ||
|
||
if (!res.ok) { | ||
const { error } = JSON.parse(await res.text()); | ||
return reject(error); | ||
} | ||
|
||
resolve(await res.json()); | ||
}); | ||
}; |
21 changes: 21 additions & 0 deletions
21
packages/web-ui/api/requests/super-admin/validate-admin-credentials.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Endpoints from '@/api/endpoints'; | ||
import { superAdminApiClient } from '@/api/superAdminApiClient'; | ||
import { SuperAdminValidateCredentialsRequestDto } from '@/contract/auth/super-admin-validate-credentials.request.dto.d'; | ||
|
||
export const validateAdminCredentials = async ( | ||
values: SuperAdminValidateCredentialsRequestDto | ||
) => { | ||
return new Promise<void>(async (resolve, reject) => { | ||
const res = await superAdminApiClient({ | ||
url: Endpoints.admin.validateCredentials(), | ||
options: { method: 'POST', body: JSON.stringify(values) }, | ||
}); | ||
|
||
if (!res.ok) { | ||
const { error } = JSON.parse(await res.text()); | ||
return reject(error); | ||
} | ||
|
||
resolve(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.