diff --git a/apps/web/app/api/public/team/[profileLink]/[teamId]/route.ts b/apps/web/app/api/public/team/[profileLink]/[teamId]/route.ts index ae8430811..861839fe0 100644 --- a/apps/web/app/api/public/team/[profileLink]/[teamId]/route.ts +++ b/apps/web/app/api/public/team/[profileLink]/[teamId]/route.ts @@ -4,24 +4,24 @@ import { } from '@app/services/server/requests/public-organization-team'; import { NextResponse } from 'next/server'; -export async function GET(req: Request, { params }: { params: { profileLink: string; teamId: string } }) { +export async function GET(req: Request, { params }: { params: { profileLink: string; teamId: string } }) { const { searchParams } = new URL(req.url); - const { profileLink, teamId, } = params; - const { type } = searchParams as unknown as {type: string;}; + const { profileLink, teamId } = params; + const { type } = searchParams as unknown as { type: string }; if (type === 'misc') { - return NextResponse.json( - await getPublicOrganizationTeamMiscDataRequest({ - profileLink: profileLink, - teamId - }) - ); - } - return NextResponse.json( - await getPublicOrganizationTeamRequest({ + const response = await getPublicOrganizationTeamMiscDataRequest({ profileLink: profileLink, teamId - }) - ); + }); + + return NextResponse.json(response.data); + } + + const response = await getPublicOrganizationTeamRequest({ + profileLink: profileLink, + teamId + }); + return NextResponse.json(response.data); } diff --git a/apps/web/app/api/roles/[id]/route.ts b/apps/web/app/api/roles/[id]/route.ts index 1654f262f..94bf659bc 100644 --- a/apps/web/app/api/roles/[id]/route.ts +++ b/apps/web/app/api/roles/[id]/route.ts @@ -10,29 +10,29 @@ export async function PUT(req: Request) { if (!user) return $res('unauthorized'); const body = (await req.json()) as IRole; - return $res( - await updateRoleRequest({ - bearer_token: access_token, - tenantId, - data: body - }) - ); + const response = await updateRoleRequest({ + bearer_token: access_token, + tenantId, + data: body + }); + + 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 + const { id } = params; + + const response = await deleteRoleRequest({ + id: id as string, + bearer_token: access_token, + tenantId + }); - return $res( - await deleteRoleRequest({ - id: id as string, - bearer_token: access_token, - tenantId - }) - ); + return $res(response.data); } diff --git a/apps/web/app/api/task-related-issue-types/[id]/route.ts b/apps/web/app/api/task-related-issue-types/[id]/route.ts index 86e9f972f..c8b3245a4 100644 --- a/apps/web/app/api/task-related-issue-types/[id]/route.ts +++ b/apps/web/app/api/task-related-issue-types/[id]/route.ts @@ -6,40 +6,39 @@ import { } from '@app/services/server/requests/task-related-issue-type'; 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 ITaskRelatedIssueTypeCreate; - return $res( - await editTaskRelatedIssueTypeRequest({ - id, - datas, - bearer_token: access_token, - tenantId - }) - ); + + const response = await editTaskRelatedIssueTypeRequest({ + 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 deleteTaskRelatedIssueTypeRequest({ - id, - bearer_token: access_token, - tenantId - }) - ); + const response = await deleteTaskRelatedIssueTypeRequest({ + id, + bearer_token: access_token, + tenantId + }); + + return $res(response.data); } diff --git a/apps/web/app/api/task-related-issue-types/route.ts b/apps/web/app/api/task-related-issue-types/route.ts index 4f6a2ac6c..79ca45f1b 100644 --- a/apps/web/app/api/task-related-issue-types/route.ts +++ b/apps/web/app/api/task-related-issue-types/route.ts @@ -35,5 +35,7 @@ export async function POST(req: Request) { const body = (await req.json()) as unknown as ITaskRelatedIssueTypeCreate; - return $res(await createRelatedIssueTypeRequest(body, access_token, body?.tenantId)); + const response = await createRelatedIssueTypeRequest(body, access_token, body?.tenantId); + + return $res(response.data); } diff --git a/apps/web/app/api/task-sizes/[id]/route.ts b/apps/web/app/api/task-sizes/[id]/route.ts index d54aba1a0..ab9644f12 100644 --- a/apps/web/app/api/task-sizes/[id]/route.ts +++ b/apps/web/app/api/task-sizes/[id]/route.ts @@ -3,38 +3,39 @@ import { authenticatedGuard } from '@app/services/server/guards/authenticated-gu import { deleteTaskSizesRequest, editTaskSizesRequest } 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 { id } = params; const datas = (await req.json()) as unknown as ITaskSizesCreate; - return $res( - await editTaskSizesRequest({ - id, - datas, - bearer_token: access_token, - tenantId - }) - ); + + const response = await editTaskSizesRequest({ + 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 + const { id } = params; + + const response = await deleteTaskSizesRequest({ + id, + bearer_token: access_token, + tenantId + }); - return $res( - await deleteTaskSizesRequest({ - id, - bearer_token: access_token, - tenantId - }) - ); + return $res(response.data); } diff --git a/apps/web/app/api/task-sizes/route.ts b/apps/web/app/api/task-sizes/route.ts index 4b9cf60c4..ffe1a8daa 100644 --- a/apps/web/app/api/task-sizes/route.ts +++ b/apps/web/app/api/task-sizes/route.ts @@ -32,5 +32,7 @@ export async function POST(req: Request) { const body = (await req.json()) as unknown as ITaskSizesCreate; - return $res(await createSizesRequest(body, access_token, body?.tenantId)); + const response = await createSizesRequest(body, access_token, body?.tenantId); + + return $res(response.data); } diff --git a/apps/web/app/api/task-statuses/[id]/route.ts b/apps/web/app/api/task-statuses/[id]/route.ts index 64e656609..2d60edab8 100644 --- a/apps/web/app/api/task-statuses/[id]/route.ts +++ b/apps/web/app/api/task-statuses/[id]/route.ts @@ -3,7 +3,7 @@ import { authenticatedGuard } from '@app/services/server/guards/authenticated-gu import { deleteTaskStatusRequest, editTaskStatusRequest } from '@app/services/server/requests/taskStatus'; 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); @@ -12,17 +12,18 @@ export async function PUT(req: Request, { params }: { params: { id: string } }) const { id } = params; const datas = (await req.json()) as unknown as ITaskStatusCreate; - return $res( - await editTaskStatusRequest({ - id, - datas, - bearer_token: access_token, - tenantId - }) - ); + + const response = await editTaskStatusRequest({ + 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); @@ -30,11 +31,11 @@ export async function DELETE(req: Request, { params }: { params: { id: string } const { id } = params; - return $res( - await deleteTaskStatusRequest({ - id, - bearer_token: access_token, - tenantId - }) - ); + const response = await deleteTaskStatusRequest({ + id, + bearer_token: access_token, + tenantId + }); + + return $res(response.data); } diff --git a/apps/web/app/api/task-statuses/route.ts b/apps/web/app/api/task-statuses/route.ts index 58d1e5c09..b23d495f4 100644 --- a/apps/web/app/api/task-statuses/route.ts +++ b/apps/web/app/api/task-statuses/route.ts @@ -32,5 +32,7 @@ export async function POST(req: Request) { const body = (await req.json()) as unknown as ITaskStatusCreate; - return $res(await createStatusRequest(body, access_token, body?.tenantId)); + const response = await createStatusRequest(body, access_token, body?.tenantId); + + return $res(response.data); } diff --git a/apps/web/app/hooks/features/usePublicOrganizationTeams.ts b/apps/web/app/hooks/features/usePublicOrganizationTeams.ts index 468f14832..7467f68a6 100644 --- a/apps/web/app/hooks/features/usePublicOrganizationTeams.ts +++ b/apps/web/app/hooks/features/usePublicOrganizationTeams.ts @@ -36,7 +36,7 @@ export function usePublicOrganizationTeams() { } return queryCall(profileLink, teamId).then((res) => { - if (res.data?.data?.status === 404) { + if (res.data.status === 404) { setTeams([]); return res; } @@ -46,7 +46,7 @@ export function usePublicOrganizationTeams() { const newData = [ { ...updatedTeams[0], - ...res.data.data + ...res.data } ]; @@ -54,23 +54,23 @@ export function usePublicOrganizationTeams() { setTeams([ { ...updatedTeams[0], - ...res.data.data + ...res.data } ]); } } else { - setTeams([res.data.data]); + setTeams([res.data]); } const newPublicTeamData = { ...publicTeam, - ...res.data.data + ...res.data }; if (!isEqual(newPublicTeamData, publicTeam)) { setPublicTeam(newPublicTeamData); } - let responseTasks = (res.data?.data?.tasks as ITeamTask[]) || []; + let responseTasks = (res.data.tasks as ITeamTask[]) || []; if (responseTasks && responseTasks.length) { responseTasks = responseTasks.map((task) => { const clone = cloneDeep(task); @@ -92,16 +92,16 @@ export function usePublicOrganizationTeams() { const loadPublicTeamMiscData = useCallback( (profileLink: string, teamId: string) => { return queryCallMiscData(profileLink, teamId).then((res) => { - if (res.data?.data?.status === 404) { + if (res.data.status === 404) { setTeams([]); return res; } if (res.data) { - setTaskStatus(res.data.data?.statuses || []); - setTaskSizes(res.data.data?.sizes || []); - setTaskPriorities(res.data.data?.priorities || []); - setTaskLabels(res.data.data?.labels || []); + setTaskStatus(res.data?.statuses || []); + setTaskSizes(res.data?.sizes || []); + setTaskPriorities(res.data?.priorities || []); + setTaskLabels(res.data?.labels || []); } return res; diff --git a/apps/web/app/services/client/api/public-organization-team.ts b/apps/web/app/services/client/api/public-organization-team.ts index cdef52033..dc77a87a5 100644 --- a/apps/web/app/services/client/api/public-organization-team.ts +++ b/apps/web/app/services/client/api/public-organization-team.ts @@ -1,14 +1,57 @@ -import { IOrganizationTeamList, CreateResponse, IDataResponse } from '@app/interfaces'; -import api from '../axios'; +import { IDataResponse } from '@app/interfaces'; +import { get } from '../axios'; +import moment from 'moment'; +import { GAUZY_API_BASE_SERVER_URL } from '@app/constants'; export function getPublicOrganizationTeamsAPI(profile_link: string, team_id: string) { - return api.get | IDataResponse>( - `/public/team/${profile_link}/${team_id}?type=team` - ); + const relations = [ + 'tasks', + 'tasks.members', + 'tasks.teams', + 'tasks.tags', + 'members', + // 'members.role', + 'members.employee', + 'members.employee.user' + ]; + + const params = { + withLaskWorkedTask: 'true', + startDate: moment().startOf('day').toISOString(), + endDate: moment().endOf('day').toISOString() + } as { [x: string]: string }; + + relations.forEach((rl, i) => { + params[`relations[${i}]`] = rl; + }); + + const queries = new URLSearchParams(params || {}); + + const endpoint = GAUZY_API_BASE_SERVER_URL.value + ? `/public/team/${profile_link}/${team_id}?${queries.toString()}` + : `/public/team/${profile_link}/${team_id}?type=team`; + + return get(endpoint); } export function getPublicOrganizationTeamsMiscDataAPI(profile_link: string, team_id: string) { - return api.get | IDataResponse>( - `/public/team/${profile_link}/${team_id}?type=misc` - ); + const relations = ['statuses', 'priorities', 'sizes', 'labels', 'issueTypes']; + + const params = { + withLaskWorkedTask: 'true', + startDate: moment().startOf('day').toISOString(), + endDate: moment().endOf('day').toISOString() + } as { [x: string]: string }; + + relations.forEach((rl, i) => { + params[`relations[${i}]`] = rl; + }); + + const queries = new URLSearchParams(params || {}); + + const endpoint = GAUZY_API_BASE_SERVER_URL.value + ? `/public/team/${profile_link}/${team_id}?${queries.toString()}` + : `/public/team/${profile_link}/${team_id}?type=misc`; + + return get(endpoint); } diff --git a/apps/web/app/services/client/api/roles.ts b/apps/web/app/services/client/api/roles.ts index c1e88d5ab..7b489bb87 100644 --- a/apps/web/app/services/client/api/roles.ts +++ b/apps/web/app/services/client/api/roles.ts @@ -1,5 +1,5 @@ import { IRole, PaginationResponse } from '@app/interfaces'; -import api, { get, post } from '../axios'; +import { deleteApi, get, post, put } from '../axios'; export function getRolesAPI() { return get>('/roles'); @@ -10,9 +10,9 @@ export function createRoleAPI(data: IRole) { } export function deleteRoleAPI(id: string) { - return api.delete(`/roles/${id}`); + return deleteApi(`/roles/${id}`); } export function updateRoleAPI(data: IRole) { - return api.put(`/roles/${data.id}`, data); + return put(`/roles/${data.id}`, data); } diff --git a/apps/web/app/services/client/api/task-linked-issue.ts b/apps/web/app/services/client/api/task-linked-issue.ts index fad777e91..a2038ac36 100644 --- a/apps/web/app/services/client/api/task-linked-issue.ts +++ b/apps/web/app/services/client/api/task-linked-issue.ts @@ -1,10 +1,13 @@ import { ITaskLinkedIssue, ITaskLinkedIssueResponse, LinkedTaskIssue } from '@app/interfaces'; -import api from '../axios'; +import { post, put } from '../axios'; +import { GAUZY_API_BASE_SERVER_URL } from '@app/constants'; export function createTaskLinkedIsssueAPI(data: ITaskLinkedIssue) { - return api.post('/tasks/task-linked-issue', data); + const endpoint = GAUZY_API_BASE_SERVER_URL.value ? '/task-linked-issue' : '/tasks/task-linked-issue'; + return post(endpoint, data); } export function updateTaskLinkedIssueAPI(data: LinkedTaskIssue) { - return api.put('/tasks/task-linked-issue', data); + const endpoint = GAUZY_API_BASE_SERVER_URL.value ? `/task-linked-issue/${data.id}` : '/tasks/task-linked-issue'; + return put(endpoint, data); } diff --git a/apps/web/app/services/client/api/task-related-issue-type.ts b/apps/web/app/services/client/api/task-related-issue-type.ts index 87c07820c..c9f8d3d77 100644 --- a/apps/web/app/services/client/api/task-related-issue-type.ts +++ b/apps/web/app/services/client/api/task-related-issue-type.ts @@ -1,30 +1,25 @@ import { - CreateResponse, DeleteResponse, ITaskRelatedIssueTypeCreate, ITaskRelatedIssueTypeItemList, PaginationResponse } from '@app/interfaces'; -import api, { get } from '../axios'; +import { deleteApi, get, post, put } from '../axios'; export function createTaskRelatedIssueTypeAPI(data: ITaskRelatedIssueTypeCreate, tenantId?: string) { - return api.post>('/task-related-issue-types', data, { - headers: { - 'Tenant-Id': tenantId - } + return post('/task-related-issue-types', data, { + tenantId }); } export function editTaskRelatedIssueTypeAPI(id: string, data: ITaskRelatedIssueTypeCreate, tenantId?: string) { - return api.put>(`/task-related-issue-types/${id}`, data, { - headers: { - 'Tenant-Id': tenantId - } + return put(`/task-related-issue-types/${id}`, data, { + tenantId }); } export function deleteTaskRelatedIssueTypeAPI(id: string) { - return api.delete(`/task-related-issue-types/${id}`); + return deleteApi(`/task-related-issue-types/${id}`); } export async function getTaskRelatedIssueTypeList( diff --git a/apps/web/app/services/client/api/task-sizes.ts b/apps/web/app/services/client/api/task-sizes.ts index ebedd4c58..3f0551125 100644 --- a/apps/web/app/services/client/api/task-sizes.ts +++ b/apps/web/app/services/client/api/task-sizes.ts @@ -1,30 +1,20 @@ -import { - CreateResponse, - DeleteResponse, - ITaskSizesCreate, - ITaskSizesItemList, - PaginationResponse -} from '@app/interfaces'; -import api, { get } from '../axios'; +import { DeleteResponse, ITaskSizesCreate, ITaskSizesItemList, PaginationResponse } from '@app/interfaces'; +import { deleteApi, get, post, put } from '../axios'; export function createTaskSizesAPI(data: ITaskSizesCreate, tenantId?: string) { - return api.post>('/task-sizes', data, { - headers: { - 'Tenant-Id': tenantId - } + return post('/task-sizes', data, { + tenantId }); } export function editTaskSizesAPI(id: string, data: ITaskSizesCreate, tenantId?: string) { - return api.put>(`/task-sizes/${id}`, data, { - headers: { - 'Tenant-Id': tenantId - } + return put(`/task-sizes/${id}`, data, { + tenantId }); } export function deleteTaskSizesAPI(id: string) { - return api.delete(`/task-sizes/${id}`); + return deleteApi(`/task-sizes/${id}`); } export async function getTaskSizesList(tenantId: string, organizationId: string, activeTeamId: string | null) { diff --git a/apps/web/app/services/client/api/task-status.ts b/apps/web/app/services/client/api/task-status.ts index e8afdfc7b..e5f3eecb5 100644 --- a/apps/web/app/services/client/api/task-status.ts +++ b/apps/web/app/services/client/api/task-status.ts @@ -1,30 +1,20 @@ -import { - CreateResponse, - DeleteResponse, - ITaskStatusCreate, - ITaskStatusItemList, - PaginationResponse -} from '@app/interfaces'; -import api, { get } from '../axios'; +import { DeleteResponse, ITaskStatusCreate, ITaskStatusItemList, PaginationResponse } from '@app/interfaces'; +import { deleteApi, get, post, put } from '../axios'; export function createTaskStatusAPI(data: ITaskStatusCreate, tenantId?: string) { - return api.post>('/task-statuses', data, { - headers: { - 'Tenant-Id': tenantId - } + return post('/task-statuses', data, { + tenantId }); } export function editTaskStatusAPI(id: string, data: ITaskStatusCreate, tenantId?: string) { - return api.put>(`/task-statuses/${id}`, data, { - headers: { - 'Tenant-Id': tenantId - } + return put(`/task-statuses/${id}`, data, { + tenantId }); } export function deleteTaskStatusAPI(id: string) { - return api.delete(`/task-statuses/${id}`); + return deleteApi(`/task-statuses/${id}`); } export async function getTaskStatusList(tenantId: string, organizationId: string, organizationTeamId: string | null) {