From b5bcb90ec49673376041bad4ce50a9d53d53c1aa Mon Sep 17 00:00:00 2001 From: Paradoxe Ngwasi Date: Tue, 16 Jan 2024 08:38:39 +0000 Subject: [PATCH 1/9] implement organization-team-join validate on frontend --- apps/web/app/api/organization-team-join/validate/route.ts | 4 +++- apps/web/app/services/client/api/request-to-join-team.ts | 6 +----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/web/app/api/organization-team-join/validate/route.ts b/apps/web/app/api/organization-team-join/validate/route.ts index 8ef997a76..04820cf7e 100644 --- a/apps/web/app/api/organization-team-join/validate/route.ts +++ b/apps/web/app/api/organization-team-join/validate/route.ts @@ -5,5 +5,7 @@ import { NextResponse } from 'next/server'; export async function POST(req: Request) { const body = (await req.json()) as IValidateRequestToJoin; - return NextResponse.json(await validateRequestToJoinRequest(body)); + const response = await validateRequestToJoinRequest(body); + + return NextResponse.json(response.data); } diff --git a/apps/web/app/services/client/api/request-to-join-team.ts b/apps/web/app/services/client/api/request-to-join-team.ts index a2630e504..d36a9c65b 100644 --- a/apps/web/app/services/client/api/request-to-join-team.ts +++ b/apps/web/app/services/client/api/request-to-join-team.ts @@ -4,7 +4,6 @@ import { IDataResponse, ISuccessResponse, IValidateRequestToJoin, - CreateResponse, PaginationResponse, IRequestToJoinActionEnum } from '@app/interfaces'; @@ -29,10 +28,7 @@ export function requestToJoinAPI(data: IRequestToJoinCreate) { } export function validateRequestToJoinAPI(data: IValidateRequestToJoin) { - return api.post>>( - '/organization-team-join/validate', - data - ); + return post>('/organization-team-join/validate', data); } export function resendCodeRequestToJoinAPI(data: IRequestToJoinCreate) { From 1718e9caee7d57b004d4959eaf2fb33a19fe2b61 Mon Sep 17 00:00:00 2001 From: Paradoxe Ngwasi Date: Tue, 16 Jan 2024 09:47:32 +0000 Subject: [PATCH 2/9] implement organization-team-join resend-code api on frontend --- apps/web/app/api/organization-team-join/resend-code/route.ts | 4 +++- apps/web/app/services/client/api/request-to-join-team.ts | 2 +- apps/web/components/layout/header/request-to-join-modal.tsx | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/web/app/api/organization-team-join/resend-code/route.ts b/apps/web/app/api/organization-team-join/resend-code/route.ts index 18ff21df6..31a2a62c6 100644 --- a/apps/web/app/api/organization-team-join/resend-code/route.ts +++ b/apps/web/app/api/organization-team-join/resend-code/route.ts @@ -5,5 +5,7 @@ import { NextResponse } from 'next/server'; export async function POST(req: Request) { const body = (await req.json()) as IRequestToJoinCreate; - return NextResponse.json(await resendCodeRequestToJoinRequest(body)); + const response = await resendCodeRequestToJoinRequest(body); + + return NextResponse.json(response.data); } diff --git a/apps/web/app/services/client/api/request-to-join-team.ts b/apps/web/app/services/client/api/request-to-join-team.ts index d36a9c65b..11ccc3daf 100644 --- a/apps/web/app/services/client/api/request-to-join-team.ts +++ b/apps/web/app/services/client/api/request-to-join-team.ts @@ -32,7 +32,7 @@ export function validateRequestToJoinAPI(data: IValidateRequestToJoin) { } export function resendCodeRequestToJoinAPI(data: IRequestToJoinCreate) { - return api.post>('/organization-team-join/resend-code', data); + return post>('/organization-team-join/resend-code', data); } export function acceptRejectRequestToJoinAPI(id: string, action: IRequestToJoinActionEnum) { diff --git a/apps/web/components/layout/header/request-to-join-modal.tsx b/apps/web/components/layout/header/request-to-join-modal.tsx index a980898a7..55d7e2b88 100644 --- a/apps/web/components/layout/header/request-to-join-modal.tsx +++ b/apps/web/components/layout/header/request-to-join-modal.tsx @@ -190,7 +190,7 @@ const BecomeMember = ({ closeModal }: { closeModal: any }) => { organizationTeamId: requestToJoinPayload.organizationTeamId, code: formValues.code }).then((res) => { - if (res.data.email && res.data.organizationTeamId) { + if (res.email && res.organizationTeamId) { closeModal(); } setErrors({ From 14eeada4660a41009db4dac307a7834499532018 Mon Sep 17 00:00:00 2001 From: Paradoxe Ngwasi Date: Tue, 16 Jan 2024 10:25:39 +0000 Subject: [PATCH 3/9] implement GET /tags api on frontend --- apps/web/app/api/tags/route.ts | 4 +++- apps/web/app/hooks/features/useTaskLabels.ts | 2 +- apps/web/app/services/client/api/task-labels.ts | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/web/app/api/tags/route.ts b/apps/web/app/api/tags/route.ts index c86ebf135..a4c659498 100644 --- a/apps/web/app/api/tags/route.ts +++ b/apps/web/app/api/tags/route.ts @@ -30,5 +30,7 @@ export async function POST(req: Request) { if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); - return $res(await createLabelsRequest(body, access_token, body?.tenantId)); + const response = await createLabelsRequest(body, access_token, body?.tenantId); + + return $res(response.data); } diff --git a/apps/web/app/hooks/features/useTaskLabels.ts b/apps/web/app/hooks/features/useTaskLabels.ts index 779222388..eb5de8f87 100644 --- a/apps/web/app/hooks/features/useTaskLabels.ts +++ b/apps/web/app/hooks/features/useTaskLabels.ts @@ -69,7 +69,7 @@ export function useTaskLabels() { }, user?.tenantId || '' ).then((res) => { - if (res?.data?.data && res?.data?.data?.name) { + if (res?.data && res?.data?.name) { queryCall( user?.tenantId as string, user?.employee?.organizationId as string, diff --git a/apps/web/app/services/client/api/task-labels.ts b/apps/web/app/services/client/api/task-labels.ts index 828fd9489..969e259ee 100644 --- a/apps/web/app/services/client/api/task-labels.ts +++ b/apps/web/app/services/client/api/task-labels.ts @@ -5,10 +5,10 @@ import { ITaskLabelsItemList, PaginationResponse } from '@app/interfaces'; -import api, { get } from '../axios'; +import api, { get, post } from '../axios'; export function createTaskLabelsAPI(data: ITaskLabelsCreate, tenantId?: string) { - return api.post>('/tags', data, { + return post('/tags', data, { headers: { 'Tenant-Id': tenantId } From a08f35f7f477a50e033af44b394468ddaffb6984 Mon Sep 17 00:00:00 2001 From: Paradoxe Ngwasi Date: Tue, 16 Jan 2024 10:37:59 +0000 Subject: [PATCH 4/9] implement PUT organization-team-join api on frontend --- .../[id]/[action]/route.ts | 16 ++++++++-------- .../client/api/request-to-join-team.ts | 4 ++-- apps/web/app/services/client/axios.ts | 19 ++++++++++++++++++- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/apps/web/app/api/organization-team-join/[id]/[action]/route.ts b/apps/web/app/api/organization-team-join/[id]/[action]/route.ts index d649458b3..251f06eb0 100644 --- a/apps/web/app/api/organization-team-join/[id]/[action]/route.ts +++ b/apps/web/app/api/organization-team-join/[id]/[action]/route.ts @@ -11,13 +11,13 @@ export async function PUT(req: Request, { params }: { params: { id: string; acti const { id, action } = params; if (id) { - return $res( - await acceptRejectRequestToJoinRequest({ - id: id as string, - bearer_token: access_token, - tenantId, - action: action as IRequestToJoinActionEnum - }) - ); + const response = await acceptRejectRequestToJoinRequest({ + id: id as string, + bearer_token: access_token, + tenantId, + action: action as IRequestToJoinActionEnum + }); + + return $res(response.data); } } diff --git a/apps/web/app/services/client/api/request-to-join-team.ts b/apps/web/app/services/client/api/request-to-join-team.ts index 11ccc3daf..3cc34c10b 100644 --- a/apps/web/app/services/client/api/request-to-join-team.ts +++ b/apps/web/app/services/client/api/request-to-join-team.ts @@ -7,7 +7,7 @@ import { PaginationResponse, IRequestToJoinActionEnum } from '@app/interfaces'; -import api, { get, post } from '../axios'; +import { get, post, put } from '../axios'; import { getOrganizationIdCookie, getTenantIdCookie } from '@app/helpers'; export function getRequestToJoinAPI() { @@ -36,5 +36,5 @@ export function resendCodeRequestToJoinAPI(data: IRequestToJoinCreate) { } export function acceptRejectRequestToJoinAPI(id: string, action: IRequestToJoinActionEnum) { - return api.put>(`/organization-team-join/${id}/${action}`); + return put>(`/organization-team-join/${id}/${action}`); } diff --git a/apps/web/app/services/client/axios.ts b/apps/web/app/services/client/axios.ts index 6c35076ae..f355fc9a8 100644 --- a/apps/web/app/services/client/axios.ts +++ b/apps/web/app/services/client/axios.ts @@ -132,6 +132,23 @@ function post(url: string, data?: Record | FormData, config?: AP return baseURL && directAPI ? apiDirect.post(url, data, { ...config, headers }) : api.post(url, data); } -export { get, post, deleteApi }; +function put(url: string, data?: Record | FormData, config?: APIConfig) { + const { baseURL, headers, tenantId, organizationId } = apiConfig(config); + const { directAPI = true } = config || {}; + + if (baseURL && directAPI && data && !(data instanceof FormData)) { + if (!data.tenantId) { + data.tenantId = tenantId; + } + + if (!data.organizationId) { + data.organizationId = organizationId; + } + } + + return baseURL && directAPI ? apiDirect.put(url, data, { ...config, headers }) : api.put(url, data); +} + +export { get, post, deleteApi, put }; export default api; From 558e7003fa7384f3438903c402de8deca1dd000c Mon Sep 17 00:00:00 2001 From: Paradoxe Ngwasi Date: Tue, 16 Jan 2024 10:53:15 +0000 Subject: [PATCH 5/9] implement PUT tags/:id api on frontend --- apps/web/app/api/tags/[id]/route.ts | 20 +++++++++---------- .../app/services/client/api/task-labels.ts | 16 ++++----------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/apps/web/app/api/tags/[id]/route.ts b/apps/web/app/api/tags/[id]/route.ts index cc2703a2d..b431938b9 100644 --- a/apps/web/app/api/tags/[id]/route.ts +++ b/apps/web/app/api/tags/[id]/route.ts @@ -3,7 +3,7 @@ import { authenticatedGuard } from '@app/services/server/guards/authenticated-gu import { deleteTaskLabelsRequest, editTaskLabelsRequest } from '@app/services/server/requests'; import { NextResponse } from 'next/server'; -export async function DELETE(req: Request, { params }: { params: { id: string } }) { +export async function DELETE(req: Request, { params }: { params: { id: string } }) { const res = new NextResponse(); const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); @@ -20,7 +20,7 @@ export async function DELETE(req: Request, { params }: { params: { id: string } ); } -export async function PUT(req: Request, { params }: { params: { id: string } }) { +export async function PUT(req: Request, { params }: { params: { id: string } }) { const body = (await req.json()) as unknown as ITaskLabelsCreate; const res = new NextResponse(); const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); @@ -29,12 +29,12 @@ export async function PUT(req: Request, { params }: { params: { id: string } }) const { id } = params; - return $res( - await editTaskLabelsRequest({ - id, - datas: body, - bearer_token: access_token, - tenantId - }) - ); + const response = await editTaskLabelsRequest({ + id, + datas: body, + bearer_token: access_token, + tenantId + }); + + return $res(response.data); } diff --git a/apps/web/app/services/client/api/task-labels.ts b/apps/web/app/services/client/api/task-labels.ts index 969e259ee..f346c8862 100644 --- a/apps/web/app/services/client/api/task-labels.ts +++ b/apps/web/app/services/client/api/task-labels.ts @@ -1,11 +1,5 @@ -import { - CreateResponse, - DeleteResponse, - ITaskLabelsCreate, - ITaskLabelsItemList, - PaginationResponse -} from '@app/interfaces'; -import api, { get, post } from '../axios'; +import { DeleteResponse, ITaskLabelsCreate, ITaskLabelsItemList, PaginationResponse } from '@app/interfaces'; +import api, { get, post, put } from '../axios'; export function createTaskLabelsAPI(data: ITaskLabelsCreate, tenantId?: string) { return post('/tags', data, { @@ -16,10 +10,8 @@ export function createTaskLabelsAPI(data: ITaskLabelsCreate, tenantId?: string) } export function editTaskLabelsAPI(id: string, data: ITaskLabelsCreate, tenantId?: string) { - return api.put>(`/tags/${id}`, data, { - headers: { - 'Tenant-Id': tenantId - } + return put(`/tags/${id}`, data, { + tenantId }); } From 763fdce4f6b0aed65ae1f60bb77b78cf6332bb23 Mon Sep 17 00:00:00 2001 From: Paradoxe Ngwasi Date: Tue, 16 Jan 2024 11:01:27 +0000 Subject: [PATCH 6/9] implement DELETE tags/:id api on frontend --- apps/web/app/api/tags/[id]/route.ts | 14 +++++++------- apps/web/app/services/client/api/task-labels.ts | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/web/app/api/tags/[id]/route.ts b/apps/web/app/api/tags/[id]/route.ts index b431938b9..2b676f239 100644 --- a/apps/web/app/api/tags/[id]/route.ts +++ b/apps/web/app/api/tags/[id]/route.ts @@ -11,13 +11,13 @@ export async function DELETE(req: Request, { params }: { params: { id: string } const { id } = params; - return $res( - await deleteTaskLabelsRequest({ - id, - bearer_token: access_token, - tenantId - }) - ); + const response = await deleteTaskLabelsRequest({ + id, + bearer_token: access_token, + tenantId + }); + + return $res(response.data); } export async function PUT(req: Request, { params }: { params: { id: string } }) { diff --git a/apps/web/app/services/client/api/task-labels.ts b/apps/web/app/services/client/api/task-labels.ts index f346c8862..401e4c3bf 100644 --- a/apps/web/app/services/client/api/task-labels.ts +++ b/apps/web/app/services/client/api/task-labels.ts @@ -1,5 +1,5 @@ import { DeleteResponse, ITaskLabelsCreate, ITaskLabelsItemList, PaginationResponse } from '@app/interfaces'; -import api, { get, post, put } from '../axios'; +import { deleteApi, get, post, put } from '../axios'; export function createTaskLabelsAPI(data: ITaskLabelsCreate, tenantId?: string) { return post('/tags', data, { @@ -16,7 +16,7 @@ export function editTaskLabelsAPI(id: string, data: ITaskLabelsCreate, tenantId? } export function deleteTaskLabelsAPI(id: string) { - return api.delete(`/tags/${id}`); + return deleteApi(`/tags/${id}`); } export async function getTaskLabelsList(tenantId: string, organizationId: string, organizationTeamId: string | null) { From e5720ed8ae0902c35ab802cb76529a9190b38215 Mon Sep 17 00:00:00 2001 From: Paradoxe Ngwasi Date: Tue, 16 Jan 2024 11:45:35 +0000 Subject: [PATCH 7/9] implement POST /task-priorities api on frontend --- apps/web/app/api/task-priorities/route.ts | 4 +++- apps/web/app/services/client/api/task-priorities.ts | 8 +++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/web/app/api/task-priorities/route.ts b/apps/web/app/api/task-priorities/route.ts index de09a1472..1ba254b66 100644 --- a/apps/web/app/api/task-priorities/route.ts +++ b/apps/web/app/api/task-priorities/route.ts @@ -32,5 +32,7 @@ export async function POST(req: Request) { const body = (await req.json()) as unknown as ITaskPrioritiesCreate; - return $res(await createPrioritiesRequest(body, access_token, body?.tenantId)); + const response = await createPrioritiesRequest(body, access_token, body?.tenantId); + + return $res(response.data); } diff --git a/apps/web/app/services/client/api/task-priorities.ts b/apps/web/app/services/client/api/task-priorities.ts index 4437c4694..95c45bc5d 100644 --- a/apps/web/app/services/client/api/task-priorities.ts +++ b/apps/web/app/services/client/api/task-priorities.ts @@ -5,13 +5,11 @@ import { ITaskPrioritiesItemList, PaginationResponse } from '@app/interfaces'; -import api, { get } from '../axios'; +import api, { get, post } from '../axios'; export function createTaskPrioritiesAPI(data: ITaskPrioritiesCreate, tenantId?: string) { - return api.post>('/task-priorities', data, { - headers: { - 'Tenant-Id': tenantId - } + return post('/task-priorities', data, { + tenantId }); } From 5f5204c35c22a6f73f66b40c2ae4bbfd5ac1cec0 Mon Sep 17 00:00:00 2001 From: Paradoxe Ngwasi Date: Tue, 16 Jan 2024 11:53:34 +0000 Subject: [PATCH 8/9] implement PUT task-priorities/:id api on frontend --- .../web/app/api/task-priorities/[id]/route.ts | 23 +++++++++---------- .../app/hooks/features/useTaskPriorities.ts | 4 ++-- .../services/client/api/task-priorities.ts | 16 ++++--------- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/apps/web/app/api/task-priorities/[id]/route.ts b/apps/web/app/api/task-priorities/[id]/route.ts index 36396543f..a32723b97 100644 --- a/apps/web/app/api/task-priorities/[id]/route.ts +++ b/apps/web/app/api/task-priorities/[id]/route.ts @@ -3,33 +3,32 @@ import { authenticatedGuard } from '@app/services/server/guards/authenticated-gu import { deleteTaskPrioritiesRequest, editTaskPrioritiesRequest } from '@app/services/server/requests'; import { NextResponse } from 'next/server'; -export async function PUT(req: Request, { params }: { params: { id: string } }) { +export async function PUT(req: Request, { params }: { params: { id: string } }) { const res = new NextResponse(); const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); if (!user) return $res('Unauthorized'); - const { id } = params; const datas = (await req.json()) as unknown as ITaskPrioritiesCreate; - return $res( - await editTaskPrioritiesRequest({ - id, - datas, - bearer_token: access_token, - tenantId - }) - ); + + const response = await editTaskPrioritiesRequest({ + id, + datas, + bearer_token: access_token, + tenantId + }); + + return $res(response.data); } -export async function DELETE(req: Request, { params }: { params: { id: string } }) { +export async function DELETE(req: Request, { params }: { params: { id: string } }) { const res = new NextResponse(); const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); if (!user) return $res('Unauthorized'); - const { id } = params; return $res( diff --git a/apps/web/app/hooks/features/useTaskPriorities.ts b/apps/web/app/hooks/features/useTaskPriorities.ts index 8a2a4d66b..4d60b24b7 100644 --- a/apps/web/app/hooks/features/useTaskPriorities.ts +++ b/apps/web/app/hooks/features/useTaskPriorities.ts @@ -96,7 +96,7 @@ export function useTaskPriorities() { const editTaskPriorities = useCallback( (id: string, data: ITaskPrioritiesCreate) => { if (user?.tenantId) { - return editQueryCall(id, data, user?.tenantId || '').then((res) => { + return editQueryCall(id, data, user?.tenantId || '').then((eRes) => { queryCall( user?.tenantId as string, user?.employee?.organizationId as string, @@ -105,7 +105,7 @@ export function useTaskPriorities() { setTaskPriorities(res?.data?.items || []); return res; }); - return res; + return eRes; }); } }, diff --git a/apps/web/app/services/client/api/task-priorities.ts b/apps/web/app/services/client/api/task-priorities.ts index 95c45bc5d..4662193a0 100644 --- a/apps/web/app/services/client/api/task-priorities.ts +++ b/apps/web/app/services/client/api/task-priorities.ts @@ -1,11 +1,5 @@ -import { - CreateResponse, - DeleteResponse, - ITaskPrioritiesCreate, - ITaskPrioritiesItemList, - PaginationResponse -} from '@app/interfaces'; -import api, { get, post } from '../axios'; +import { DeleteResponse, ITaskPrioritiesCreate, ITaskPrioritiesItemList, PaginationResponse } from '@app/interfaces'; +import api, { get, post, put } from '../axios'; export function createTaskPrioritiesAPI(data: ITaskPrioritiesCreate, tenantId?: string) { return post('/task-priorities', data, { @@ -14,10 +8,8 @@ export function createTaskPrioritiesAPI(data: ITaskPrioritiesCreate, tenantId?: } export function editTaskPrioritiesAPI(id: string, data: ITaskPrioritiesCreate, tenantId?: string) { - return api.put>(`/task-priorities/${id}`, data, { - headers: { - 'Tenant-Id': tenantId - } + return put(`/task-priorities/${id}`, data, { + tenantId }); } From de34d6a77f76feb0642833db41684b27cdb7e7ad Mon Sep 17 00:00:00 2001 From: Paradoxe Ngwasi Date: Tue, 16 Jan 2024 11:56:42 +0000 Subject: [PATCH 9/9] implement PUT /task-priorities api on frontend --- apps/web/app/api/task-priorities/[id]/route.ts | 14 +++++++------- .../web/app/services/client/api/task-priorities.ts | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/web/app/api/task-priorities/[id]/route.ts b/apps/web/app/api/task-priorities/[id]/route.ts index a32723b97..94f779cc2 100644 --- a/apps/web/app/api/task-priorities/[id]/route.ts +++ b/apps/web/app/api/task-priorities/[id]/route.ts @@ -31,11 +31,11 @@ export async function DELETE(req: Request, { params }: { params: { id: string } const { id } = params; - return $res( - await deleteTaskPrioritiesRequest({ - id, - bearer_token: access_token, - tenantId - }) - ); + const response = await deleteTaskPrioritiesRequest({ + id, + bearer_token: access_token, + tenantId + }); + + return $res(response.data); } diff --git a/apps/web/app/services/client/api/task-priorities.ts b/apps/web/app/services/client/api/task-priorities.ts index 4662193a0..35f8d1b46 100644 --- a/apps/web/app/services/client/api/task-priorities.ts +++ b/apps/web/app/services/client/api/task-priorities.ts @@ -1,5 +1,5 @@ import { DeleteResponse, ITaskPrioritiesCreate, ITaskPrioritiesItemList, PaginationResponse } from '@app/interfaces'; -import api, { get, post, put } from '../axios'; +import { deleteApi, get, post, put } from '../axios'; export function createTaskPrioritiesAPI(data: ITaskPrioritiesCreate, tenantId?: string) { return post('/task-priorities', data, { @@ -14,7 +14,7 @@ export function editTaskPrioritiesAPI(id: string, data: ITaskPrioritiesCreate, t } export function deleteTaskPrioritiesAPI(id: string) { - return api.delete(`/task-priorities/${id}`); + return deleteApi(`/task-priorities/${id}`); } export async function getTaskPrioritiesList(