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/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/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/api/tags/[id]/route.ts b/apps/web/app/api/tags/[id]/route.ts index cc2703a2d..2b676f239 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); @@ -11,16 +11,16 @@ 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 } }) { +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/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/api/task-priorities/[id]/route.ts b/apps/web/app/api/task-priorities/[id]/route.ts index 36396543f..94f779cc2 100644 --- a/apps/web/app/api/task-priorities/[id]/route.ts +++ b/apps/web/app/api/task-priorities/[id]/route.ts @@ -3,40 +3,39 @@ 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( - 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/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/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/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/request-to-join-team.ts b/apps/web/app/services/client/api/request-to-join-team.ts index a2630e504..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 @@ -4,11 +4,10 @@ import { IDataResponse, ISuccessResponse, IValidateRequestToJoin, - CreateResponse, 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() { @@ -29,16 +28,13 @@ 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) { - return api.post>('/organization-team-join/resend-code', data); + return post>('/organization-team-join/resend-code', data); } 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/api/task-labels.ts b/apps/web/app/services/client/api/task-labels.ts index 828fd9489..401e4c3bf 100644 --- a/apps/web/app/services/client/api/task-labels.ts +++ b/apps/web/app/services/client/api/task-labels.ts @@ -1,14 +1,8 @@ -import { - CreateResponse, - DeleteResponse, - ITaskLabelsCreate, - ITaskLabelsItemList, - PaginationResponse -} from '@app/interfaces'; -import api, { get } from '../axios'; +import { DeleteResponse, ITaskLabelsCreate, ITaskLabelsItemList, PaginationResponse } from '@app/interfaces'; +import { deleteApi, get, post, put } from '../axios'; export function createTaskLabelsAPI(data: ITaskLabelsCreate, tenantId?: string) { - return api.post>('/tags', data, { + return post('/tags', data, { headers: { 'Tenant-Id': tenantId } @@ -16,15 +10,13 @@ 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 }); } 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) { diff --git a/apps/web/app/services/client/api/task-priorities.ts b/apps/web/app/services/client/api/task-priorities.ts index 4437c4694..35f8d1b46 100644 --- a/apps/web/app/services/client/api/task-priorities.ts +++ b/apps/web/app/services/client/api/task-priorities.ts @@ -1,30 +1,20 @@ -import { - CreateResponse, - DeleteResponse, - ITaskPrioritiesCreate, - ITaskPrioritiesItemList, - PaginationResponse -} from '@app/interfaces'; -import api, { get } from '../axios'; +import { DeleteResponse, ITaskPrioritiesCreate, ITaskPrioritiesItemList, PaginationResponse } from '@app/interfaces'; +import { deleteApi, get, post, put } 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 }); } 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 }); } export function deleteTaskPrioritiesAPI(id: string) { - return api.delete(`/task-priorities/${id}`); + return deleteApi(`/task-priorities/${id}`); } export async function getTaskPrioritiesList( 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; 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({