Skip to content

Commit

Permalink
Merge pull request #2095 from ever-co/feat/static-build-support-3
Browse files Browse the repository at this point in the history
Feat/Next-Frontend APIs
  • Loading branch information
evereq authored Jan 16, 2024
2 parents af70063 + de34d6a commit 5c98fb5
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 92 deletions.
16 changes: 8 additions & 8 deletions apps/web/app/api/organization-team-join/[id]/[action]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 3 additions & 1 deletion apps/web/app/api/organization-team-join/resend-code/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 3 additions & 1 deletion apps/web/app/api/organization-team-join/validate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
34 changes: 17 additions & 17 deletions apps/web/app/api/tags/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ 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);

if (!user) return NextResponse.json({ error: 'unauthorized' }, { status: 401 });

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);
Expand All @@ -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);
}
4 changes: 3 additions & 1 deletion apps/web/app/api/tags/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
37 changes: 18 additions & 19 deletions apps/web/app/api/task-priorities/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 3 additions & 1 deletion apps/web/app/api/task-priorities/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion apps/web/app/hooks/features/useTaskLabels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions apps/web/app/hooks/features/useTaskPriorities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -105,7 +105,7 @@ export function useTaskPriorities() {
setTaskPriorities(res?.data?.items || []);
return res;
});
return res;
return eRes;
});
}
},
Expand Down
12 changes: 4 additions & 8 deletions apps/web/app/services/client/api/request-to-join-team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -29,16 +28,13 @@ export function requestToJoinAPI(data: IRequestToJoinCreate) {
}

export function validateRequestToJoinAPI(data: IValidateRequestToJoin) {
return api.post<CreateResponse<Pick<IRequestToJoin, 'email' | 'organizationTeamId'>>>(
'/organization-team-join/validate',
data
);
return post<Pick<IRequestToJoin, 'email' | 'organizationTeamId'>>('/organization-team-join/validate', data);
}

export function resendCodeRequestToJoinAPI(data: IRequestToJoinCreate) {
return api.post<IDataResponse<ISuccessResponse>>('/organization-team-join/resend-code', data);
return post<IDataResponse<ISuccessResponse>>('/organization-team-join/resend-code', data);
}

export function acceptRejectRequestToJoinAPI(id: string, action: IRequestToJoinActionEnum) {
return api.put<PaginationResponse<IRequestToJoin>>(`/organization-team-join/${id}/${action}`);
return put<PaginationResponse<IRequestToJoin>>(`/organization-team-join/${id}/${action}`);
}
20 changes: 6 additions & 14 deletions apps/web/app/services/client/api/task-labels.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
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<CreateResponse<ITaskLabelsCreate>>('/tags', data, {
return post<ITaskLabelsCreate>('/tags', data, {
headers: {
'Tenant-Id': tenantId
}
});
}

export function editTaskLabelsAPI(id: string, data: ITaskLabelsCreate, tenantId?: string) {
return api.put<CreateResponse<ITaskLabelsCreate>>(`/tags/${id}`, data, {
headers: {
'Tenant-Id': tenantId
}
return put<ITaskLabelsCreate>(`/tags/${id}`, data, {
tenantId
});
}

export function deleteTaskLabelsAPI(id: string) {
return api.delete<DeleteResponse>(`/tags/${id}`);
return deleteApi<DeleteResponse>(`/tags/${id}`);
}

export async function getTaskLabelsList(tenantId: string, organizationId: string, organizationTeamId: string | null) {
Expand Down
24 changes: 7 additions & 17 deletions apps/web/app/services/client/api/task-priorities.ts
Original file line number Diff line number Diff line change
@@ -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<CreateResponse<ITaskPrioritiesCreate>>('/task-priorities', data, {
headers: {
'Tenant-Id': tenantId
}
return post<ITaskPrioritiesCreate>('/task-priorities', data, {
tenantId
});
}

export function editTaskPrioritiesAPI(id: string, data: ITaskPrioritiesCreate, tenantId?: string) {
return api.put<CreateResponse<ITaskPrioritiesCreate>>(`/task-priorities/${id}`, data, {
headers: {
'Tenant-Id': tenantId
}
return put<ITaskPrioritiesCreate>(`/task-priorities/${id}`, data, {
tenantId
});
}

export function deleteTaskPrioritiesAPI(id: string) {
return api.delete<DeleteResponse>(`/task-priorities/${id}`);
return deleteApi<DeleteResponse>(`/task-priorities/${id}`);
}

export async function getTaskPrioritiesList(
Expand Down
19 changes: 18 additions & 1 deletion apps/web/app/services/client/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,23 @@ function post<T>(url: string, data?: Record<string, any> | FormData, config?: AP
return baseURL && directAPI ? apiDirect.post<T>(url, data, { ...config, headers }) : api.post<T>(url, data);
}

export { get, post, deleteApi };
function put<T>(url: string, data?: Record<string, any> | 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<T>(url, data, { ...config, headers }) : api.put<T>(url, data);
}

export { get, post, deleteApi, put };

export default api;
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 5c98fb5

Please sign in to comment.