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/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/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/api/organization-team-employee/[id]/route.ts b/apps/web/app/api/organization-team-employee/[id]/route.ts index 654aebb94..1d5b2e580 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); } } @@ -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/api/role-permissions/[id]/route.ts b/apps/web/app/api/role-permissions/[id]/route.ts index 4dea0195c..6ceb4941c 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) { @@ -29,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/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/organization-projects.ts b/apps/web/app/services/client/api/organization-projects.ts index 84f4c5d64..1f2d7243f 100644 --- a/apps/web/app/services/client/api/organization-projects.ts +++ b/apps/web/app/services/client/api/organization-projects.ts @@ -1,18 +1,14 @@ import { IProject } from '@app/interfaces'; -import api from '../axios'; +import { 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 }); } 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 }); } 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..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,7 @@ import { IOrganizationTeamEmployeeUpdate } from '@app/interfaces'; -import { CreateResponse } from '@app/interfaces/IDataResponse'; import { IOrganizationTeam } from '@app/interfaces/IOrganizationTeam'; -import api from '../axios'; +import { deleteApi, put } from '../axios'; +import { getActiveTeamIdCookie } from '@app/helpers'; export function deleteOrganizationEmployeeTeamAPI({ id, @@ -14,21 +14,20 @@ 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}` ); } 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( id: string, data: Partial ) { - return api.put>( - `/organization-team-employee/${id}/active-task`, - data - ); + return put(`/organization-team-employee/${id}/active-task`, data); } diff --git a/apps/web/app/services/client/api/role-permissions.ts b/apps/web/app/services/client/api/role-permissions.ts index c55ee84be..127d8f0ad 100644 --- a/apps/web/app/services/client/api/role-permissions.ts +++ b/apps/web/app/services/client/api/role-permissions.ts @@ -1,10 +1,23 @@ import { IRolePermissions, PaginationResponse } from '@app/interfaces/'; -import api from '../axios'; +import { get, put } 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) { - return api.put(`/role-permissions/${data.id}`, data); + return put(`/role-permissions/${data.id}`, 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; } }