From d25254a0237c47bc27b562df1673041e231ad352 Mon Sep 17 00:00:00 2001 From: Paradoxe Ngwasi Date: Thu, 18 Jan 2024 07:22:23 +0000 Subject: [PATCH 1/8] implement PUT organization-projects/setting/:id api on frontend --- .../setting/[id]/route.ts | 20 +++++++++---------- .../client/api/organization-projects.ts | 8 +++----- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/apps/web/app/api/organization-projects/setting/[id]/route.ts b/apps/web/app/api/organization-projects/setting/[id]/route.ts index 93c6816d2..830715142 100644 --- a/apps/web/app/api/organization-projects/setting/[id]/route.ts +++ b/apps/web/app/api/organization-projects/setting/[id]/route.ts @@ -10,15 +10,13 @@ export async function PUT(req: Request, { params }: { params: { id: string } }) const { id } = params; const body = await req.json(); - switch (req.method) { - case 'PUT': - return $res( - await editOrganizationProjectsSettingsRequest({ - bearer_token: access_token, - id, - datas: body, - tenantId - }) - ); - } + + const response = await editOrganizationProjectsSettingsRequest({ + bearer_token: access_token, + id, + datas: body, + tenantId + }); + + $res(response.data); } diff --git a/apps/web/app/services/client/api/organization-projects.ts b/apps/web/app/services/client/api/organization-projects.ts index 84f4c5d64..7239c4081 100644 --- a/apps/web/app/services/client/api/organization-projects.ts +++ b/apps/web/app/services/client/api/organization-projects.ts @@ -1,11 +1,9 @@ import { IProject } from '@app/interfaces'; -import api from '../axios'; +import api, { put } from '../axios'; export function editOrganizationProjectSettingAPI(id: string, data: any, tenantId?: string) { - return api.put(`/organization-projects/setting/${id}`, data, { - headers: { - 'Tenant-Id': tenantId - } + return put(`/organization-projects/setting/${id}`, data, { + tenantId }); } From 7552607f91c08503b88a94f1907108ff38118de5 Mon Sep 17 00:00:00 2001 From: Paradoxe Ngwasi Date: Thu, 18 Jan 2024 11:01:05 +0000 Subject: [PATCH 2/8] implement PUT organization-projects/:id api on frontend --- .../app/api/organization-projects/[id]/route.ts | 17 +++++++++-------- .../client/api/organization-projects.ts | 8 +++----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/apps/web/app/api/organization-projects/[id]/route.ts b/apps/web/app/api/organization-projects/[id]/route.ts index 88a982d9c..0b2242eb3 100644 --- a/apps/web/app/api/organization-projects/[id]/route.ts +++ b/apps/web/app/api/organization-projects/[id]/route.ts @@ -9,14 +9,15 @@ export async function PUT(req: Request, { params }: { params: { id: string } }) if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); const { id } = params; + const body = await req.json(); - return $res( - await editOrganizationProjectsRequest({ - bearer_token: access_token, - id, - datas: body, - tenantId - }) - ); + const response = await editOrganizationProjectsRequest({ + bearer_token: access_token, + id, + datas: body, + tenantId + }); + + return $res(response.data); } diff --git a/apps/web/app/services/client/api/organization-projects.ts b/apps/web/app/services/client/api/organization-projects.ts index 7239c4081..1f2d7243f 100644 --- a/apps/web/app/services/client/api/organization-projects.ts +++ b/apps/web/app/services/client/api/organization-projects.ts @@ -1,5 +1,5 @@ import { IProject } from '@app/interfaces'; -import api, { put } from '../axios'; +import { put } from '../axios'; export function editOrganizationProjectSettingAPI(id: string, data: any, tenantId?: string) { return put(`/organization-projects/setting/${id}`, data, { @@ -8,9 +8,7 @@ export function editOrganizationProjectSettingAPI(id: string, data: any, tenantI } export function editOrganizationProjectAPI(id: string, data: any, tenantId?: string) { - return api.put(`/organization-projects/${id}`, data, { - headers: { - 'Tenant-Id': tenantId - } + return put(`/organization-projects/${id}`, data, { + tenantId }); } From 4e1c84377f7244a66001e1516c9b59e0a4f71b6d Mon Sep 17 00:00:00 2001 From: Paradoxe Ngwasi Date: Thu, 18 Jan 2024 11:58:09 +0000 Subject: [PATCH 3/8] implement organization-team-employee/:id on frontend --- .../api/organization-team-employee/[id]/route.ts | 16 ++++++++-------- .../client/api/organization-team-employee.ts | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/web/app/api/organization-team-employee/[id]/route.ts b/apps/web/app/api/organization-team-employee/[id]/route.ts index 654aebb94..e2c1246b6 100644 --- a/apps/web/app/api/organization-team-employee/[id]/route.ts +++ b/apps/web/app/api/organization-team-employee/[id]/route.ts @@ -15,15 +15,15 @@ export async function PUT(req: Request, { params }: { params: { id: string } }) const { id } = params; + const response = await updateOrganizationTeamEmployeeRequest({ + id: id as string, + bearer_token: access_token, + tenantId, + body: body + }); + if (id) { - return $res( - await updateOrganizationTeamEmployeeRequest({ - id: id as string, - bearer_token: access_token, - tenantId, - body: body - }) - ); + return $res(response.data); } } diff --git a/apps/web/app/services/client/api/organization-team-employee.ts b/apps/web/app/services/client/api/organization-team-employee.ts index e14328d1a..7f081e50a 100644 --- a/apps/web/app/services/client/api/organization-team-employee.ts +++ b/apps/web/app/services/client/api/organization-team-employee.ts @@ -1,7 +1,7 @@ import { IOrganizationTeamEmployeeUpdate } from '@app/interfaces'; import { CreateResponse } from '@app/interfaces/IDataResponse'; import { IOrganizationTeam } from '@app/interfaces/IOrganizationTeam'; -import api from '../axios'; +import api, { put } from '../axios'; export function deleteOrganizationEmployeeTeamAPI({ id, @@ -20,7 +20,7 @@ export function deleteOrganizationEmployeeTeamAPI({ } export function updateOrganizationEmployeeTeamAPI(id: string, data: Partial) { - return api.put>(`/organization-team-employee/${id}`, data); + return put(`/organization-team-employee/${id}`, data); } export function updateOrganizationTeamEmployeeActiveTaskAPI( From cb652a1da310a1318e703d018c46b3e06670d4cd Mon Sep 17 00:00:00 2001 From: Paradoxe Ngwasi Date: Thu, 18 Jan 2024 12:06:48 +0000 Subject: [PATCH 4/8] implement organization-team-employee/:id api on frontend --- .../organization-team-employee/[id]/route.ts | 20 +++++++++---------- .../client/api/organization-team-employee.ts | 9 ++++++--- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/apps/web/app/api/organization-team-employee/[id]/route.ts b/apps/web/app/api/organization-team-employee/[id]/route.ts index e2c1246b6..1d5b2e580 100644 --- a/apps/web/app/api/organization-team-employee/[id]/route.ts +++ b/apps/web/app/api/organization-team-employee/[id]/route.ts @@ -37,16 +37,16 @@ export async function DELETE(req: Request, { params }: { params: { id: string } const { employeeId } = searchParams as unknown as { employeeId: string }; const { id } = params; + const response = await deleteOrganizationTeamEmployeeRequest({ + id: id as string, + bearer_token: access_token, + tenantId, + organizationId, + employeeId: employeeId as string, + organizationTeamId: teamId + }); + if (id) { - return $res( - await deleteOrganizationTeamEmployeeRequest({ - id: id as string, - bearer_token: access_token, - tenantId, - organizationId, - employeeId: employeeId as string, - organizationTeamId: teamId - }) - ); + return $res(response.data); } } diff --git a/apps/web/app/services/client/api/organization-team-employee.ts b/apps/web/app/services/client/api/organization-team-employee.ts index 7f081e50a..cace5d820 100644 --- a/apps/web/app/services/client/api/organization-team-employee.ts +++ b/apps/web/app/services/client/api/organization-team-employee.ts @@ -1,7 +1,8 @@ import { IOrganizationTeamEmployeeUpdate } from '@app/interfaces'; import { CreateResponse } from '@app/interfaces/IDataResponse'; import { IOrganizationTeam } from '@app/interfaces/IOrganizationTeam'; -import api, { put } from '../axios'; +import api, { deleteApi, put } from '../axios'; +import { getActiveTeamIdCookie } from '@app/helpers'; export function deleteOrganizationEmployeeTeamAPI({ id, @@ -14,8 +15,10 @@ export function deleteOrganizationEmployeeTeamAPI({ organizationId: string; tenantId: string; }) { - return api.delete>( - `/organization-team-employee/${id}?tenantId=${tenantId}&employeeId=${employeeId}&organizationId=${organizationId}` + const teamId = getActiveTeamIdCookie(); + + return deleteApi( + `/organization-team-employee/${id}?tenantId=${tenantId}&employeeId=${employeeId}&organizationId=${organizationId}&organizationTeamId=${teamId}` ); } From c9fe7071ae949eaea7ecccbb12ef0e0bac016521 Mon Sep 17 00:00:00 2001 From: Paradoxe Ngwasi Date: Thu, 18 Jan 2024 12:14:49 +0000 Subject: [PATCH 5/8] implement organization-team-employee/:id/active-task api frontend --- .../[id]/active-task/route.ts | 16 ++++++++-------- .../client/api/organization-team-employee.ts | 8 ++------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/apps/web/app/api/organization-team-employee/[id]/active-task/route.ts b/apps/web/app/api/organization-team-employee/[id]/active-task/route.ts index fddf8fbd6..5857a8804 100644 --- a/apps/web/app/api/organization-team-employee/[id]/active-task/route.ts +++ b/apps/web/app/api/organization-team-employee/[id]/active-task/route.ts @@ -12,13 +12,13 @@ export async function PUT(req: Request, { params }: { params: { id: string } }) const body = (await req.json()) as IOrganizationTeamEmployeeUpdate; if (id) { - return $res( - await updateOrganizationTeamEmployeeActiveTaskRequest({ - id: id as string, - bearer_token: access_token, - tenantId, - body - }) - ); + const response = await updateOrganizationTeamEmployeeActiveTaskRequest({ + id: id as string, + bearer_token: access_token, + tenantId, + body + }); + + return $res(response.data); } } diff --git a/apps/web/app/services/client/api/organization-team-employee.ts b/apps/web/app/services/client/api/organization-team-employee.ts index cace5d820..e4210ae25 100644 --- a/apps/web/app/services/client/api/organization-team-employee.ts +++ b/apps/web/app/services/client/api/organization-team-employee.ts @@ -1,7 +1,6 @@ import { IOrganizationTeamEmployeeUpdate } from '@app/interfaces'; -import { CreateResponse } from '@app/interfaces/IDataResponse'; import { IOrganizationTeam } from '@app/interfaces/IOrganizationTeam'; -import api, { deleteApi, put } from '../axios'; +import { deleteApi, put } from '../axios'; import { getActiveTeamIdCookie } from '@app/helpers'; export function deleteOrganizationEmployeeTeamAPI({ @@ -30,8 +29,5 @@ export function updateOrganizationTeamEmployeeActiveTaskAPI( id: string, data: Partial ) { - return api.put>( - `/organization-team-employee/${id}/active-task`, - data - ); + return put(`/organization-team-employee/${id}/active-task`, data); } From 59273b301350d3d257d957c48341c1988f2b787d Mon Sep 17 00:00:00 2001 From: Paradoxe Ngwasi Date: Thu, 18 Jan 2024 12:33:04 +0000 Subject: [PATCH 6/8] implement GET /role-permissions/:id api on frontend --- .../web/app/api/role-permissions/[id]/route.ts | 18 ++++++++---------- .../services/client/api/role-permissions.ts | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/apps/web/app/api/role-permissions/[id]/route.ts b/apps/web/app/api/role-permissions/[id]/route.ts index 4dea0195c..e21421189 100644 --- a/apps/web/app/api/role-permissions/[id]/route.ts +++ b/apps/web/app/api/role-permissions/[id]/route.ts @@ -2,7 +2,7 @@ import { authenticatedGuard } from '@app/services/server/guards/authenticated-gu import { getRolePermissionsRequest, updateRolePermissionRequest } from '@app/services/server/requests'; import { NextResponse } from 'next/server'; -export async function GET(req: Request, { params }: { params: { id: string } }) { +export async function GET(req: Request, { params }: { params: { id: string } }) { const res = new NextResponse(); const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); @@ -10,15 +10,13 @@ export async function GET(req: Request, { params }: { params: { id: string } }) const { id } = params; - return $res( - ( - await getRolePermissionsRequest({ - bearer_token: access_token, - tenantId, - roleId: id as string - }) - ).data - ); + const response = await getRolePermissionsRequest({ + bearer_token: access_token, + tenantId, + roleId: id as string + }); + + return $res(response.data); } export async function PUT(req: Request) { diff --git a/apps/web/app/services/client/api/role-permissions.ts b/apps/web/app/services/client/api/role-permissions.ts index c55ee84be..74e6e6783 100644 --- a/apps/web/app/services/client/api/role-permissions.ts +++ b/apps/web/app/services/client/api/role-permissions.ts @@ -1,8 +1,21 @@ import { IRolePermissions, PaginationResponse } from '@app/interfaces/'; -import api from '../axios'; +import api, { get } from '../axios'; +import { getTenantIdCookie } from '@app/helpers'; export function getRolePermissionAPI(id: string) { - return api.get>(`/role-permissions/${id}`); + const tenantId = getTenantIdCookie(); + + const params = { + data: JSON.stringify({ + findInput: { + roleId: id, + tenantId + } + }) + }; + const query = new URLSearchParams(params); + + return get>(`/role-permissions/${id}?${query.toString()}`); } export function updateRolePermissionAPI(data: IRolePermissions) { From b805b319644a28994fa7d47a7ad0ef639780f956 Mon Sep 17 00:00:00 2001 From: Paradoxe Ngwasi Date: Thu, 18 Jan 2024 12:41:07 +0000 Subject: [PATCH 7/8] implement PUT role-permissions/:id api on frontend --- apps/web/app/api/role-permissions/[id]/route.ts | 16 +++++++--------- .../app/services/client/api/role-permissions.ts | 4 ++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/apps/web/app/api/role-permissions/[id]/route.ts b/apps/web/app/api/role-permissions/[id]/route.ts index e21421189..6ceb4941c 100644 --- a/apps/web/app/api/role-permissions/[id]/route.ts +++ b/apps/web/app/api/role-permissions/[id]/route.ts @@ -27,13 +27,11 @@ export async function PUT(req: Request) { const body = await req.json(); - return $res( - ( - await updateRolePermissionRequest({ - bearer_token: access_token, - tenantId, - data: body - }) - ).data - ); + const response = await updateRolePermissionRequest({ + bearer_token: access_token, + tenantId, + data: body + }); + + return $res(response.data); } diff --git a/apps/web/app/services/client/api/role-permissions.ts b/apps/web/app/services/client/api/role-permissions.ts index 74e6e6783..127d8f0ad 100644 --- a/apps/web/app/services/client/api/role-permissions.ts +++ b/apps/web/app/services/client/api/role-permissions.ts @@ -1,5 +1,5 @@ import { IRolePermissions, PaginationResponse } from '@app/interfaces/'; -import api, { get } from '../axios'; +import { get, put } from '../axios'; import { getTenantIdCookie } from '@app/helpers'; export function getRolePermissionAPI(id: string) { @@ -19,5 +19,5 @@ export function getRolePermissionAPI(id: string) { } export function updateRolePermissionAPI(data: IRolePermissions) { - return api.put(`/role-permissions/${data.id}`, data); + return put(`/role-permissions/${data.id}`, data); } From 9642cc1c779b5b6f4407afdc06570b37bde26116 Mon Sep 17 00:00:00 2001 From: Paradoxe Ngwasi Date: Thu, 18 Jan 2024 13:20:39 +0000 Subject: [PATCH 8/8] implement POST /roles api on frontend --- apps/web/app/api/roles/route.ts | 38 +++++++++++------------ apps/web/app/services/client/api/roles.ts | 6 ++-- apps/web/app/services/client/axios.ts | 4 +-- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/apps/web/app/api/roles/route.ts b/apps/web/app/api/roles/route.ts index cc4a1fe87..39d7a8761 100644 --- a/apps/web/app/api/roles/route.ts +++ b/apps/web/app/api/roles/route.ts @@ -9,32 +9,30 @@ export async function GET(req: Request) { const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); if (!user) return $res('unauthorized'); - return $res( - ( - await getRolesRequest({ - bearer_token: access_token, - tenantId - }) - ).data - ); + const response = await getRolesRequest({ + bearer_token: access_token, + tenantId + }); + + return $res(response.data); } export async function POST(req: Request) { const res = new NextResponse(); const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + const body = (await req.json()) as IRole; + if (!user) return $res('unauthorized'); - return $res( - ( - await createRoleRequest({ - bearer_token: access_token, - tenantId, - data: { - ...body, - tenantId - } - }) - ).data - ); + const response = await createRoleRequest({ + bearer_token: access_token, + tenantId, + data: { + ...body, + tenantId + } + }); + + return $res(response.data); } diff --git a/apps/web/app/services/client/api/roles.ts b/apps/web/app/services/client/api/roles.ts index 5e3999383..c1e88d5ab 100644 --- a/apps/web/app/services/client/api/roles.ts +++ b/apps/web/app/services/client/api/roles.ts @@ -1,12 +1,12 @@ import { IRole, PaginationResponse } from '@app/interfaces'; -import api from '../axios'; +import api, { get, post } from '../axios'; export function getRolesAPI() { - return api.get>('/roles'); + return get>('/roles'); } export function createRoleAPI(data: IRole) { - return api.post('/roles', data); + return post('/roles', data); } export function deleteRoleAPI(id: string) { diff --git a/apps/web/app/services/client/axios.ts b/apps/web/app/services/client/axios.ts index f355fc9a8..a940e724f 100644 --- a/apps/web/app/services/client/axios.ts +++ b/apps/web/app/services/client/axios.ts @@ -120,11 +120,11 @@ function post(url: string, data?: Record | FormData, config?: AP const { directAPI = true } = config || {}; if (baseURL && directAPI && data && !(data instanceof FormData)) { - if (!data.tenantId) { + if (!data.tenantId && data.tenantId !== null) { data.tenantId = tenantId; } - if (!data.organizationId) { + if (!data.organizationId && data.organizationId !== null) { data.organizationId = organizationId; } }