Skip to content

Commit

Permalink
Merge pull request #2101 from ever-co/feat/static-build-support-5
Browse files Browse the repository at this point in the history
Feat/Next-Frontend APIs
  • Loading branch information
evereq authored Jan 18, 2024
2 parents aa6f46e + 9642cc1 commit 0e2eda4
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 110 deletions.
17 changes: 9 additions & 8 deletions apps/web/app/api/organization-projects/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
20 changes: 9 additions & 11 deletions apps/web/app/api/organization-projects/setting/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
36 changes: 18 additions & 18 deletions apps/web/app/api/organization-team-employee/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}
34 changes: 15 additions & 19 deletions apps/web/app/api/role-permissions/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ 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);

if (!user) return $res('unauthorized');

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) {
Expand All @@ -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);
}
38 changes: 18 additions & 20 deletions apps/web/app/api/roles/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
14 changes: 5 additions & 9 deletions apps/web/app/services/client/api/organization-projects.ts
Original file line number Diff line number Diff line change
@@ -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<any>(`/organization-projects/setting/${id}`, data, {
headers: {
'Tenant-Id': tenantId
}
return put<any>(`/organization-projects/setting/${id}`, data, {
tenantId
});
}

export function editOrganizationProjectAPI(id: string, data: any, tenantId?: string) {
return api.put<IProject>(`/organization-projects/${id}`, data, {
headers: {
'Tenant-Id': tenantId
}
return put<IProject>(`/organization-projects/${id}`, data, {
tenantId
});
}
17 changes: 8 additions & 9 deletions apps/web/app/services/client/api/organization-team-employee.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -14,21 +14,20 @@ export function deleteOrganizationEmployeeTeamAPI({
organizationId: string;
tenantId: string;
}) {
return api.delete<CreateResponse<IOrganizationTeam>>(
`/organization-team-employee/${id}?tenantId=${tenantId}&employeeId=${employeeId}&organizationId=${organizationId}`
const teamId = getActiveTeamIdCookie();

return deleteApi<IOrganizationTeam>(
`/organization-team-employee/${id}?tenantId=${tenantId}&employeeId=${employeeId}&organizationId=${organizationId}&organizationTeamId=${teamId}`
);
}

export function updateOrganizationEmployeeTeamAPI(id: string, data: Partial<IOrganizationTeamEmployeeUpdate>) {
return api.put<CreateResponse<IOrganizationTeamEmployeeUpdate>>(`/organization-team-employee/${id}`, data);
return put<IOrganizationTeamEmployeeUpdate>(`/organization-team-employee/${id}`, data);
}

export function updateOrganizationTeamEmployeeActiveTaskAPI(
id: string,
data: Partial<IOrganizationTeamEmployeeUpdate>
) {
return api.put<CreateResponse<IOrganizationTeamEmployeeUpdate>>(
`/organization-team-employee/${id}/active-task`,
data
);
return put<IOrganizationTeamEmployeeUpdate>(`/organization-team-employee/${id}/active-task`, data);
}
19 changes: 16 additions & 3 deletions apps/web/app/services/client/api/role-permissions.ts
Original file line number Diff line number Diff line change
@@ -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<PaginationResponse<IRolePermissions>>(`/role-permissions/${id}`);
const tenantId = getTenantIdCookie();

const params = {
data: JSON.stringify({
findInput: {
roleId: id,
tenantId
}
})
};
const query = new URLSearchParams(params);

return get<PaginationResponse<IRolePermissions>>(`/role-permissions/${id}?${query.toString()}`);
}

export function updateRolePermissionAPI(data: IRolePermissions) {
return api.put<IRolePermissions>(`/role-permissions/${data.id}`, data);
return put<IRolePermissions>(`/role-permissions/${data.id}`, data);
}
6 changes: 3 additions & 3 deletions apps/web/app/services/client/api/roles.ts
Original file line number Diff line number Diff line change
@@ -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<PaginationResponse<IRole>>('/roles');
return get<PaginationResponse<IRole>>('/roles');
}

export function createRoleAPI(data: IRole) {
return api.post<IRole>('/roles', data);
return post<IRole>('/roles', data);
}

export function deleteRoleAPI(id: string) {
Expand Down
4 changes: 2 additions & 2 deletions apps/web/app/services/client/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ function post<T>(url: string, data?: Record<string, any> | 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;
}
}
Expand Down

0 comments on commit 0e2eda4

Please sign in to comment.