From 52687460e2a54d57513b2ebef4aaf51b82feef9f Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Fri, 5 Jan 2024 16:27:27 +0200 Subject: [PATCH 01/22] feat: move /public/team/ to app folder --- .../app/[locale]/settings/personal/page.tsx | 5 +++- apps/web/app/[locale]/settings/team/page.tsx | 5 +++- .../api/public/team/[profileLink]/[teamId].ts | 29 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 apps/web/app/api/public/team/[profileLink]/[teamId].ts diff --git a/apps/web/app/[locale]/settings/personal/page.tsx b/apps/web/app/[locale]/settings/personal/page.tsx index 3432375fe..b2066f45f 100644 --- a/apps/web/app/[locale]/settings/personal/page.tsx +++ b/apps/web/app/[locale]/settings/personal/page.tsx @@ -18,7 +18,10 @@ import { fullWidthState } from '@app/stores/fullWidth'; const Personal = () => { const t = useTranslations(); const [user] = useRecoilState(userState); - const breadcrumb = [...JSON.parse(t('pages.settings.BREADCRUMB'))]; + const breadcrumb = [ + { title: JSON.parse(t('pages.home.BREADCRUMB')), href: '/' }, + { title: JSON.parse(t('pages.settings.BREADCRUMB')), href: '/settings/personnal' } + ]; const fullWidth = useRecoilValue(fullWidthState); return ( diff --git a/apps/web/app/[locale]/settings/team/page.tsx b/apps/web/app/[locale]/settings/team/page.tsx index 4bde85620..a747a50bc 100644 --- a/apps/web/app/[locale]/settings/team/page.tsx +++ b/apps/web/app/[locale]/settings/team/page.tsx @@ -27,7 +27,10 @@ const Team = () => { const [user] = useRecoilState(userState); const { isTeamMember, activeTeam } = useOrganizationTeams(); const { isTeamManager } = useIsMemberManager(user); - const breadcrumb = [...JSON.parse(t('pages.settings.BREADCRUMB'))]; + const breadcrumb = [ + { title: JSON.parse(t('pages.home.BREADCRUMB')), href: '/' }, + { title: JSON.parse(t('pages.settings.BREADCRUMB')), href: '/settings/team' } + ]; const fullWidth = useRecoilValue(fullWidthState); return ( <> diff --git a/apps/web/app/api/public/team/[profileLink]/[teamId].ts b/apps/web/app/api/public/team/[profileLink]/[teamId].ts new file mode 100644 index 000000000..0075e9d5b --- /dev/null +++ b/apps/web/app/api/public/team/[profileLink]/[teamId].ts @@ -0,0 +1,29 @@ +import { + getPublicOrganizationTeamMiscDataRequest, + getPublicOrganizationTeamRequest +} from '@app/services/server/requests/public-organization-team'; + +export default async function GET(req: Request) { + const { searchParams } = new URL(req.url); + const { profileLink, teamId, type }: { profileLink: string; teamId: string; type: string } = + searchParams as unknown as { + profileLink: string; + teamId: string; + type: string; + }; + + if (type === 'misc') { + return Response.json( + await getPublicOrganizationTeamMiscDataRequest({ + profileLink: profileLink, + teamId + }) + ); + } + return Response.json( + await getPublicOrganizationTeamRequest({ + profileLink: profileLink, + teamId + }) + ); +} From 741ce1175c2c1692905c86eec51cd83a53204d7f Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Fri, 5 Jan 2024 17:16:58 +0200 Subject: [PATCH 02/22] feat: move /reset/user to app folder --- apps/web/app/api/user/reset.ts | 17 ++++++++ apps/web/app/helpers/cookies/index.ts | 12 +++--- .../server/guards/authenticated-guard-app.ts | 41 +++++++++++++++++++ 3 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 apps/web/app/api/user/reset.ts create mode 100644 apps/web/app/services/server/guards/authenticated-guard-app.ts diff --git a/apps/web/app/api/user/reset.ts b/apps/web/app/api/user/reset.ts new file mode 100644 index 000000000..54fbae5a3 --- /dev/null +++ b/apps/web/app/api/user/reset.ts @@ -0,0 +1,17 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; + +import { resetUserRequest } from '@app/services/server/requests/user'; +import { NextResponse } from 'next/server'; + +export default async function DELETE(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + if (!user) return $res(); + + return Response.json( + await resetUserRequest({ + bearer_token: access_token, + tenantId + }) + ); +} diff --git a/apps/web/app/helpers/cookies/index.ts b/apps/web/app/helpers/cookies/index.ts index 78b8a4084..701f09439 100644 --- a/apps/web/app/helpers/cookies/index.ts +++ b/apps/web/app/helpers/cookies/index.ts @@ -16,7 +16,6 @@ import { import { IDecodedRefreshToken } from '@app/interfaces/IAuthentication'; import { deleteCookie, getCookie, setCookie } from './helpers'; import { chunk, range } from 'lib/utils'; -import { NextApiRequest, NextApiResponse } from 'next'; type DataParams = { refresh_token: { @@ -33,13 +32,16 @@ type DataParams = { userId: string; }; -type NextCtx = { req: NextApiRequest; res: NextApiResponse }; +type NextCtx = { + req: any; + res: any; +}; export const setLargeStringInCookies = ( COOKIE_NAME: string, largeString: string, - req: NextApiRequest, - res: NextApiResponse, + req: any, + res: any, crossSite = false ) => { const chunkSize = 4000; @@ -75,7 +77,7 @@ export const getLargeStringFromCookies = (COOKIE_NAME: string, ctx?: NextCtx) => return chunks.join(''); }; -export function setAuthCookies(datas: DataParams, req: NextApiRequest, res: NextApiResponse) { +export function setAuthCookies(datas: DataParams, req: any, res: any) { const { refresh_token, access_token, diff --git a/apps/web/app/services/server/guards/authenticated-guard-app.ts b/apps/web/app/services/server/guards/authenticated-guard-app.ts new file mode 100644 index 000000000..d5c41a996 --- /dev/null +++ b/apps/web/app/services/server/guards/authenticated-guard-app.ts @@ -0,0 +1,41 @@ +import { + getAccessTokenCookie, + getActiveProjectIdCookie, + getActiveTaskIdCookie, + getActiveTeamIdCookie, + getOrganizationIdCookie, + getTenantIdCookie +} from '@app/helpers/cookies'; +import { currentAuthenticatedUserRequest } from '../requests/auth'; +import { NextResponse } from 'next/server'; + +export async function authenticatedGuard(req: Request, res: NextResponse) { + const access_token = getAccessTokenCookie({ req, res }); + const tenantId = getTenantIdCookie({ req, res }); + const organizationId = getOrganizationIdCookie({ req, res }); + const teamId = getActiveTeamIdCookie({ req, res }); + const taskId = getActiveTaskIdCookie({ req, res }); + const projectId = getActiveProjectIdCookie({ req, res }); + + const r_res = await currentAuthenticatedUserRequest({ + bearer_token: access_token?.toString() || '' + }).catch(console.error); + + if (!r_res || (r_res.data as any).statusCode === 401) { + return { + $res: () => Response.json({ statusCode: 401, message: 'Unauthorized' }), + user: null + }; + } + + return { + $res: res, + user: r_res.data, + access_token: access_token as string, + tenantId, + organizationId, + teamId, + taskId, + projectId + }; +} From ef3fed1a380bfff04bae817f5a78fd2e3223bdd5 Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Fri, 5 Jan 2024 17:30:41 +0200 Subject: [PATCH 03/22] feat: move /user/[id] to app folder --- apps/web/app/api/user/[id].ts | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 apps/web/app/api/user/[id].ts diff --git a/apps/web/app/api/user/[id].ts b/apps/web/app/api/user/[id].ts new file mode 100644 index 000000000..8d8f254c3 --- /dev/null +++ b/apps/web/app/api/user/[id].ts @@ -0,0 +1,56 @@ +import { IUser } from '@app/interfaces/IUserData'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { getTaskCreator, updateUserAvatarRequest } from '@app/services/server/requests'; +import { deleteUserRequest } from '@app/services/server/requests/user'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { searchParams } = new URL(req.url); + + const { $res, user, access_token } = await authenticatedGuard(req, res); + if (!user) return $res(); + + const { id: userId } = searchParams as unknown as { id: string }; + return Response.json( + await getTaskCreator({ + userId: userId as string, + bearer_token: access_token + }) + ); +} + +export async function POST(req: Request) { + const res = new NextResponse(); + + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + if (!user) return $res(); + + const body = req.body as unknown as IUser; + + return Response.json( + await updateUserAvatarRequest( + { + data: body, + id: user.id as string, + tenantId + }, + access_token + ) + ); +} + +export async function DELETE(req: Request) { + const res = new NextResponse(); + + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + if (!user) return $res(); + + return Response.json( + await deleteUserRequest({ + id: user.id, + bearer_token: access_token, + tenantId + }) + ); +} From 7efb9e10bcf92d630c58b4d9428cc404d60c3784 Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Fri, 5 Jan 2024 20:22:19 +0200 Subject: [PATCH 04/22] feat: move /timesheet/* to app folder --- .../{[teamId].ts => [teamId]/route.ts} | 0 .../timer => app/api/timer/start}/start.ts | 0 .../timer => app/api/timer/status}/status.ts | 0 .../api/timer => app/api/timer/stop}/stop.ts | 0 .../api/timer => app/api/timer/sync}/sync.ts | 0 .../timesheet/all-statistics-tasks/route.ts | 21 ++++++++ apps/web/app/api/timer/timesheet/route.ts | 8 +++ .../timer/timesheet/statistics-tasks/route.ts | 51 +++++++++++++++++++ apps/web/app/api/timer/toogle/route.ts | 40 +++++++++++++++ .../app/api/user/{[id].ts => [id]/route.ts} | 12 ++--- apps/web/app/api/user/me/route.ts | 10 ++++ .../app/api/user/{reset.ts => reset/route.ts} | 4 +- .../server/guards/authenticated-guard-app.ts | 5 +- apps/web/pages/{api => others}/auth/login.ts | 0 .../pages/{api => others}/auth/meet/jwt.ts | 0 .../web/pages/{api => others}/auth/refresh.ts | 0 .../pages/{api => others}/auth/register.ts | 0 .../pages/{api => others}/auth/send-code.ts | 0 .../auth/signin-email-confirm.ts | 0 .../{api => others}/auth/signin-email.ts | 0 .../{api => others}/auth/signin-workspace.ts | 0 .../pages/{api => others}/auth/verify/code.ts | 0 .../auth/verify/resend-link.ts | 0 .../{api => others}/auth/verify/token.ts | 0 .../email-reset/request-change-email.ts | 0 .../email-reset/verify-change-email.ts | 0 .../pages/{api => others}/employee/working.ts | 0 .../integration-tenant/[id].ts | 0 .../remember/state/index.ts | 0 .../integration/github/install.ts | 0 .../integration/github/metadata.ts | 0 .../integration/github/oauth.ts | 0 .../integration/github/repositories.ts | 0 .../integration/github/repository/sync.ts | 0 .../integration/types/index.ts | 0 apps/web/pages/{api => others}/invite/[id].ts | 0 .../pages/{api => others}/invite/emails.ts | 0 .../web/pages/{api => others}/invite/index.ts | 0 .../pages/{api => others}/invite/resend.ts | 0 .../invite/validate-by-code.ts | 0 .../pages/{api => others}/issue-types/[id].ts | 0 .../{api => others}/issue-types/index.tsx | 0 .../pages/{api => others}/languages/index.ts | 0 .../organization-projects/[id].ts | 0 .../organization-projects/setting/[id].ts | 0 .../[id]/active-task.ts | 0 .../organization-team-employee/[id]/index.tsx | 0 .../organization-team-join/[id]/[action].ts | 0 .../organization-team-join/index.ts | 0 .../organization-team-join/resend-code.ts | 0 .../organization-team-join/validate.ts | 0 .../{api => others}/organization-team/[id].ts | 0 .../organization-team/employee/[id].ts | 0 .../organization-team/index.ts | 0 .../organization-team/teams/[id].ts | 0 .../public/team/[profileLink]/[teamId].ts | 0 .../{api => others}/role-permissions/[id].ts | 0 apps/web/pages/{api => others}/roles/[id].ts | 0 apps/web/pages/{api => others}/roles/index.ts | 0 apps/web/pages/{api => others}/tags/[id].ts | 0 apps/web/pages/{api => others}/tags/index.tsx | 0 apps/web/pages/{api => others}/tags/level.ts | 0 .../{api => others}/task-priorities/[id].ts | 0 .../{api => others}/task-priorities/index.tsx | 0 .../task-related-issue-types/[id].ts | 0 .../task-related-issue-types/index.ts | 0 .../pages/{api => others}/task-sizes/[id].ts | 0 .../{api => others}/task-sizes/index.tsx | 0 .../{api => others}/task-statuses/[id].ts | 0 .../{api => others}/task-statuses/index.tsx | 0 .../{api => others}/task-versions/[id].ts | 0 .../{api => others}/task-versions/index.tsx | 0 apps/web/pages/{api => others}/tasks/[id].ts | 0 .../tasks/employee/[employeeId].ts | 0 .../tasks/task-linked-issue.ts | 0 apps/web/pages/{api => others}/tasks/team.ts | 0 apps/web/pages/others/timer/start.ts | 34 +++++++++++++ apps/web/pages/others/timer/status.ts | 12 +++++ apps/web/pages/others/timer/stop.ts | 31 +++++++++++ apps/web/pages/others/timer/sync.ts | 30 +++++++++++ .../timer/timesheet/all-statistics-tasks.ts | 0 .../{api => others}/timer/timesheet/index.ts | 0 .../timer/timesheet/statistics-tasks.ts | 0 .../web/pages/{api => others}/timer/toggle.ts | 0 apps/web/pages/{api => others}/user/[id].ts | 0 apps/web/pages/{api => others}/user/me.ts | 0 apps/web/pages/{api => others}/user/reset.ts | 0 87 files changed, 248 insertions(+), 10 deletions(-) rename apps/web/app/api/public/team/[profileLink]/{[teamId].ts => [teamId]/route.ts} (100%) rename apps/web/{pages/api/timer => app/api/timer/start}/start.ts (100%) rename apps/web/{pages/api/timer => app/api/timer/status}/status.ts (100%) rename apps/web/{pages/api/timer => app/api/timer/stop}/stop.ts (100%) rename apps/web/{pages/api/timer => app/api/timer/sync}/sync.ts (100%) create mode 100644 apps/web/app/api/timer/timesheet/all-statistics-tasks/route.ts create mode 100644 apps/web/app/api/timer/timesheet/route.ts create mode 100644 apps/web/app/api/timer/timesheet/statistics-tasks/route.ts create mode 100644 apps/web/app/api/timer/toogle/route.ts rename apps/web/app/api/user/{[id].ts => [id]/route.ts} (88%) create mode 100644 apps/web/app/api/user/me/route.ts rename apps/web/app/api/user/{reset.ts => reset/route.ts} (89%) rename apps/web/pages/{api => others}/auth/login.ts (100%) rename apps/web/pages/{api => others}/auth/meet/jwt.ts (100%) rename apps/web/pages/{api => others}/auth/refresh.ts (100%) rename apps/web/pages/{api => others}/auth/register.ts (100%) rename apps/web/pages/{api => others}/auth/send-code.ts (100%) rename apps/web/pages/{api => others}/auth/signin-email-confirm.ts (100%) rename apps/web/pages/{api => others}/auth/signin-email.ts (100%) rename apps/web/pages/{api => others}/auth/signin-workspace.ts (100%) rename apps/web/pages/{api => others}/auth/verify/code.ts (100%) rename apps/web/pages/{api => others}/auth/verify/resend-link.ts (100%) rename apps/web/pages/{api => others}/auth/verify/token.ts (100%) rename apps/web/pages/{api => others}/email-reset/request-change-email.ts (100%) rename apps/web/pages/{api => others}/email-reset/verify-change-email.ts (100%) rename apps/web/pages/{api => others}/employee/working.ts (100%) rename apps/web/pages/{api => others}/integration-tenant/[id].ts (100%) rename apps/web/pages/{api => others}/integration-tenant/remember/state/index.ts (100%) rename apps/web/pages/{api => others}/integration/github/install.ts (100%) rename apps/web/pages/{api => others}/integration/github/metadata.ts (100%) rename apps/web/pages/{api => others}/integration/github/oauth.ts (100%) rename apps/web/pages/{api => others}/integration/github/repositories.ts (100%) rename apps/web/pages/{api => others}/integration/github/repository/sync.ts (100%) rename apps/web/pages/{api => others}/integration/types/index.ts (100%) rename apps/web/pages/{api => others}/invite/[id].ts (100%) rename apps/web/pages/{api => others}/invite/emails.ts (100%) rename apps/web/pages/{api => others}/invite/index.ts (100%) rename apps/web/pages/{api => others}/invite/resend.ts (100%) rename apps/web/pages/{api => others}/invite/validate-by-code.ts (100%) rename apps/web/pages/{api => others}/issue-types/[id].ts (100%) rename apps/web/pages/{api => others}/issue-types/index.tsx (100%) rename apps/web/pages/{api => others}/languages/index.ts (100%) rename apps/web/pages/{api => others}/organization-projects/[id].ts (100%) rename apps/web/pages/{api => others}/organization-projects/setting/[id].ts (100%) rename apps/web/pages/{api => others}/organization-team-employee/[id]/active-task.ts (100%) rename apps/web/pages/{api => others}/organization-team-employee/[id]/index.tsx (100%) rename apps/web/pages/{api => others}/organization-team-join/[id]/[action].ts (100%) rename apps/web/pages/{api => others}/organization-team-join/index.ts (100%) rename apps/web/pages/{api => others}/organization-team-join/resend-code.ts (100%) rename apps/web/pages/{api => others}/organization-team-join/validate.ts (100%) rename apps/web/pages/{api => others}/organization-team/[id].ts (100%) rename apps/web/pages/{api => others}/organization-team/employee/[id].ts (100%) rename apps/web/pages/{api => others}/organization-team/index.ts (100%) rename apps/web/pages/{api => others}/organization-team/teams/[id].ts (100%) rename apps/web/pages/{api => others}/public/team/[profileLink]/[teamId].ts (100%) rename apps/web/pages/{api => others}/role-permissions/[id].ts (100%) rename apps/web/pages/{api => others}/roles/[id].ts (100%) rename apps/web/pages/{api => others}/roles/index.ts (100%) rename apps/web/pages/{api => others}/tags/[id].ts (100%) rename apps/web/pages/{api => others}/tags/index.tsx (100%) rename apps/web/pages/{api => others}/tags/level.ts (100%) rename apps/web/pages/{api => others}/task-priorities/[id].ts (100%) rename apps/web/pages/{api => others}/task-priorities/index.tsx (100%) rename apps/web/pages/{api => others}/task-related-issue-types/[id].ts (100%) rename apps/web/pages/{api => others}/task-related-issue-types/index.ts (100%) rename apps/web/pages/{api => others}/task-sizes/[id].ts (100%) rename apps/web/pages/{api => others}/task-sizes/index.tsx (100%) rename apps/web/pages/{api => others}/task-statuses/[id].ts (100%) rename apps/web/pages/{api => others}/task-statuses/index.tsx (100%) rename apps/web/pages/{api => others}/task-versions/[id].ts (100%) rename apps/web/pages/{api => others}/task-versions/index.tsx (100%) rename apps/web/pages/{api => others}/tasks/[id].ts (100%) rename apps/web/pages/{api => others}/tasks/employee/[employeeId].ts (100%) rename apps/web/pages/{api => others}/tasks/task-linked-issue.ts (100%) rename apps/web/pages/{api => others}/tasks/team.ts (100%) create mode 100644 apps/web/pages/others/timer/start.ts create mode 100644 apps/web/pages/others/timer/status.ts create mode 100644 apps/web/pages/others/timer/stop.ts create mode 100644 apps/web/pages/others/timer/sync.ts rename apps/web/pages/{api => others}/timer/timesheet/all-statistics-tasks.ts (100%) rename apps/web/pages/{api => others}/timer/timesheet/index.ts (100%) rename apps/web/pages/{api => others}/timer/timesheet/statistics-tasks.ts (100%) rename apps/web/pages/{api => others}/timer/toggle.ts (100%) rename apps/web/pages/{api => others}/user/[id].ts (100%) rename apps/web/pages/{api => others}/user/me.ts (100%) rename apps/web/pages/{api => others}/user/reset.ts (100%) diff --git a/apps/web/app/api/public/team/[profileLink]/[teamId].ts b/apps/web/app/api/public/team/[profileLink]/[teamId]/route.ts similarity index 100% rename from apps/web/app/api/public/team/[profileLink]/[teamId].ts rename to apps/web/app/api/public/team/[profileLink]/[teamId]/route.ts diff --git a/apps/web/pages/api/timer/start.ts b/apps/web/app/api/timer/start/start.ts similarity index 100% rename from apps/web/pages/api/timer/start.ts rename to apps/web/app/api/timer/start/start.ts diff --git a/apps/web/pages/api/timer/status.ts b/apps/web/app/api/timer/status/status.ts similarity index 100% rename from apps/web/pages/api/timer/status.ts rename to apps/web/app/api/timer/status/status.ts diff --git a/apps/web/pages/api/timer/stop.ts b/apps/web/app/api/timer/stop/stop.ts similarity index 100% rename from apps/web/pages/api/timer/stop.ts rename to apps/web/app/api/timer/stop/stop.ts diff --git a/apps/web/pages/api/timer/sync.ts b/apps/web/app/api/timer/sync/sync.ts similarity index 100% rename from apps/web/pages/api/timer/sync.ts rename to apps/web/app/api/timer/sync/sync.ts diff --git a/apps/web/app/api/timer/timesheet/all-statistics-tasks/route.ts b/apps/web/app/api/timer/timesheet/all-statistics-tasks/route.ts new file mode 100644 index 000000000..824fa83dc --- /dev/null +++ b/apps/web/app/api/timer/timesheet/all-statistics-tasks/route.ts @@ -0,0 +1,21 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { tasksTimesheetStatisticsRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user, tenantId, organizationId, access_token } = await authenticatedGuard(req, res); + if (!user) return $res('Unauthorized'); + + const { data } = await tasksTimesheetStatisticsRequest( + { + tenantId, + organizationId, + employeeIds: [], + defaultRange: 'false' + }, + access_token + ); + + return $res(data); +} diff --git a/apps/web/app/api/timer/timesheet/route.ts b/apps/web/app/api/timer/timesheet/route.ts new file mode 100644 index 000000000..b3eb30d0d --- /dev/null +++ b/apps/web/app/api/timer/timesheet/route.ts @@ -0,0 +1,8 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { NextResponse } from 'next/server'; + +export default async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user } = await authenticatedGuard(req, res); + if (!user) return $res('unauthorized'); +} diff --git a/apps/web/app/api/timer/timesheet/statistics-tasks/route.ts b/apps/web/app/api/timer/timesheet/statistics-tasks/route.ts new file mode 100644 index 000000000..0883d18bd --- /dev/null +++ b/apps/web/app/api/timer/timesheet/statistics-tasks/route.ts @@ -0,0 +1,51 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { tasksTimesheetStatisticsRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { searchParams } = new URL(req.url); + + const { $res, user, tenantId, organizationId, access_token, taskId } = await authenticatedGuard(req, res); + if (!user) return $res('unauthorized'); + + const query = searchParams as unknown as { activeTask: string; employeeId: string }; + const activeTask = query.activeTask; + let employeeId = query.employeeId; + employeeId = employeeId || user.employee?.id; + + if (activeTask && !taskId) { + return $res({ + global: [], + today: [] + }); + } + + const { data } = await tasksTimesheetStatisticsRequest( + { + tenantId, + organizationId, + employeeIds: employeeId ? [employeeId] : [], + defaultRange: 'false', + ...(activeTask && taskId ? { 'taskIds[0]': taskId } : {}) + }, + access_token + ); + + const { data: todayData } = await tasksTimesheetStatisticsRequest( + { + tenantId, + organizationId, + employeeIds: employeeId ? [employeeId] : [], + defaultRange: 'true', + ...(activeTask && taskId ? { 'taskIds[0]': taskId } : {}), + unitOfTime: 'day' + }, + access_token + ); + + return $res({ + global: data, + today: todayData + }); +} diff --git a/apps/web/app/api/timer/toogle/route.ts b/apps/web/app/api/timer/toogle/route.ts new file mode 100644 index 000000000..62c80b565 --- /dev/null +++ b/apps/web/app/api/timer/toogle/route.ts @@ -0,0 +1,40 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { getTimerStatusRequest, stopTimerRequest, toggleTimerRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export default async function POST(req: Request) { + const res = new NextResponse(); + const { $res, user, tenantId, access_token, organizationId, taskId } = await authenticatedGuard(req, res); + if (!user) return $res(''); + + const body = req.body as unknown as { source: any }; + const { source } = body; + + await toggleTimerRequest( + { + source, + logType: 'TRACKED', + tenantId, + taskId, + organizationId, + tags: [] + }, + access_token + ); + + await stopTimerRequest( + { + tenantId, + organizationId, + taskId, + logType: 'TRACKED', + source, + tags: [] + }, + access_token + ); + + const { data: timerStatus } = await getTimerStatusRequest({ tenantId, organizationId }, access_token); + + return $res(timerStatus); +} diff --git a/apps/web/app/api/user/[id].ts b/apps/web/app/api/user/[id]/route.ts similarity index 88% rename from apps/web/app/api/user/[id].ts rename to apps/web/app/api/user/[id]/route.ts index 8d8f254c3..1793d2bf0 100644 --- a/apps/web/app/api/user/[id].ts +++ b/apps/web/app/api/user/[id]/route.ts @@ -9,10 +9,10 @@ export async function GET(req: Request) { const { searchParams } = new URL(req.url); const { $res, user, access_token } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return $res('Unauthorized'); const { id: userId } = searchParams as unknown as { id: string }; - return Response.json( + return $res( await getTaskCreator({ userId: userId as string, bearer_token: access_token @@ -24,11 +24,11 @@ export async function POST(req: Request) { const res = new NextResponse(); const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return $res('Unauthorized'); const body = req.body as unknown as IUser; - return Response.json( + return $res( await updateUserAvatarRequest( { data: body, @@ -44,9 +44,9 @@ export async function DELETE(req: Request) { const res = new NextResponse(); const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return $res('Unauthorized'); - return Response.json( + return $res( await deleteUserRequest({ id: user.id, bearer_token: access_token, diff --git a/apps/web/app/api/user/me/route.ts b/apps/web/app/api/user/me/route.ts new file mode 100644 index 000000000..6c0ef1079 --- /dev/null +++ b/apps/web/app/api/user/me/route.ts @@ -0,0 +1,10 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { NextResponse } from 'next/server'; + +export default async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user } = await authenticatedGuard(req, res); + if (!user) return $res('unhautorized'); + + $res(user); +} diff --git a/apps/web/app/api/user/reset.ts b/apps/web/app/api/user/reset/route.ts similarity index 89% rename from apps/web/app/api/user/reset.ts rename to apps/web/app/api/user/reset/route.ts index 54fbae5a3..bd7c0d6d5 100644 --- a/apps/web/app/api/user/reset.ts +++ b/apps/web/app/api/user/reset/route.ts @@ -6,9 +6,9 @@ import { NextResponse } from 'next/server'; export default async function DELETE(req: Request) { const res = new NextResponse(); const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return $res('Unauthorized'); - return Response.json( + return $res( await resetUserRequest({ bearer_token: access_token, tenantId diff --git a/apps/web/app/services/server/guards/authenticated-guard-app.ts b/apps/web/app/services/server/guards/authenticated-guard-app.ts index d5c41a996..ba8702923 100644 --- a/apps/web/app/services/server/guards/authenticated-guard-app.ts +++ b/apps/web/app/services/server/guards/authenticated-guard-app.ts @@ -23,13 +23,14 @@ export async function authenticatedGuard(req: Request, res: NextResponse Response.json({ statusCode: 401, message: 'Unauthorized' }), + // eslint-disable-next-line @typescript-eslint/no-unused-vars + $res: (data: any) => Response.json({ statusCode: 401, message: data }), user: null }; } return { - $res: res, + $res: (data: any) => Response.json(data), user: r_res.data, access_token: access_token as string, tenantId, diff --git a/apps/web/pages/api/auth/login.ts b/apps/web/pages/others/auth/login.ts similarity index 100% rename from apps/web/pages/api/auth/login.ts rename to apps/web/pages/others/auth/login.ts diff --git a/apps/web/pages/api/auth/meet/jwt.ts b/apps/web/pages/others/auth/meet/jwt.ts similarity index 100% rename from apps/web/pages/api/auth/meet/jwt.ts rename to apps/web/pages/others/auth/meet/jwt.ts diff --git a/apps/web/pages/api/auth/refresh.ts b/apps/web/pages/others/auth/refresh.ts similarity index 100% rename from apps/web/pages/api/auth/refresh.ts rename to apps/web/pages/others/auth/refresh.ts diff --git a/apps/web/pages/api/auth/register.ts b/apps/web/pages/others/auth/register.ts similarity index 100% rename from apps/web/pages/api/auth/register.ts rename to apps/web/pages/others/auth/register.ts diff --git a/apps/web/pages/api/auth/send-code.ts b/apps/web/pages/others/auth/send-code.ts similarity index 100% rename from apps/web/pages/api/auth/send-code.ts rename to apps/web/pages/others/auth/send-code.ts diff --git a/apps/web/pages/api/auth/signin-email-confirm.ts b/apps/web/pages/others/auth/signin-email-confirm.ts similarity index 100% rename from apps/web/pages/api/auth/signin-email-confirm.ts rename to apps/web/pages/others/auth/signin-email-confirm.ts diff --git a/apps/web/pages/api/auth/signin-email.ts b/apps/web/pages/others/auth/signin-email.ts similarity index 100% rename from apps/web/pages/api/auth/signin-email.ts rename to apps/web/pages/others/auth/signin-email.ts diff --git a/apps/web/pages/api/auth/signin-workspace.ts b/apps/web/pages/others/auth/signin-workspace.ts similarity index 100% rename from apps/web/pages/api/auth/signin-workspace.ts rename to apps/web/pages/others/auth/signin-workspace.ts diff --git a/apps/web/pages/api/auth/verify/code.ts b/apps/web/pages/others/auth/verify/code.ts similarity index 100% rename from apps/web/pages/api/auth/verify/code.ts rename to apps/web/pages/others/auth/verify/code.ts diff --git a/apps/web/pages/api/auth/verify/resend-link.ts b/apps/web/pages/others/auth/verify/resend-link.ts similarity index 100% rename from apps/web/pages/api/auth/verify/resend-link.ts rename to apps/web/pages/others/auth/verify/resend-link.ts diff --git a/apps/web/pages/api/auth/verify/token.ts b/apps/web/pages/others/auth/verify/token.ts similarity index 100% rename from apps/web/pages/api/auth/verify/token.ts rename to apps/web/pages/others/auth/verify/token.ts diff --git a/apps/web/pages/api/email-reset/request-change-email.ts b/apps/web/pages/others/email-reset/request-change-email.ts similarity index 100% rename from apps/web/pages/api/email-reset/request-change-email.ts rename to apps/web/pages/others/email-reset/request-change-email.ts diff --git a/apps/web/pages/api/email-reset/verify-change-email.ts b/apps/web/pages/others/email-reset/verify-change-email.ts similarity index 100% rename from apps/web/pages/api/email-reset/verify-change-email.ts rename to apps/web/pages/others/email-reset/verify-change-email.ts diff --git a/apps/web/pages/api/employee/working.ts b/apps/web/pages/others/employee/working.ts similarity index 100% rename from apps/web/pages/api/employee/working.ts rename to apps/web/pages/others/employee/working.ts diff --git a/apps/web/pages/api/integration-tenant/[id].ts b/apps/web/pages/others/integration-tenant/[id].ts similarity index 100% rename from apps/web/pages/api/integration-tenant/[id].ts rename to apps/web/pages/others/integration-tenant/[id].ts diff --git a/apps/web/pages/api/integration-tenant/remember/state/index.ts b/apps/web/pages/others/integration-tenant/remember/state/index.ts similarity index 100% rename from apps/web/pages/api/integration-tenant/remember/state/index.ts rename to apps/web/pages/others/integration-tenant/remember/state/index.ts diff --git a/apps/web/pages/api/integration/github/install.ts b/apps/web/pages/others/integration/github/install.ts similarity index 100% rename from apps/web/pages/api/integration/github/install.ts rename to apps/web/pages/others/integration/github/install.ts diff --git a/apps/web/pages/api/integration/github/metadata.ts b/apps/web/pages/others/integration/github/metadata.ts similarity index 100% rename from apps/web/pages/api/integration/github/metadata.ts rename to apps/web/pages/others/integration/github/metadata.ts diff --git a/apps/web/pages/api/integration/github/oauth.ts b/apps/web/pages/others/integration/github/oauth.ts similarity index 100% rename from apps/web/pages/api/integration/github/oauth.ts rename to apps/web/pages/others/integration/github/oauth.ts diff --git a/apps/web/pages/api/integration/github/repositories.ts b/apps/web/pages/others/integration/github/repositories.ts similarity index 100% rename from apps/web/pages/api/integration/github/repositories.ts rename to apps/web/pages/others/integration/github/repositories.ts diff --git a/apps/web/pages/api/integration/github/repository/sync.ts b/apps/web/pages/others/integration/github/repository/sync.ts similarity index 100% rename from apps/web/pages/api/integration/github/repository/sync.ts rename to apps/web/pages/others/integration/github/repository/sync.ts diff --git a/apps/web/pages/api/integration/types/index.ts b/apps/web/pages/others/integration/types/index.ts similarity index 100% rename from apps/web/pages/api/integration/types/index.ts rename to apps/web/pages/others/integration/types/index.ts diff --git a/apps/web/pages/api/invite/[id].ts b/apps/web/pages/others/invite/[id].ts similarity index 100% rename from apps/web/pages/api/invite/[id].ts rename to apps/web/pages/others/invite/[id].ts diff --git a/apps/web/pages/api/invite/emails.ts b/apps/web/pages/others/invite/emails.ts similarity index 100% rename from apps/web/pages/api/invite/emails.ts rename to apps/web/pages/others/invite/emails.ts diff --git a/apps/web/pages/api/invite/index.ts b/apps/web/pages/others/invite/index.ts similarity index 100% rename from apps/web/pages/api/invite/index.ts rename to apps/web/pages/others/invite/index.ts diff --git a/apps/web/pages/api/invite/resend.ts b/apps/web/pages/others/invite/resend.ts similarity index 100% rename from apps/web/pages/api/invite/resend.ts rename to apps/web/pages/others/invite/resend.ts diff --git a/apps/web/pages/api/invite/validate-by-code.ts b/apps/web/pages/others/invite/validate-by-code.ts similarity index 100% rename from apps/web/pages/api/invite/validate-by-code.ts rename to apps/web/pages/others/invite/validate-by-code.ts diff --git a/apps/web/pages/api/issue-types/[id].ts b/apps/web/pages/others/issue-types/[id].ts similarity index 100% rename from apps/web/pages/api/issue-types/[id].ts rename to apps/web/pages/others/issue-types/[id].ts diff --git a/apps/web/pages/api/issue-types/index.tsx b/apps/web/pages/others/issue-types/index.tsx similarity index 100% rename from apps/web/pages/api/issue-types/index.tsx rename to apps/web/pages/others/issue-types/index.tsx diff --git a/apps/web/pages/api/languages/index.ts b/apps/web/pages/others/languages/index.ts similarity index 100% rename from apps/web/pages/api/languages/index.ts rename to apps/web/pages/others/languages/index.ts diff --git a/apps/web/pages/api/organization-projects/[id].ts b/apps/web/pages/others/organization-projects/[id].ts similarity index 100% rename from apps/web/pages/api/organization-projects/[id].ts rename to apps/web/pages/others/organization-projects/[id].ts diff --git a/apps/web/pages/api/organization-projects/setting/[id].ts b/apps/web/pages/others/organization-projects/setting/[id].ts similarity index 100% rename from apps/web/pages/api/organization-projects/setting/[id].ts rename to apps/web/pages/others/organization-projects/setting/[id].ts diff --git a/apps/web/pages/api/organization-team-employee/[id]/active-task.ts b/apps/web/pages/others/organization-team-employee/[id]/active-task.ts similarity index 100% rename from apps/web/pages/api/organization-team-employee/[id]/active-task.ts rename to apps/web/pages/others/organization-team-employee/[id]/active-task.ts diff --git a/apps/web/pages/api/organization-team-employee/[id]/index.tsx b/apps/web/pages/others/organization-team-employee/[id]/index.tsx similarity index 100% rename from apps/web/pages/api/organization-team-employee/[id]/index.tsx rename to apps/web/pages/others/organization-team-employee/[id]/index.tsx diff --git a/apps/web/pages/api/organization-team-join/[id]/[action].ts b/apps/web/pages/others/organization-team-join/[id]/[action].ts similarity index 100% rename from apps/web/pages/api/organization-team-join/[id]/[action].ts rename to apps/web/pages/others/organization-team-join/[id]/[action].ts diff --git a/apps/web/pages/api/organization-team-join/index.ts b/apps/web/pages/others/organization-team-join/index.ts similarity index 100% rename from apps/web/pages/api/organization-team-join/index.ts rename to apps/web/pages/others/organization-team-join/index.ts diff --git a/apps/web/pages/api/organization-team-join/resend-code.ts b/apps/web/pages/others/organization-team-join/resend-code.ts similarity index 100% rename from apps/web/pages/api/organization-team-join/resend-code.ts rename to apps/web/pages/others/organization-team-join/resend-code.ts diff --git a/apps/web/pages/api/organization-team-join/validate.ts b/apps/web/pages/others/organization-team-join/validate.ts similarity index 100% rename from apps/web/pages/api/organization-team-join/validate.ts rename to apps/web/pages/others/organization-team-join/validate.ts diff --git a/apps/web/pages/api/organization-team/[id].ts b/apps/web/pages/others/organization-team/[id].ts similarity index 100% rename from apps/web/pages/api/organization-team/[id].ts rename to apps/web/pages/others/organization-team/[id].ts diff --git a/apps/web/pages/api/organization-team/employee/[id].ts b/apps/web/pages/others/organization-team/employee/[id].ts similarity index 100% rename from apps/web/pages/api/organization-team/employee/[id].ts rename to apps/web/pages/others/organization-team/employee/[id].ts diff --git a/apps/web/pages/api/organization-team/index.ts b/apps/web/pages/others/organization-team/index.ts similarity index 100% rename from apps/web/pages/api/organization-team/index.ts rename to apps/web/pages/others/organization-team/index.ts diff --git a/apps/web/pages/api/organization-team/teams/[id].ts b/apps/web/pages/others/organization-team/teams/[id].ts similarity index 100% rename from apps/web/pages/api/organization-team/teams/[id].ts rename to apps/web/pages/others/organization-team/teams/[id].ts diff --git a/apps/web/pages/api/public/team/[profileLink]/[teamId].ts b/apps/web/pages/others/public/team/[profileLink]/[teamId].ts similarity index 100% rename from apps/web/pages/api/public/team/[profileLink]/[teamId].ts rename to apps/web/pages/others/public/team/[profileLink]/[teamId].ts diff --git a/apps/web/pages/api/role-permissions/[id].ts b/apps/web/pages/others/role-permissions/[id].ts similarity index 100% rename from apps/web/pages/api/role-permissions/[id].ts rename to apps/web/pages/others/role-permissions/[id].ts diff --git a/apps/web/pages/api/roles/[id].ts b/apps/web/pages/others/roles/[id].ts similarity index 100% rename from apps/web/pages/api/roles/[id].ts rename to apps/web/pages/others/roles/[id].ts diff --git a/apps/web/pages/api/roles/index.ts b/apps/web/pages/others/roles/index.ts similarity index 100% rename from apps/web/pages/api/roles/index.ts rename to apps/web/pages/others/roles/index.ts diff --git a/apps/web/pages/api/tags/[id].ts b/apps/web/pages/others/tags/[id].ts similarity index 100% rename from apps/web/pages/api/tags/[id].ts rename to apps/web/pages/others/tags/[id].ts diff --git a/apps/web/pages/api/tags/index.tsx b/apps/web/pages/others/tags/index.tsx similarity index 100% rename from apps/web/pages/api/tags/index.tsx rename to apps/web/pages/others/tags/index.tsx diff --git a/apps/web/pages/api/tags/level.ts b/apps/web/pages/others/tags/level.ts similarity index 100% rename from apps/web/pages/api/tags/level.ts rename to apps/web/pages/others/tags/level.ts diff --git a/apps/web/pages/api/task-priorities/[id].ts b/apps/web/pages/others/task-priorities/[id].ts similarity index 100% rename from apps/web/pages/api/task-priorities/[id].ts rename to apps/web/pages/others/task-priorities/[id].ts diff --git a/apps/web/pages/api/task-priorities/index.tsx b/apps/web/pages/others/task-priorities/index.tsx similarity index 100% rename from apps/web/pages/api/task-priorities/index.tsx rename to apps/web/pages/others/task-priorities/index.tsx diff --git a/apps/web/pages/api/task-related-issue-types/[id].ts b/apps/web/pages/others/task-related-issue-types/[id].ts similarity index 100% rename from apps/web/pages/api/task-related-issue-types/[id].ts rename to apps/web/pages/others/task-related-issue-types/[id].ts diff --git a/apps/web/pages/api/task-related-issue-types/index.ts b/apps/web/pages/others/task-related-issue-types/index.ts similarity index 100% rename from apps/web/pages/api/task-related-issue-types/index.ts rename to apps/web/pages/others/task-related-issue-types/index.ts diff --git a/apps/web/pages/api/task-sizes/[id].ts b/apps/web/pages/others/task-sizes/[id].ts similarity index 100% rename from apps/web/pages/api/task-sizes/[id].ts rename to apps/web/pages/others/task-sizes/[id].ts diff --git a/apps/web/pages/api/task-sizes/index.tsx b/apps/web/pages/others/task-sizes/index.tsx similarity index 100% rename from apps/web/pages/api/task-sizes/index.tsx rename to apps/web/pages/others/task-sizes/index.tsx diff --git a/apps/web/pages/api/task-statuses/[id].ts b/apps/web/pages/others/task-statuses/[id].ts similarity index 100% rename from apps/web/pages/api/task-statuses/[id].ts rename to apps/web/pages/others/task-statuses/[id].ts diff --git a/apps/web/pages/api/task-statuses/index.tsx b/apps/web/pages/others/task-statuses/index.tsx similarity index 100% rename from apps/web/pages/api/task-statuses/index.tsx rename to apps/web/pages/others/task-statuses/index.tsx diff --git a/apps/web/pages/api/task-versions/[id].ts b/apps/web/pages/others/task-versions/[id].ts similarity index 100% rename from apps/web/pages/api/task-versions/[id].ts rename to apps/web/pages/others/task-versions/[id].ts diff --git a/apps/web/pages/api/task-versions/index.tsx b/apps/web/pages/others/task-versions/index.tsx similarity index 100% rename from apps/web/pages/api/task-versions/index.tsx rename to apps/web/pages/others/task-versions/index.tsx diff --git a/apps/web/pages/api/tasks/[id].ts b/apps/web/pages/others/tasks/[id].ts similarity index 100% rename from apps/web/pages/api/tasks/[id].ts rename to apps/web/pages/others/tasks/[id].ts diff --git a/apps/web/pages/api/tasks/employee/[employeeId].ts b/apps/web/pages/others/tasks/employee/[employeeId].ts similarity index 100% rename from apps/web/pages/api/tasks/employee/[employeeId].ts rename to apps/web/pages/others/tasks/employee/[employeeId].ts diff --git a/apps/web/pages/api/tasks/task-linked-issue.ts b/apps/web/pages/others/tasks/task-linked-issue.ts similarity index 100% rename from apps/web/pages/api/tasks/task-linked-issue.ts rename to apps/web/pages/others/tasks/task-linked-issue.ts diff --git a/apps/web/pages/api/tasks/team.ts b/apps/web/pages/others/tasks/team.ts similarity index 100% rename from apps/web/pages/api/tasks/team.ts rename to apps/web/pages/others/tasks/team.ts diff --git a/apps/web/pages/others/timer/start.ts b/apps/web/pages/others/timer/start.ts new file mode 100644 index 000000000..78bf0c113 --- /dev/null +++ b/apps/web/pages/others/timer/start.ts @@ -0,0 +1,34 @@ +import { TimerSource } from '@app/interfaces/ITimer'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { getTimerStatusRequest, startTimerRequest } from '@app/services/server/requests'; +import { NextApiRequest, NextApiResponse } from 'next'; + +export default async function handler(req: NextApiRequest, res: NextApiResponse) { + const { + $res, + user, + tenantId, + access_token, + organizationId, + taskId, + teamId: organizationTeamId + } = await authenticatedGuard(req, res); + if (!user) return $res(); + + await startTimerRequest( + { + tenantId, + organizationId, + taskId, + logType: 'TRACKED', + source: TimerSource.TEAMS, + tags: [], + organizationTeamId + }, + access_token + ); + + const { data: timerStatus } = await getTimerStatusRequest({ tenantId, organizationId }, access_token); + + return $res.json(timerStatus); +} diff --git a/apps/web/pages/others/timer/status.ts b/apps/web/pages/others/timer/status.ts new file mode 100644 index 000000000..fd993a3dc --- /dev/null +++ b/apps/web/pages/others/timer/status.ts @@ -0,0 +1,12 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { getTimerStatusRequest } from '@app/services/server/requests'; +import { NextApiRequest, NextApiResponse } from 'next'; + +export default async function handler(req: NextApiRequest, res: NextApiResponse) { + const { $res, user, tenantId, access_token, organizationId } = await authenticatedGuard(req, res); + if (!user) return $res(); + + const { data } = await getTimerStatusRequest({ tenantId, organizationId }, access_token); + + $res.json(data); +} diff --git a/apps/web/pages/others/timer/stop.ts b/apps/web/pages/others/timer/stop.ts new file mode 100644 index 000000000..155c8ffb6 --- /dev/null +++ b/apps/web/pages/others/timer/stop.ts @@ -0,0 +1,31 @@ +/* eslint-disable no-mixed-spaces-and-tabs */ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { getTimerStatusRequest, stopTimerRequest } from '@app/services/server/requests'; +import { NextApiRequest, NextApiResponse } from 'next'; + +export default async function handler(req: NextApiRequest, res: NextApiResponse) { + const { $res, user, tenantId, access_token, organizationId, taskId } = await authenticatedGuard(req, res); + if (!user) return $res(); + + const { source } = req.body; + await stopTimerRequest( + { + tenantId, + organizationId, + logType: 'TRACKED', + source: source, + tags: [], + // Task id is optional in case timer is already started in another source + ...(taskId + ? { + taskId + } + : {}) + }, + access_token + ); + + const { data: timerStatus } = await getTimerStatusRequest({ tenantId, organizationId }, access_token); + + return $res.json(timerStatus); +} diff --git a/apps/web/pages/others/timer/sync.ts b/apps/web/pages/others/timer/sync.ts new file mode 100644 index 000000000..84f501bd8 --- /dev/null +++ b/apps/web/pages/others/timer/sync.ts @@ -0,0 +1,30 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { getTimerStatusRequest, syncTimeSlotRequest } from '@app/services/server/requests'; +import { NextApiRequest, NextApiResponse } from 'next'; + +export default async function handler(req: NextApiRequest, res: NextApiResponse) { + const { $res, user, tenantId, access_token, organizationId } = await authenticatedGuard(req, res); + if (!user) return $res(); + + if (req.method !== 'POST') { + $res.status(405).send({}); + return; + } + + const { source } = req.body; + await syncTimeSlotRequest( + { + tenantId, + organizationId, + logType: 'TRACKED', + source, + employeeId: user.employee.id, + duration: 5 + }, + access_token + ); + + const { data: timerStatus } = await getTimerStatusRequest({ tenantId, organizationId }, access_token); + + return $res.json(timerStatus); +} diff --git a/apps/web/pages/api/timer/timesheet/all-statistics-tasks.ts b/apps/web/pages/others/timer/timesheet/all-statistics-tasks.ts similarity index 100% rename from apps/web/pages/api/timer/timesheet/all-statistics-tasks.ts rename to apps/web/pages/others/timer/timesheet/all-statistics-tasks.ts diff --git a/apps/web/pages/api/timer/timesheet/index.ts b/apps/web/pages/others/timer/timesheet/index.ts similarity index 100% rename from apps/web/pages/api/timer/timesheet/index.ts rename to apps/web/pages/others/timer/timesheet/index.ts diff --git a/apps/web/pages/api/timer/timesheet/statistics-tasks.ts b/apps/web/pages/others/timer/timesheet/statistics-tasks.ts similarity index 100% rename from apps/web/pages/api/timer/timesheet/statistics-tasks.ts rename to apps/web/pages/others/timer/timesheet/statistics-tasks.ts diff --git a/apps/web/pages/api/timer/toggle.ts b/apps/web/pages/others/timer/toggle.ts similarity index 100% rename from apps/web/pages/api/timer/toggle.ts rename to apps/web/pages/others/timer/toggle.ts diff --git a/apps/web/pages/api/user/[id].ts b/apps/web/pages/others/user/[id].ts similarity index 100% rename from apps/web/pages/api/user/[id].ts rename to apps/web/pages/others/user/[id].ts diff --git a/apps/web/pages/api/user/me.ts b/apps/web/pages/others/user/me.ts similarity index 100% rename from apps/web/pages/api/user/me.ts rename to apps/web/pages/others/user/me.ts diff --git a/apps/web/pages/api/user/reset.ts b/apps/web/pages/others/user/reset.ts similarity index 100% rename from apps/web/pages/api/user/reset.ts rename to apps/web/pages/others/user/reset.ts From 0a7395789455da8293b7053a82ff279aa663e68c Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Fri, 5 Jan 2024 20:41:12 +0200 Subject: [PATCH 05/22] feat: move /timer to app folder --- .../api/timer/start/{start.ts => route.ts} | 11 ++++++----- .../api/timer/status/{status.ts => route.ts} | 11 ++++++----- .../app/api/timer/stop/{stop.ts => route.ts} | 14 ++++++++------ .../app/api/timer/sync/{sync.ts => route.ts} | 19 ++++++++----------- 4 files changed, 28 insertions(+), 27 deletions(-) rename apps/web/app/api/timer/start/{start.ts => route.ts} (74%) rename apps/web/app/api/timer/status/{status.ts => route.ts} (61%) rename apps/web/app/api/timer/stop/{stop.ts => route.ts} (70%) rename apps/web/app/api/timer/sync/{sync.ts => route.ts} (62%) diff --git a/apps/web/app/api/timer/start/start.ts b/apps/web/app/api/timer/start/route.ts similarity index 74% rename from apps/web/app/api/timer/start/start.ts rename to apps/web/app/api/timer/start/route.ts index 78bf0c113..f782a7d2b 100644 --- a/apps/web/app/api/timer/start/start.ts +++ b/apps/web/app/api/timer/start/route.ts @@ -1,9 +1,10 @@ import { TimerSource } from '@app/interfaces/ITimer'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { getTimerStatusRequest, startTimerRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; +import { NextResponse } from 'next/server'; -export default async function handler(req: NextApiRequest, res: NextApiResponse) { +export default async function POST(req: Request) { + const res = new NextResponse(); const { $res, user, @@ -13,7 +14,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) taskId, teamId: organizationTeamId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return $res('Unauthorized'); await startTimerRequest( { @@ -30,5 +31,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const { data: timerStatus } = await getTimerStatusRequest({ tenantId, organizationId }, access_token); - return $res.json(timerStatus); + return $res(timerStatus); } diff --git a/apps/web/app/api/timer/status/status.ts b/apps/web/app/api/timer/status/route.ts similarity index 61% rename from apps/web/app/api/timer/status/status.ts rename to apps/web/app/api/timer/status/route.ts index fd993a3dc..a123a3e06 100644 --- a/apps/web/app/api/timer/status/status.ts +++ b/apps/web/app/api/timer/status/route.ts @@ -1,12 +1,13 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { getTimerStatusRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; +import { NextResponse } from 'next/server'; -export default async function handler(req: NextApiRequest, res: NextApiResponse) { +export async function GET(req: Request) { + const res = new NextResponse(); const { $res, user, tenantId, access_token, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return $res('Unauthorized'); const { data } = await getTimerStatusRequest({ tenantId, organizationId }, access_token); - $res.json(data); + $res(data); } diff --git a/apps/web/app/api/timer/stop/stop.ts b/apps/web/app/api/timer/stop/route.ts similarity index 70% rename from apps/web/app/api/timer/stop/stop.ts rename to apps/web/app/api/timer/stop/route.ts index 155c8ffb6..c37bf401b 100644 --- a/apps/web/app/api/timer/stop/stop.ts +++ b/apps/web/app/api/timer/stop/route.ts @@ -1,13 +1,15 @@ /* eslint-disable no-mixed-spaces-and-tabs */ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { getTimerStatusRequest, stopTimerRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; +import { NextResponse } from 'next/server'; -export default async function handler(req: NextApiRequest, res: NextApiResponse) { +export async function POST(req: Request) { + const res = new NextResponse(); const { $res, user, tenantId, access_token, organizationId, taskId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return $res('Unauthorized'); - const { source } = req.body; + const body = req.body as unknown as { source: any }; + const { source } = body; await stopTimerRequest( { tenantId, @@ -27,5 +29,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const { data: timerStatus } = await getTimerStatusRequest({ tenantId, organizationId }, access_token); - return $res.json(timerStatus); + return $res(timerStatus); } diff --git a/apps/web/app/api/timer/sync/sync.ts b/apps/web/app/api/timer/sync/route.ts similarity index 62% rename from apps/web/app/api/timer/sync/sync.ts rename to apps/web/app/api/timer/sync/route.ts index 84f501bd8..b91fbb2e1 100644 --- a/apps/web/app/api/timer/sync/sync.ts +++ b/apps/web/app/api/timer/sync/route.ts @@ -1,17 +1,14 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { getTimerStatusRequest, syncTimeSlotRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; +import { NextResponse } from 'next/server'; -export default async function handler(req: NextApiRequest, res: NextApiResponse) { +export async function POST(req: Request) { + const res = new NextResponse(); const { $res, user, tenantId, access_token, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return $res('Unauthorized'); - if (req.method !== 'POST') { - $res.status(405).send({}); - return; - } - - const { source } = req.body; + const body = req.body as unknown as { source: any }; + const { source } = body; await syncTimeSlotRequest( { tenantId, @@ -26,5 +23,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const { data: timerStatus } = await getTimerStatusRequest({ tenantId, organizationId }, access_token); - return $res.json(timerStatus); + return $res(timerStatus); } From 7ec906104eb4c5191ed989fd526bbe241449f546 Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Fri, 5 Jan 2024 21:03:31 +0200 Subject: [PATCH 06/22] feat: move /tasks/* to app folder --- apps/web/app/api/tasks/[id]/route.ts | 59 +++++++++++++++++++ .../api/tasks/employee/[employeeId]/route.ts | 25 ++++++++ .../app/api/tasks/task-linked-issue/route.ts | 27 +++++++++ apps/web/app/api/tasks/team/route.ts | 52 ++++++++++++++++ apps/web/app/api/user/me/route.ts | 2 +- 5 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 apps/web/app/api/tasks/[id]/route.ts create mode 100644 apps/web/app/api/tasks/employee/[employeeId]/route.ts create mode 100644 apps/web/app/api/tasks/task-linked-issue/route.ts create mode 100644 apps/web/app/api/tasks/team/route.ts diff --git a/apps/web/app/api/tasks/[id]/route.ts b/apps/web/app/api/tasks/[id]/route.ts new file mode 100644 index 000000000..e9504e9e7 --- /dev/null +++ b/apps/web/app/api/tasks/[id]/route.ts @@ -0,0 +1,59 @@ +import { ITeamTask } from '@app/interfaces/ITask'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { getTeamTasksRequest, updateTaskRequest, getTaskByIdRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user, tenantId, access_token, organizationId } = await authenticatedGuard(req, res); + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + + const { id: taskId } = searchParams as unknown as { id: string }; + + return $res( + await getTaskByIdRequest({ + taskId: taskId as string, + tenantId, + organizationId, + bearer_token: access_token + }) + ); +} + +export async function PUT(req: Request) { + const res = new NextResponse(); + const { $res, user, tenantId, access_token, organizationId, projectId, teamId } = await authenticatedGuard( + req, + res + ); + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + + const { id: taskId } = searchParams as unknown as { id: string }; + const body = req.body as unknown as ITeamTask; + + delete body.selectedTeam; + delete body.rootEpic; + + await updateTaskRequest( + { + data: body, + id: taskId as string + }, + access_token + ); + + const { data: tasks } = await getTeamTasksRequest({ + tenantId, + organizationId, + projectId, + teamId, + bearer_token: access_token + }); + + $res(tasks); +} +// Unauthorized; diff --git a/apps/web/app/api/tasks/employee/[employeeId]/route.ts b/apps/web/app/api/tasks/employee/[employeeId]/route.ts new file mode 100644 index 000000000..c012dd2df --- /dev/null +++ b/apps/web/app/api/tasks/employee/[employeeId]/route.ts @@ -0,0 +1,25 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { deleteEmployeeFromTasksRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function DELETE(req: Request) { + const res = new NextResponse(); + const { $res, user, tenantId, access_token: bearer_token } = await authenticatedGuard(req, res); + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + + const { employeeId, organizationTeamId } = searchParams as unknown as { + employeeId: string; + organizationTeamId: string; + }; + + $res( + await deleteEmployeeFromTasksRequest({ + tenantId, + employeeId, + organizationTeamId, + bearer_token + }) + ); +} diff --git a/apps/web/app/api/tasks/task-linked-issue/route.ts b/apps/web/app/api/tasks/task-linked-issue/route.ts new file mode 100644 index 000000000..2af790fd3 --- /dev/null +++ b/apps/web/app/api/tasks/task-linked-issue/route.ts @@ -0,0 +1,27 @@ +import { ITaskLinkedIssue, LinkedTaskIssue } from '@app/interfaces/ITask'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { createTaskLinkedIsssue, updateTaskLinkedIssue } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const res = new NextResponse(); + const { $res, user, tenantId, access_token } = await authenticatedGuard(req, res); + if (!user) return $res('Unauthorized'); + + const body = req.body as unknown as ITaskLinkedIssue; + const response = await createTaskLinkedIsssue(body, access_token, tenantId); + + $res(response.data); +} + +export async function PUT(req: Request) { + const res = new NextResponse(); + const { $res, user, tenantId, access_token } = await authenticatedGuard(req, res); + if (!user) return $res('Unauthorized'); + + const body = req.body as unknown as LinkedTaskIssue; + const response = await updateTaskLinkedIssue(body, access_token, tenantId); + + $res(response.data); + return; +} diff --git a/apps/web/app/api/tasks/team/route.ts b/apps/web/app/api/tasks/team/route.ts new file mode 100644 index 000000000..2b250afaa --- /dev/null +++ b/apps/web/app/api/tasks/team/route.ts @@ -0,0 +1,52 @@ +import { getActiveTeamIdCookie } from '@app/helpers/cookies'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { createTaskRequest, getTeamTasksRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const res = new NextResponse(); + const { $res, user, tenantId, organizationId, access_token, projectId, teamId } = await authenticatedGuard( + req, + res + ); + if (!user) return $res('Unauthorized'); + + const body: Record = req.body || {}; + + const title = body.title?.trim() || ''; + if (title.trim().length < 2) { + return $res({ errors: { name: 'Invalid task name !' } }); + } + const activeTeam = getActiveTeamIdCookie({ req, res }); + + await createTaskRequest({ + bearer_token: access_token, + data: { + description: '', + status: 'open', + members: user?.employee?.id ? [{ id: user.employee.id }] : [], + teams: [ + { + id: activeTeam + } + ], + tags: [], + organizationId, + tenantId, + projectId, + estimate: 0, + ...body, + title // this must be called after ...body + } + }); + + const { data: tasks } = await getTeamTasksRequest({ + tenantId, + organizationId, + projectId, + teamId, + bearer_token: access_token + }); + + $res(tasks); +} diff --git a/apps/web/app/api/user/me/route.ts b/apps/web/app/api/user/me/route.ts index 6c0ef1079..e76e83312 100644 --- a/apps/web/app/api/user/me/route.ts +++ b/apps/web/app/api/user/me/route.ts @@ -4,7 +4,7 @@ import { NextResponse } from 'next/server'; export default async function GET(req: Request) { const res = new NextResponse(); const { $res, user } = await authenticatedGuard(req, res); - if (!user) return $res('unhautorized'); + if (!user) return $res('Unauthorized'); $res(user); } From 66d6850e94b2806da10fb75059b24c11b5b4a948 Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Fri, 5 Jan 2024 21:51:31 +0200 Subject: [PATCH 07/22] feat: move others task routes to app folder --- .../web/app/api/task-priorities/[id]/route.ts | 42 +++++++++++++++++ apps/web/app/api/task-priorities/route.ts | 35 +++++++++++++++ .../task-related-issue-types/[id]/route.ts | 45 +++++++++++++++++++ .../app/api/task-related-issue-types/route.ts | 37 +++++++++++++++ apps/web/app/api/task-sizes/[id]/route.ts | 42 +++++++++++++++++ apps/web/app/api/task-sizes/route.ts | 34 ++++++++++++++ apps/web/app/api/task-statuses/[id]/route.ts | 42 +++++++++++++++++ apps/web/app/api/task-statuses/route.ts | 34 ++++++++++++++ apps/web/app/api/task-versions/[id]/route.ts | 42 +++++++++++++++++ apps/web/app/api/task-versions/route.ts | 34 ++++++++++++++ apps/web/app/api/user/reset/route.ts | 2 +- .../public/team/[profileLink]/[teamId].ts | 0 .../_moved}/task-priorities/[id].ts | 0 .../_moved}/task-priorities/index.tsx | 0 .../_moved}/task-related-issue-types/[id].ts | 0 .../_moved}/task-related-issue-types/index.ts | 0 .../{others => api/_moved}/task-sizes/[id].ts | 0 .../_moved}/task-sizes/index.tsx | 0 .../_moved}/task-statuses/[id].ts | 0 .../_moved}/task-statuses/index.tsx | 0 .../_moved}/task-versions/[id].ts | 0 .../_moved}/task-versions/index.tsx | 0 .../{others => api/_moved}/tasks/[id].ts | 0 .../_moved}/tasks/employee/[employeeId].ts | 0 .../_moved}/tasks/task-linked-issue.ts | 0 .../{others => api/_moved}/tasks/team.ts | 0 .../{others => api/_moved}/timer/start.ts | 0 .../{others => api/_moved}/timer/status.ts | 0 .../{others => api/_moved}/timer/stop.ts | 0 .../{others => api/_moved}/timer/sync.ts | 0 .../timer/timesheet/all-statistics-tasks.ts | 0 .../_moved}/timer/timesheet/index.ts | 0 .../timer/timesheet/statistics-tasks.ts | 0 .../{others => api/_moved}/timer/toggle.ts | 0 .../pages/{others => api/_moved}/user/[id].ts | 0 .../pages/{others => api/_moved}/user/me.ts | 0 .../{others => api/_moved}/user/reset.ts | 0 apps/web/pages/{others => api}/auth/login.ts | 0 .../pages/{others => api}/auth/meet/jwt.ts | 0 .../web/pages/{others => api}/auth/refresh.ts | 0 .../pages/{others => api}/auth/register.ts | 0 .../pages/{others => api}/auth/send-code.ts | 0 .../auth/signin-email-confirm.ts | 0 .../{others => api}/auth/signin-email.ts | 0 .../{others => api}/auth/signin-workspace.ts | 0 .../pages/{others => api}/auth/verify/code.ts | 0 .../auth/verify/resend-link.ts | 0 .../{others => api}/auth/verify/token.ts | 0 .../email-reset/request-change-email.ts | 0 .../email-reset/verify-change-email.ts | 0 .../pages/{others => api}/employee/working.ts | 0 .../integration-tenant/[id].ts | 0 .../remember/state/index.ts | 0 .../integration/github/install.ts | 0 .../integration/github/metadata.ts | 0 .../integration/github/oauth.ts | 0 .../integration/github/repositories.ts | 0 .../integration/github/repository/sync.ts | 0 .../integration/types/index.ts | 0 apps/web/pages/{others => api}/invite/[id].ts | 0 .../pages/{others => api}/invite/emails.ts | 0 .../web/pages/{others => api}/invite/index.ts | 0 .../pages/{others => api}/invite/resend.ts | 0 .../invite/validate-by-code.ts | 0 .../pages/{others => api}/issue-types/[id].ts | 0 .../{others => api}/issue-types/index.tsx | 0 .../pages/{others => api}/languages/index.ts | 0 .../organization-projects/[id].ts | 0 .../organization-projects/setting/[id].ts | 0 .../[id]/active-task.ts | 0 .../organization-team-employee/[id]/index.tsx | 0 .../organization-team-join/[id]/[action].ts | 0 .../organization-team-join/index.ts | 0 .../organization-team-join/resend-code.ts | 0 .../organization-team-join/validate.ts | 0 .../{others => api}/organization-team/[id].ts | 0 .../organization-team/employee/[id].ts | 0 .../organization-team/index.ts | 0 .../organization-team/teams/[id].ts | 0 .../{others => api}/role-permissions/[id].ts | 0 apps/web/pages/{others => api}/roles/[id].ts | 0 apps/web/pages/{others => api}/roles/index.ts | 0 apps/web/pages/{others => api}/tags/[id].ts | 0 apps/web/pages/{others => api}/tags/index.tsx | 0 apps/web/pages/{others => api}/tags/level.ts | 0 85 files changed, 388 insertions(+), 1 deletion(-) create mode 100644 apps/web/app/api/task-priorities/[id]/route.ts create mode 100644 apps/web/app/api/task-priorities/route.ts create mode 100644 apps/web/app/api/task-related-issue-types/[id]/route.ts create mode 100644 apps/web/app/api/task-related-issue-types/route.ts create mode 100644 apps/web/app/api/task-sizes/[id]/route.ts create mode 100644 apps/web/app/api/task-sizes/route.ts create mode 100644 apps/web/app/api/task-statuses/[id]/route.ts create mode 100644 apps/web/app/api/task-statuses/route.ts create mode 100644 apps/web/app/api/task-versions/[id]/route.ts create mode 100644 apps/web/app/api/task-versions/route.ts rename apps/web/pages/{others => api/_moved}/public/team/[profileLink]/[teamId].ts (100%) rename apps/web/pages/{others => api/_moved}/task-priorities/[id].ts (100%) rename apps/web/pages/{others => api/_moved}/task-priorities/index.tsx (100%) rename apps/web/pages/{others => api/_moved}/task-related-issue-types/[id].ts (100%) rename apps/web/pages/{others => api/_moved}/task-related-issue-types/index.ts (100%) rename apps/web/pages/{others => api/_moved}/task-sizes/[id].ts (100%) rename apps/web/pages/{others => api/_moved}/task-sizes/index.tsx (100%) rename apps/web/pages/{others => api/_moved}/task-statuses/[id].ts (100%) rename apps/web/pages/{others => api/_moved}/task-statuses/index.tsx (100%) rename apps/web/pages/{others => api/_moved}/task-versions/[id].ts (100%) rename apps/web/pages/{others => api/_moved}/task-versions/index.tsx (100%) rename apps/web/pages/{others => api/_moved}/tasks/[id].ts (100%) rename apps/web/pages/{others => api/_moved}/tasks/employee/[employeeId].ts (100%) rename apps/web/pages/{others => api/_moved}/tasks/task-linked-issue.ts (100%) rename apps/web/pages/{others => api/_moved}/tasks/team.ts (100%) rename apps/web/pages/{others => api/_moved}/timer/start.ts (100%) rename apps/web/pages/{others => api/_moved}/timer/status.ts (100%) rename apps/web/pages/{others => api/_moved}/timer/stop.ts (100%) rename apps/web/pages/{others => api/_moved}/timer/sync.ts (100%) rename apps/web/pages/{others => api/_moved}/timer/timesheet/all-statistics-tasks.ts (100%) rename apps/web/pages/{others => api/_moved}/timer/timesheet/index.ts (100%) rename apps/web/pages/{others => api/_moved}/timer/timesheet/statistics-tasks.ts (100%) rename apps/web/pages/{others => api/_moved}/timer/toggle.ts (100%) rename apps/web/pages/{others => api/_moved}/user/[id].ts (100%) rename apps/web/pages/{others => api/_moved}/user/me.ts (100%) rename apps/web/pages/{others => api/_moved}/user/reset.ts (100%) rename apps/web/pages/{others => api}/auth/login.ts (100%) rename apps/web/pages/{others => api}/auth/meet/jwt.ts (100%) rename apps/web/pages/{others => api}/auth/refresh.ts (100%) rename apps/web/pages/{others => api}/auth/register.ts (100%) rename apps/web/pages/{others => api}/auth/send-code.ts (100%) rename apps/web/pages/{others => api}/auth/signin-email-confirm.ts (100%) rename apps/web/pages/{others => api}/auth/signin-email.ts (100%) rename apps/web/pages/{others => api}/auth/signin-workspace.ts (100%) rename apps/web/pages/{others => api}/auth/verify/code.ts (100%) rename apps/web/pages/{others => api}/auth/verify/resend-link.ts (100%) rename apps/web/pages/{others => api}/auth/verify/token.ts (100%) rename apps/web/pages/{others => api}/email-reset/request-change-email.ts (100%) rename apps/web/pages/{others => api}/email-reset/verify-change-email.ts (100%) rename apps/web/pages/{others => api}/employee/working.ts (100%) rename apps/web/pages/{others => api}/integration-tenant/[id].ts (100%) rename apps/web/pages/{others => api}/integration-tenant/remember/state/index.ts (100%) rename apps/web/pages/{others => api}/integration/github/install.ts (100%) rename apps/web/pages/{others => api}/integration/github/metadata.ts (100%) rename apps/web/pages/{others => api}/integration/github/oauth.ts (100%) rename apps/web/pages/{others => api}/integration/github/repositories.ts (100%) rename apps/web/pages/{others => api}/integration/github/repository/sync.ts (100%) rename apps/web/pages/{others => api}/integration/types/index.ts (100%) rename apps/web/pages/{others => api}/invite/[id].ts (100%) rename apps/web/pages/{others => api}/invite/emails.ts (100%) rename apps/web/pages/{others => api}/invite/index.ts (100%) rename apps/web/pages/{others => api}/invite/resend.ts (100%) rename apps/web/pages/{others => api}/invite/validate-by-code.ts (100%) rename apps/web/pages/{others => api}/issue-types/[id].ts (100%) rename apps/web/pages/{others => api}/issue-types/index.tsx (100%) rename apps/web/pages/{others => api}/languages/index.ts (100%) rename apps/web/pages/{others => api}/organization-projects/[id].ts (100%) rename apps/web/pages/{others => api}/organization-projects/setting/[id].ts (100%) rename apps/web/pages/{others => api}/organization-team-employee/[id]/active-task.ts (100%) rename apps/web/pages/{others => api}/organization-team-employee/[id]/index.tsx (100%) rename apps/web/pages/{others => api}/organization-team-join/[id]/[action].ts (100%) rename apps/web/pages/{others => api}/organization-team-join/index.ts (100%) rename apps/web/pages/{others => api}/organization-team-join/resend-code.ts (100%) rename apps/web/pages/{others => api}/organization-team-join/validate.ts (100%) rename apps/web/pages/{others => api}/organization-team/[id].ts (100%) rename apps/web/pages/{others => api}/organization-team/employee/[id].ts (100%) rename apps/web/pages/{others => api}/organization-team/index.ts (100%) rename apps/web/pages/{others => api}/organization-team/teams/[id].ts (100%) rename apps/web/pages/{others => api}/role-permissions/[id].ts (100%) rename apps/web/pages/{others => api}/roles/[id].ts (100%) rename apps/web/pages/{others => api}/roles/index.ts (100%) rename apps/web/pages/{others => api}/tags/[id].ts (100%) rename apps/web/pages/{others => api}/tags/index.tsx (100%) rename apps/web/pages/{others => api}/tags/level.ts (100%) diff --git a/apps/web/app/api/task-priorities/[id]/route.ts b/apps/web/app/api/task-priorities/[id]/route.ts new file mode 100644 index 000000000..c634bb93d --- /dev/null +++ b/apps/web/app/api/task-priorities/[id]/route.ts @@ -0,0 +1,42 @@ +import { ITaskPrioritiesCreate } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { deleteTaskPrioritiesRequest, editTaskPrioritiesRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function PUT(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + const { id } = searchParams as unknown as { id: string }; + + const datas = req.body as unknown as ITaskPrioritiesCreate; + return $res( + await editTaskPrioritiesRequest({ + id, + datas, + bearer_token: access_token, + tenantId + }) + ); +} + +export async function DELETE(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + const { id } = searchParams as unknown as { id: string }; + + return $res( + await deleteTaskPrioritiesRequest({ + id, + bearer_token: access_token, + tenantId + }) + ); +} diff --git a/apps/web/app/api/task-priorities/route.ts b/apps/web/app/api/task-priorities/route.ts new file mode 100644 index 000000000..9c4c9b277 --- /dev/null +++ b/apps/web/app/api/task-priorities/route.ts @@ -0,0 +1,35 @@ +import { ITaskPrioritiesCreate } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { createPrioritiesRequest, getTaskPrioritiesListRequest } from '@app/services/server/requests/task-priorities'; +import { NextApiRequest, NextApiResponse } from 'next'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + + const { organizationTeamId } = searchParams as unknown as { organizationTeamId: string }; + + const par = { + tenantId, + organizationId, + organizationTeamId: (organizationTeamId as string) || null + }; + + return $res(await getTaskPrioritiesListRequest(par, access_token)); +} + +export async function POST(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const body = req.body as unknown as ITaskPrioritiesCreate; + + return $res(await createPrioritiesRequest(body, access_token, body?.tenantId)); +} 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 new file mode 100644 index 000000000..011bd13b8 --- /dev/null +++ b/apps/web/app/api/task-related-issue-types/[id]/route.ts @@ -0,0 +1,45 @@ +import { ITaskRelatedIssueTypeCreate } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { + deleteTaskRelatedIssueTypeRequest, + editTaskRelatedIssueTypeRequest +} from '@app/services/server/requests/task-related-issue-type'; +import { NextResponse } from 'next/server'; + +export async function PUT(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + const { id } = searchParams as unknown as { id: string }; + + const datas = req.body as unknown as ITaskRelatedIssueTypeCreate; + return $res( + await editTaskRelatedIssueTypeRequest({ + id, + datas, + bearer_token: access_token, + tenantId + }) + ); +} + +export async function DELETE(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + const { id } = searchParams as unknown as { id: string }; + + return $res( + await deleteTaskRelatedIssueTypeRequest({ + id, + bearer_token: access_token, + tenantId + }) + ); +} diff --git a/apps/web/app/api/task-related-issue-types/route.ts b/apps/web/app/api/task-related-issue-types/route.ts new file mode 100644 index 000000000..63b43ea9e --- /dev/null +++ b/apps/web/app/api/task-related-issue-types/route.ts @@ -0,0 +1,37 @@ +import { ITaskRelatedIssueTypeCreate } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { + createRelatedIssueTypeRequest, + getTaskRelatedIssueTypeListRequest +} from '@app/services/server/requests/task-related-issue-type'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + + const { organizationTeamId } = searchParams as unknown as { organizationTeamId: string }; + + const par = { + tenantId, + organizationId, + organizationTeamId: (organizationTeamId as string) || null + }; + + return $res(await getTaskRelatedIssueTypeListRequest(par, access_token)); +} + +export async function POST(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const body = req.body as unknown as ITaskRelatedIssueTypeCreate; + + return $res(await createRelatedIssueTypeRequest(body, access_token, body?.tenantId)); +} diff --git a/apps/web/app/api/task-sizes/[id]/route.ts b/apps/web/app/api/task-sizes/[id]/route.ts new file mode 100644 index 000000000..498f19343 --- /dev/null +++ b/apps/web/app/api/task-sizes/[id]/route.ts @@ -0,0 +1,42 @@ +import { ITaskSizesCreate } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { deleteTaskSizesRequest, editTaskSizesRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function PUT(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + const { id } = searchParams as unknown as { id: string }; + + const datas = req.body as unknown as ITaskSizesCreate; + return $res( + await editTaskSizesRequest({ + id, + datas, + bearer_token: access_token, + tenantId + }) + ); +} + +export async function DELETE(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + const { id } = searchParams as unknown as { id: string }; + + return $res( + await deleteTaskSizesRequest({ + id, + bearer_token: access_token, + tenantId + }) + ); +} diff --git a/apps/web/app/api/task-sizes/route.ts b/apps/web/app/api/task-sizes/route.ts new file mode 100644 index 000000000..6063a9325 --- /dev/null +++ b/apps/web/app/api/task-sizes/route.ts @@ -0,0 +1,34 @@ +import { ITaskSizesCreate } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { createSizesRequest, getTaskSizesListRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + + const { organizationTeamId } = searchParams as unknown as { organizationTeamId: string }; + + const par = { + tenantId, + organizationId, + organizationTeamId: (organizationTeamId as string) || null + }; + + return $res(await getTaskSizesListRequest(par, access_token)); +} + +export async function POST(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const body = req.body as unknown as ITaskSizesCreate; + + return $res(await createSizesRequest(body, access_token, body?.tenantId)); +} diff --git a/apps/web/app/api/task-statuses/[id]/route.ts b/apps/web/app/api/task-statuses/[id]/route.ts new file mode 100644 index 000000000..245ecf602 --- /dev/null +++ b/apps/web/app/api/task-statuses/[id]/route.ts @@ -0,0 +1,42 @@ +import { ITaskStatusCreate } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { deleteTaskStatusRequest, editTaskStatusRequest } from '@app/services/server/requests/taskStatus'; +import { NextResponse } from 'next/server'; + +export async function PUT(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + const { id } = searchParams as unknown as { id: string }; + + const datas = req.body as unknown as ITaskStatusCreate; + return $res( + await editTaskStatusRequest({ + id, + datas, + bearer_token: access_token, + tenantId + }) + ); +} + +export async function DELETE(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + const { id } = searchParams as unknown as { id: string }; + + return $res( + await deleteTaskStatusRequest({ + id, + bearer_token: access_token, + tenantId + }) + ); +} diff --git a/apps/web/app/api/task-statuses/route.ts b/apps/web/app/api/task-statuses/route.ts new file mode 100644 index 000000000..f307de118 --- /dev/null +++ b/apps/web/app/api/task-statuses/route.ts @@ -0,0 +1,34 @@ +import { ITaskStatusCreate } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { createStatusRequest, getTaskStatusListRequest } from '@app/services/server/requests/taskStatus'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + + const { organizationTeamId } = searchParams as unknown as { organizationTeamId: string }; + + const par = { + tenantId, + organizationId, + organizationTeamId: (organizationTeamId as string) || null + }; + + return $res(await getTaskStatusListRequest(par, access_token)); +} + +export async function POST(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const body = req.body as unknown as ITaskStatusCreate; + + return $res(await createStatusRequest(body, access_token, body?.tenantId)); +} diff --git a/apps/web/app/api/task-versions/[id]/route.ts b/apps/web/app/api/task-versions/[id]/route.ts new file mode 100644 index 000000000..155a04cfa --- /dev/null +++ b/apps/web/app/api/task-versions/[id]/route.ts @@ -0,0 +1,42 @@ +import { ITaskVersionCreate } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { deleteTaskVersionRequest, editTaskVersionRequest } from '@app/services/server/requests/task-version'; +import { NextResponse } from 'next/server'; + +export async function PUT(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + const { id } = searchParams as unknown as { id: string }; + + const datas = req.body as unknown as ITaskVersionCreate; + return $res( + await editTaskVersionRequest({ + id, + datas, + bearer_token: access_token, + tenantId + }) + ); +} + +export async function DELETE(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + const { id } = searchParams as unknown as { id: string }; + + return $res( + await deleteTaskVersionRequest({ + id, + bearer_token: access_token, + tenantId + }) + ); +} diff --git a/apps/web/app/api/task-versions/route.ts b/apps/web/app/api/task-versions/route.ts new file mode 100644 index 000000000..d04d94151 --- /dev/null +++ b/apps/web/app/api/task-versions/route.ts @@ -0,0 +1,34 @@ +import { ITaskVersionCreate } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { createVersionRequest, getTaskVersionListRequest } from '@app/services/server/requests/task-version'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + + const { organizationTeamId } = searchParams as unknown as { organizationTeamId: string }; + + const par = { + tenantId, + organizationId, + organizationTeamId: (organizationTeamId as string) || null + }; + + return $res(await getTaskVersionListRequest(par, access_token)); +} + +export async function POST(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const body = req.body as unknown as ITaskVersionCreate; + + return $res(await createVersionRequest(body, access_token, body?.tenantId)); +} diff --git a/apps/web/app/api/user/reset/route.ts b/apps/web/app/api/user/reset/route.ts index bd7c0d6d5..fc6c55b49 100644 --- a/apps/web/app/api/user/reset/route.ts +++ b/apps/web/app/api/user/reset/route.ts @@ -3,7 +3,7 @@ import { authenticatedGuard } from '@app/services/server/guards/authenticated-gu import { resetUserRequest } from '@app/services/server/requests/user'; import { NextResponse } from 'next/server'; -export default async function DELETE(req: Request) { +export async function DELETE(req: Request) { const res = new NextResponse(); const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); if (!user) return $res('Unauthorized'); diff --git a/apps/web/pages/others/public/team/[profileLink]/[teamId].ts b/apps/web/pages/api/_moved/public/team/[profileLink]/[teamId].ts similarity index 100% rename from apps/web/pages/others/public/team/[profileLink]/[teamId].ts rename to apps/web/pages/api/_moved/public/team/[profileLink]/[teamId].ts diff --git a/apps/web/pages/others/task-priorities/[id].ts b/apps/web/pages/api/_moved/task-priorities/[id].ts similarity index 100% rename from apps/web/pages/others/task-priorities/[id].ts rename to apps/web/pages/api/_moved/task-priorities/[id].ts diff --git a/apps/web/pages/others/task-priorities/index.tsx b/apps/web/pages/api/_moved/task-priorities/index.tsx similarity index 100% rename from apps/web/pages/others/task-priorities/index.tsx rename to apps/web/pages/api/_moved/task-priorities/index.tsx diff --git a/apps/web/pages/others/task-related-issue-types/[id].ts b/apps/web/pages/api/_moved/task-related-issue-types/[id].ts similarity index 100% rename from apps/web/pages/others/task-related-issue-types/[id].ts rename to apps/web/pages/api/_moved/task-related-issue-types/[id].ts diff --git a/apps/web/pages/others/task-related-issue-types/index.ts b/apps/web/pages/api/_moved/task-related-issue-types/index.ts similarity index 100% rename from apps/web/pages/others/task-related-issue-types/index.ts rename to apps/web/pages/api/_moved/task-related-issue-types/index.ts diff --git a/apps/web/pages/others/task-sizes/[id].ts b/apps/web/pages/api/_moved/task-sizes/[id].ts similarity index 100% rename from apps/web/pages/others/task-sizes/[id].ts rename to apps/web/pages/api/_moved/task-sizes/[id].ts diff --git a/apps/web/pages/others/task-sizes/index.tsx b/apps/web/pages/api/_moved/task-sizes/index.tsx similarity index 100% rename from apps/web/pages/others/task-sizes/index.tsx rename to apps/web/pages/api/_moved/task-sizes/index.tsx diff --git a/apps/web/pages/others/task-statuses/[id].ts b/apps/web/pages/api/_moved/task-statuses/[id].ts similarity index 100% rename from apps/web/pages/others/task-statuses/[id].ts rename to apps/web/pages/api/_moved/task-statuses/[id].ts diff --git a/apps/web/pages/others/task-statuses/index.tsx b/apps/web/pages/api/_moved/task-statuses/index.tsx similarity index 100% rename from apps/web/pages/others/task-statuses/index.tsx rename to apps/web/pages/api/_moved/task-statuses/index.tsx diff --git a/apps/web/pages/others/task-versions/[id].ts b/apps/web/pages/api/_moved/task-versions/[id].ts similarity index 100% rename from apps/web/pages/others/task-versions/[id].ts rename to apps/web/pages/api/_moved/task-versions/[id].ts diff --git a/apps/web/pages/others/task-versions/index.tsx b/apps/web/pages/api/_moved/task-versions/index.tsx similarity index 100% rename from apps/web/pages/others/task-versions/index.tsx rename to apps/web/pages/api/_moved/task-versions/index.tsx diff --git a/apps/web/pages/others/tasks/[id].ts b/apps/web/pages/api/_moved/tasks/[id].ts similarity index 100% rename from apps/web/pages/others/tasks/[id].ts rename to apps/web/pages/api/_moved/tasks/[id].ts diff --git a/apps/web/pages/others/tasks/employee/[employeeId].ts b/apps/web/pages/api/_moved/tasks/employee/[employeeId].ts similarity index 100% rename from apps/web/pages/others/tasks/employee/[employeeId].ts rename to apps/web/pages/api/_moved/tasks/employee/[employeeId].ts diff --git a/apps/web/pages/others/tasks/task-linked-issue.ts b/apps/web/pages/api/_moved/tasks/task-linked-issue.ts similarity index 100% rename from apps/web/pages/others/tasks/task-linked-issue.ts rename to apps/web/pages/api/_moved/tasks/task-linked-issue.ts diff --git a/apps/web/pages/others/tasks/team.ts b/apps/web/pages/api/_moved/tasks/team.ts similarity index 100% rename from apps/web/pages/others/tasks/team.ts rename to apps/web/pages/api/_moved/tasks/team.ts diff --git a/apps/web/pages/others/timer/start.ts b/apps/web/pages/api/_moved/timer/start.ts similarity index 100% rename from apps/web/pages/others/timer/start.ts rename to apps/web/pages/api/_moved/timer/start.ts diff --git a/apps/web/pages/others/timer/status.ts b/apps/web/pages/api/_moved/timer/status.ts similarity index 100% rename from apps/web/pages/others/timer/status.ts rename to apps/web/pages/api/_moved/timer/status.ts diff --git a/apps/web/pages/others/timer/stop.ts b/apps/web/pages/api/_moved/timer/stop.ts similarity index 100% rename from apps/web/pages/others/timer/stop.ts rename to apps/web/pages/api/_moved/timer/stop.ts diff --git a/apps/web/pages/others/timer/sync.ts b/apps/web/pages/api/_moved/timer/sync.ts similarity index 100% rename from apps/web/pages/others/timer/sync.ts rename to apps/web/pages/api/_moved/timer/sync.ts diff --git a/apps/web/pages/others/timer/timesheet/all-statistics-tasks.ts b/apps/web/pages/api/_moved/timer/timesheet/all-statistics-tasks.ts similarity index 100% rename from apps/web/pages/others/timer/timesheet/all-statistics-tasks.ts rename to apps/web/pages/api/_moved/timer/timesheet/all-statistics-tasks.ts diff --git a/apps/web/pages/others/timer/timesheet/index.ts b/apps/web/pages/api/_moved/timer/timesheet/index.ts similarity index 100% rename from apps/web/pages/others/timer/timesheet/index.ts rename to apps/web/pages/api/_moved/timer/timesheet/index.ts diff --git a/apps/web/pages/others/timer/timesheet/statistics-tasks.ts b/apps/web/pages/api/_moved/timer/timesheet/statistics-tasks.ts similarity index 100% rename from apps/web/pages/others/timer/timesheet/statistics-tasks.ts rename to apps/web/pages/api/_moved/timer/timesheet/statistics-tasks.ts diff --git a/apps/web/pages/others/timer/toggle.ts b/apps/web/pages/api/_moved/timer/toggle.ts similarity index 100% rename from apps/web/pages/others/timer/toggle.ts rename to apps/web/pages/api/_moved/timer/toggle.ts diff --git a/apps/web/pages/others/user/[id].ts b/apps/web/pages/api/_moved/user/[id].ts similarity index 100% rename from apps/web/pages/others/user/[id].ts rename to apps/web/pages/api/_moved/user/[id].ts diff --git a/apps/web/pages/others/user/me.ts b/apps/web/pages/api/_moved/user/me.ts similarity index 100% rename from apps/web/pages/others/user/me.ts rename to apps/web/pages/api/_moved/user/me.ts diff --git a/apps/web/pages/others/user/reset.ts b/apps/web/pages/api/_moved/user/reset.ts similarity index 100% rename from apps/web/pages/others/user/reset.ts rename to apps/web/pages/api/_moved/user/reset.ts diff --git a/apps/web/pages/others/auth/login.ts b/apps/web/pages/api/auth/login.ts similarity index 100% rename from apps/web/pages/others/auth/login.ts rename to apps/web/pages/api/auth/login.ts diff --git a/apps/web/pages/others/auth/meet/jwt.ts b/apps/web/pages/api/auth/meet/jwt.ts similarity index 100% rename from apps/web/pages/others/auth/meet/jwt.ts rename to apps/web/pages/api/auth/meet/jwt.ts diff --git a/apps/web/pages/others/auth/refresh.ts b/apps/web/pages/api/auth/refresh.ts similarity index 100% rename from apps/web/pages/others/auth/refresh.ts rename to apps/web/pages/api/auth/refresh.ts diff --git a/apps/web/pages/others/auth/register.ts b/apps/web/pages/api/auth/register.ts similarity index 100% rename from apps/web/pages/others/auth/register.ts rename to apps/web/pages/api/auth/register.ts diff --git a/apps/web/pages/others/auth/send-code.ts b/apps/web/pages/api/auth/send-code.ts similarity index 100% rename from apps/web/pages/others/auth/send-code.ts rename to apps/web/pages/api/auth/send-code.ts diff --git a/apps/web/pages/others/auth/signin-email-confirm.ts b/apps/web/pages/api/auth/signin-email-confirm.ts similarity index 100% rename from apps/web/pages/others/auth/signin-email-confirm.ts rename to apps/web/pages/api/auth/signin-email-confirm.ts diff --git a/apps/web/pages/others/auth/signin-email.ts b/apps/web/pages/api/auth/signin-email.ts similarity index 100% rename from apps/web/pages/others/auth/signin-email.ts rename to apps/web/pages/api/auth/signin-email.ts diff --git a/apps/web/pages/others/auth/signin-workspace.ts b/apps/web/pages/api/auth/signin-workspace.ts similarity index 100% rename from apps/web/pages/others/auth/signin-workspace.ts rename to apps/web/pages/api/auth/signin-workspace.ts diff --git a/apps/web/pages/others/auth/verify/code.ts b/apps/web/pages/api/auth/verify/code.ts similarity index 100% rename from apps/web/pages/others/auth/verify/code.ts rename to apps/web/pages/api/auth/verify/code.ts diff --git a/apps/web/pages/others/auth/verify/resend-link.ts b/apps/web/pages/api/auth/verify/resend-link.ts similarity index 100% rename from apps/web/pages/others/auth/verify/resend-link.ts rename to apps/web/pages/api/auth/verify/resend-link.ts diff --git a/apps/web/pages/others/auth/verify/token.ts b/apps/web/pages/api/auth/verify/token.ts similarity index 100% rename from apps/web/pages/others/auth/verify/token.ts rename to apps/web/pages/api/auth/verify/token.ts diff --git a/apps/web/pages/others/email-reset/request-change-email.ts b/apps/web/pages/api/email-reset/request-change-email.ts similarity index 100% rename from apps/web/pages/others/email-reset/request-change-email.ts rename to apps/web/pages/api/email-reset/request-change-email.ts diff --git a/apps/web/pages/others/email-reset/verify-change-email.ts b/apps/web/pages/api/email-reset/verify-change-email.ts similarity index 100% rename from apps/web/pages/others/email-reset/verify-change-email.ts rename to apps/web/pages/api/email-reset/verify-change-email.ts diff --git a/apps/web/pages/others/employee/working.ts b/apps/web/pages/api/employee/working.ts similarity index 100% rename from apps/web/pages/others/employee/working.ts rename to apps/web/pages/api/employee/working.ts diff --git a/apps/web/pages/others/integration-tenant/[id].ts b/apps/web/pages/api/integration-tenant/[id].ts similarity index 100% rename from apps/web/pages/others/integration-tenant/[id].ts rename to apps/web/pages/api/integration-tenant/[id].ts diff --git a/apps/web/pages/others/integration-tenant/remember/state/index.ts b/apps/web/pages/api/integration-tenant/remember/state/index.ts similarity index 100% rename from apps/web/pages/others/integration-tenant/remember/state/index.ts rename to apps/web/pages/api/integration-tenant/remember/state/index.ts diff --git a/apps/web/pages/others/integration/github/install.ts b/apps/web/pages/api/integration/github/install.ts similarity index 100% rename from apps/web/pages/others/integration/github/install.ts rename to apps/web/pages/api/integration/github/install.ts diff --git a/apps/web/pages/others/integration/github/metadata.ts b/apps/web/pages/api/integration/github/metadata.ts similarity index 100% rename from apps/web/pages/others/integration/github/metadata.ts rename to apps/web/pages/api/integration/github/metadata.ts diff --git a/apps/web/pages/others/integration/github/oauth.ts b/apps/web/pages/api/integration/github/oauth.ts similarity index 100% rename from apps/web/pages/others/integration/github/oauth.ts rename to apps/web/pages/api/integration/github/oauth.ts diff --git a/apps/web/pages/others/integration/github/repositories.ts b/apps/web/pages/api/integration/github/repositories.ts similarity index 100% rename from apps/web/pages/others/integration/github/repositories.ts rename to apps/web/pages/api/integration/github/repositories.ts diff --git a/apps/web/pages/others/integration/github/repository/sync.ts b/apps/web/pages/api/integration/github/repository/sync.ts similarity index 100% rename from apps/web/pages/others/integration/github/repository/sync.ts rename to apps/web/pages/api/integration/github/repository/sync.ts diff --git a/apps/web/pages/others/integration/types/index.ts b/apps/web/pages/api/integration/types/index.ts similarity index 100% rename from apps/web/pages/others/integration/types/index.ts rename to apps/web/pages/api/integration/types/index.ts diff --git a/apps/web/pages/others/invite/[id].ts b/apps/web/pages/api/invite/[id].ts similarity index 100% rename from apps/web/pages/others/invite/[id].ts rename to apps/web/pages/api/invite/[id].ts diff --git a/apps/web/pages/others/invite/emails.ts b/apps/web/pages/api/invite/emails.ts similarity index 100% rename from apps/web/pages/others/invite/emails.ts rename to apps/web/pages/api/invite/emails.ts diff --git a/apps/web/pages/others/invite/index.ts b/apps/web/pages/api/invite/index.ts similarity index 100% rename from apps/web/pages/others/invite/index.ts rename to apps/web/pages/api/invite/index.ts diff --git a/apps/web/pages/others/invite/resend.ts b/apps/web/pages/api/invite/resend.ts similarity index 100% rename from apps/web/pages/others/invite/resend.ts rename to apps/web/pages/api/invite/resend.ts diff --git a/apps/web/pages/others/invite/validate-by-code.ts b/apps/web/pages/api/invite/validate-by-code.ts similarity index 100% rename from apps/web/pages/others/invite/validate-by-code.ts rename to apps/web/pages/api/invite/validate-by-code.ts diff --git a/apps/web/pages/others/issue-types/[id].ts b/apps/web/pages/api/issue-types/[id].ts similarity index 100% rename from apps/web/pages/others/issue-types/[id].ts rename to apps/web/pages/api/issue-types/[id].ts diff --git a/apps/web/pages/others/issue-types/index.tsx b/apps/web/pages/api/issue-types/index.tsx similarity index 100% rename from apps/web/pages/others/issue-types/index.tsx rename to apps/web/pages/api/issue-types/index.tsx diff --git a/apps/web/pages/others/languages/index.ts b/apps/web/pages/api/languages/index.ts similarity index 100% rename from apps/web/pages/others/languages/index.ts rename to apps/web/pages/api/languages/index.ts diff --git a/apps/web/pages/others/organization-projects/[id].ts b/apps/web/pages/api/organization-projects/[id].ts similarity index 100% rename from apps/web/pages/others/organization-projects/[id].ts rename to apps/web/pages/api/organization-projects/[id].ts diff --git a/apps/web/pages/others/organization-projects/setting/[id].ts b/apps/web/pages/api/organization-projects/setting/[id].ts similarity index 100% rename from apps/web/pages/others/organization-projects/setting/[id].ts rename to apps/web/pages/api/organization-projects/setting/[id].ts diff --git a/apps/web/pages/others/organization-team-employee/[id]/active-task.ts b/apps/web/pages/api/organization-team-employee/[id]/active-task.ts similarity index 100% rename from apps/web/pages/others/organization-team-employee/[id]/active-task.ts rename to apps/web/pages/api/organization-team-employee/[id]/active-task.ts diff --git a/apps/web/pages/others/organization-team-employee/[id]/index.tsx b/apps/web/pages/api/organization-team-employee/[id]/index.tsx similarity index 100% rename from apps/web/pages/others/organization-team-employee/[id]/index.tsx rename to apps/web/pages/api/organization-team-employee/[id]/index.tsx diff --git a/apps/web/pages/others/organization-team-join/[id]/[action].ts b/apps/web/pages/api/organization-team-join/[id]/[action].ts similarity index 100% rename from apps/web/pages/others/organization-team-join/[id]/[action].ts rename to apps/web/pages/api/organization-team-join/[id]/[action].ts diff --git a/apps/web/pages/others/organization-team-join/index.ts b/apps/web/pages/api/organization-team-join/index.ts similarity index 100% rename from apps/web/pages/others/organization-team-join/index.ts rename to apps/web/pages/api/organization-team-join/index.ts diff --git a/apps/web/pages/others/organization-team-join/resend-code.ts b/apps/web/pages/api/organization-team-join/resend-code.ts similarity index 100% rename from apps/web/pages/others/organization-team-join/resend-code.ts rename to apps/web/pages/api/organization-team-join/resend-code.ts diff --git a/apps/web/pages/others/organization-team-join/validate.ts b/apps/web/pages/api/organization-team-join/validate.ts similarity index 100% rename from apps/web/pages/others/organization-team-join/validate.ts rename to apps/web/pages/api/organization-team-join/validate.ts diff --git a/apps/web/pages/others/organization-team/[id].ts b/apps/web/pages/api/organization-team/[id].ts similarity index 100% rename from apps/web/pages/others/organization-team/[id].ts rename to apps/web/pages/api/organization-team/[id].ts diff --git a/apps/web/pages/others/organization-team/employee/[id].ts b/apps/web/pages/api/organization-team/employee/[id].ts similarity index 100% rename from apps/web/pages/others/organization-team/employee/[id].ts rename to apps/web/pages/api/organization-team/employee/[id].ts diff --git a/apps/web/pages/others/organization-team/index.ts b/apps/web/pages/api/organization-team/index.ts similarity index 100% rename from apps/web/pages/others/organization-team/index.ts rename to apps/web/pages/api/organization-team/index.ts diff --git a/apps/web/pages/others/organization-team/teams/[id].ts b/apps/web/pages/api/organization-team/teams/[id].ts similarity index 100% rename from apps/web/pages/others/organization-team/teams/[id].ts rename to apps/web/pages/api/organization-team/teams/[id].ts diff --git a/apps/web/pages/others/role-permissions/[id].ts b/apps/web/pages/api/role-permissions/[id].ts similarity index 100% rename from apps/web/pages/others/role-permissions/[id].ts rename to apps/web/pages/api/role-permissions/[id].ts diff --git a/apps/web/pages/others/roles/[id].ts b/apps/web/pages/api/roles/[id].ts similarity index 100% rename from apps/web/pages/others/roles/[id].ts rename to apps/web/pages/api/roles/[id].ts diff --git a/apps/web/pages/others/roles/index.ts b/apps/web/pages/api/roles/index.ts similarity index 100% rename from apps/web/pages/others/roles/index.ts rename to apps/web/pages/api/roles/index.ts diff --git a/apps/web/pages/others/tags/[id].ts b/apps/web/pages/api/tags/[id].ts similarity index 100% rename from apps/web/pages/others/tags/[id].ts rename to apps/web/pages/api/tags/[id].ts diff --git a/apps/web/pages/others/tags/index.tsx b/apps/web/pages/api/tags/index.tsx similarity index 100% rename from apps/web/pages/others/tags/index.tsx rename to apps/web/pages/api/tags/index.tsx diff --git a/apps/web/pages/others/tags/level.ts b/apps/web/pages/api/tags/level.ts similarity index 100% rename from apps/web/pages/others/tags/level.ts rename to apps/web/pages/api/tags/level.ts From ccf17f0879c82f06102398960d7b8429687a1866 Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Fri, 5 Jan 2024 21:57:02 +0200 Subject: [PATCH 08/22] fix: remove unused vars --- apps/web/app/api/task-priorities/route.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/web/app/api/task-priorities/route.ts b/apps/web/app/api/task-priorities/route.ts index 9c4c9b277..21b69deb3 100644 --- a/apps/web/app/api/task-priorities/route.ts +++ b/apps/web/app/api/task-priorities/route.ts @@ -1,7 +1,6 @@ import { ITaskPrioritiesCreate } from '@app/interfaces'; import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { createPrioritiesRequest, getTaskPrioritiesListRequest } from '@app/services/server/requests/task-priorities'; -import { NextApiRequest, NextApiResponse } from 'next'; import { NextResponse } from 'next/server'; export async function GET(req: Request) { From 01fc89cb8bab8d3c5f0fe5a5a5f4fed936876500 Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Sat, 6 Jan 2024 15:06:01 +0200 Subject: [PATCH 09/22] feat: move /page/api/auth/* to /page/api --- apps/web/app/api/auth/login/login.ts | 154 ++++++++++++++++ apps/web/app/api/auth/meet/jwt/route.ts | 78 ++++++++ apps/web/app/api/auth/refresh/route.ts | 32 ++++ apps/web/app/api/auth/register/route.ts | 145 +++++++++++++++ apps/web/app/api/auth/send-code/route.ts | 29 +++ .../api/auth/signin-email-confirm/route.ts | 129 ++++++++++++++ apps/web/app/api/auth/signin-email/route.ts | 30 ++++ .../app/api/auth/signin-workspace/route.ts | 166 ++++++++++++++++++ apps/web/app/api/auth/verify/code/route.ts | 28 +++ .../app/api/auth/verify/resend-link/route.ts | 24 +++ apps/web/app/api/auth/verify/token/route.ts | 20 +++ .../team/[profileLink]/[teamId]/route.ts | 7 +- apps/web/app/api/timer/start/route.ts | 2 +- apps/web/app/api/timer/timesheet/route.ts | 2 +- apps/web/app/api/timer/toogle/route.ts | 2 +- apps/web/app/api/user/me/route.ts | 2 +- .../server/guards/authenticated-guard-app.ts | 4 +- apps/web/pages/api/{ => _moved}/auth/login.ts | 0 .../pages/api/{ => _moved}/auth/meet/jwt.ts | 0 .../pages/api/{ => _moved}/auth/refresh.ts | 0 .../pages/api/{ => _moved}/auth/register.ts | 0 .../pages/api/{ => _moved}/auth/send-code.ts | 0 .../{ => _moved}/auth/signin-email-confirm.ts | 0 .../api/{ => _moved}/auth/signin-email.ts | 0 .../api/{ => _moved}/auth/signin-workspace.ts | 0 .../api/{ => _moved}/auth/verify/code.ts | 0 .../{ => _moved}/auth/verify/resend-link.ts | 0 .../api/{ => _moved}/auth/verify/token.ts | 0 28 files changed, 845 insertions(+), 9 deletions(-) create mode 100644 apps/web/app/api/auth/login/login.ts create mode 100644 apps/web/app/api/auth/meet/jwt/route.ts create mode 100644 apps/web/app/api/auth/refresh/route.ts create mode 100644 apps/web/app/api/auth/register/route.ts create mode 100644 apps/web/app/api/auth/send-code/route.ts create mode 100644 apps/web/app/api/auth/signin-email-confirm/route.ts create mode 100644 apps/web/app/api/auth/signin-email/route.ts create mode 100644 apps/web/app/api/auth/signin-workspace/route.ts create mode 100644 apps/web/app/api/auth/verify/code/route.ts create mode 100644 apps/web/app/api/auth/verify/resend-link/route.ts create mode 100644 apps/web/app/api/auth/verify/token/route.ts rename apps/web/pages/api/{ => _moved}/auth/login.ts (100%) rename apps/web/pages/api/{ => _moved}/auth/meet/jwt.ts (100%) rename apps/web/pages/api/{ => _moved}/auth/refresh.ts (100%) rename apps/web/pages/api/{ => _moved}/auth/register.ts (100%) rename apps/web/pages/api/{ => _moved}/auth/send-code.ts (100%) rename apps/web/pages/api/{ => _moved}/auth/signin-email-confirm.ts (100%) rename apps/web/pages/api/{ => _moved}/auth/signin-email.ts (100%) rename apps/web/pages/api/{ => _moved}/auth/signin-workspace.ts (100%) rename apps/web/pages/api/{ => _moved}/auth/verify/code.ts (100%) rename apps/web/pages/api/{ => _moved}/auth/verify/resend-link.ts (100%) rename apps/web/pages/api/{ => _moved}/auth/verify/token.ts (100%) diff --git a/apps/web/app/api/auth/login/login.ts b/apps/web/app/api/auth/login/login.ts new file mode 100644 index 000000000..dc3d31233 --- /dev/null +++ b/apps/web/app/api/auth/login/login.ts @@ -0,0 +1,154 @@ +import { setAuthCookies, setNoTeamPopupShowCookie } from '@app/helpers/cookies'; +import { generateToken } from '@app/helpers/generate-token'; +import { authFormValidate } from '@app/helpers/validations'; +import { ILoginDataAPI, ILoginResponse as ILoginResponse } from '@app/interfaces/IAuthentication'; +import { + acceptInviteRequest, + getAllOrganizationTeamRequest, + getUserOrganizationsRequest, + verifyAuthCodeRequest, + verifyInviteCodeRequest +} from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const res = new NextResponse(); + const body = req.body as unknown as ILoginDataAPI; + console.log(body); + let loginResponse: ILoginResponse | null = null; + + const { errors, valid: formValid } = authFormValidate(['email', 'code'], body as any); + + if (!formValid) { + return NextResponse.json({ errors }); + } + + /** + * Verify first if matches with invite code + */ + const inviteReq = await verifyInviteCodeRequest({ + email: body.email, + code: body.code + }).catch(() => void 0); + /** + * If the invite code verification failed then try again with the Auth code + */ + if (!inviteReq || !inviteReq.response.ok || (inviteReq.data as any).response?.statusCode) { + try { + const authReq = await verifyAuthCodeRequest(body.email, body.code); + if ( + !authReq.response.ok || + (authReq.data as any).status === 404 || + (authReq.data as any).status === 400 || + (authReq.data as any).status === 401 + ) { + return NextResponse.json({ + errors: { + email: 'Authentication code or email address invalid' + } + }); + } + + loginResponse = authReq.data; + } catch (error) { + // return notFound(res); + return NextResponse.json({ + errors: { + email: 'Authentication code or email address invalid' + } + }); + } + + /** + * If the provided code is an invite code and + * verified then accept and register the related user + */ + } else { + // General a random password with 8 chars + const password = generateToken(8); + const names = inviteReq.data.fullName.split(' '); + const acceptInviteRes = await acceptInviteRequest({ + code: body.code, + email: inviteReq.data.email, + password: password, + user: { + firstName: names[0], + lastName: names[1] || '', + email: body.email + } + }).catch(() => void 0); + + if ( + !acceptInviteRes || + !acceptInviteRes.response.ok || + acceptInviteRes.response.status === 401 || + acceptInviteRes.response.status === 400 || + (acceptInviteRes.data as any).response?.statusCode + ) { + return NextResponse.json({ + errors: { + email: 'Authentication code or email address invalid' + } + }); + } + + loginResponse = acceptInviteRes.data; + } + + if (!loginResponse) { + return NextResponse.json({ + errors: { + email: 'Authentication code or email address invalid' + } + }); + } + + /** + * Get the first team from the first organization + */ + const tenantId = loginResponse.user?.tenantId || ''; + const access_token = loginResponse.token; + const userId = loginResponse.user?.id; + + const { data: organizations } = await getUserOrganizationsRequest({ tenantId, userId }, access_token); + + const organization = organizations?.items[0]; + + if (!organization) { + return NextResponse.json({ + errors: { + email: 'Your account is not yet ready to be used on the Ever Teams Platform' + } + }); + } + + const { data: teams } = await getAllOrganizationTeamRequest( + { tenantId, organizationId: organization.organizationId }, + access_token + ); + + const team = teams.items[0]; + + if (!team) { + setNoTeamPopupShowCookie(true); + } + + setAuthCookies( + { + access_token: loginResponse.token, + refresh_token: { + token: loginResponse.refresh_token + }, + teamId: team?.id, + tenantId, + organizationId: organization?.organizationId, + languageId: 'en', // TODO: not sure what should be here + noTeamPopup: true, + userId + }, + req, + res + ); + + NextResponse.json({ team, loginResponse }); +} diff --git a/apps/web/app/api/auth/meet/jwt/route.ts b/apps/web/app/api/auth/meet/jwt/route.ts new file mode 100644 index 000000000..93608591d --- /dev/null +++ b/apps/web/app/api/auth/meet/jwt/route.ts @@ -0,0 +1,78 @@ +import { MEET_DOMAIN, MEET_JWT_APP_ID, MEET_JWT_APP_SECRET } from '@app/constants'; +// import { +// // getMeetJwtSessionCookie, +// setMeetJwtSessionCookie, +// } from '@app/helpers'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import jwt from 'jsonwebtoken'; + +import { NextResponse } from 'next/server'; + +const algo: jwt.SignOptions = { algorithm: 'HS256' }; +type Params = { + name: string; + email: string; + room: string; + appid: string; + appkey: string; + domain: string; + audience: string; + avatar: string | null; + id: string; +}; + +function generateToken(params: Params): string { + const payload = { + context: { + user: { + id: params.id, + avatar: params.avatar, + name: params.name, + email: params.email + } + }, + aud: params.audience, + iss: params.appid, + sub: params.domain, + room: params.room + }; + + return jwt.sign(payload, params.appkey, algo); +} + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user } = await authenticatedGuard(req, res); + if (!user) return $res('Unauthorized'); + + if (!MEET_JWT_APP_SECRET || !MEET_JWT_APP_ID || !MEET_DOMAIN) { + return $res('Invalid configuration !'); + } + + // Check if existing token from cookie is valid + // const existing_token = getMeetJwtSessionCookie({ req, res }); + // if ( + // existing_token && + // jwt.verify(existing_token, MEET_JWT_APP_SECRET, algo) + // ) { + // return $res.json({ token: existing_token }); + // } + + // Generate new token + const new_token = generateToken({ + id: user.id, + name: user.name || user.email.split('@')[0], + email: user.email, + avatar: user.imageUrl, + audience: 'jitsi', + room: '*', + domain: MEET_DOMAIN.value, + appid: MEET_JWT_APP_ID, + appkey: MEET_JWT_APP_SECRET + }); + + // We don't use this cookie for now + // setMeetJwtSessionCookie(new_token, { req, res }); + + NextResponse.json({ token: new_token }); +} diff --git a/apps/web/app/api/auth/refresh/route.ts b/apps/web/app/api/auth/refresh/route.ts new file mode 100644 index 000000000..3e3e9ec1b --- /dev/null +++ b/apps/web/app/api/auth/refresh/route.ts @@ -0,0 +1,32 @@ +import { setAccessTokenCookie } from '@app/helpers/cookies'; +import { hasErrors } from '@app/helpers/validations'; +import { currentAuthenticatedUserRequest, refreshTokenRequest } from '@app/services/server/requests/auth'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const res = new NextResponse(); + + const body = req.body as { refresh_token: string } | null; + const refresh_token = body?.refresh_token; + + if (!refresh_token || refresh_token.trim().length < 2) { + return NextResponse.json( + hasErrors({ + refresh_token: 'The refresh token must be provided on the request body' + }) + ); + } + + const { data } = await refreshTokenRequest(refresh_token); + if (!data) { + return NextResponse.error(); + } + + const { data: user } = await currentAuthenticatedUserRequest({ + bearer_token: data.token + }); + + setAccessTokenCookie(data.token, { res, req }); + + return NextResponse.json({ user, token: data.token }); +} diff --git a/apps/web/app/api/auth/register/route.ts b/apps/web/app/api/auth/register/route.ts new file mode 100644 index 000000000..3642c4a6d --- /dev/null +++ b/apps/web/app/api/auth/register/route.ts @@ -0,0 +1,145 @@ +import { generateToken } from '@app/helpers/generate-token'; +import { authFormValidate } from '@app/helpers/validations'; +import { IRegisterDataAPI } from '@app/interfaces/IAuthentication'; +import { + createEmployeeFromUser, + createOrganizationRequest, + createOrganizationTeamRequest, + createTenantRequest, + createTenantSmtpRequest, + loginUserRequest, + registerUserRequest, + refreshTokenRequest +} from '@app/services/server/requests'; +import { setAuthCookies } from '@app/helpers/cookies'; +import { recaptchaVerification } from '@app/services/server/recaptcha'; +import { RECAPTCHA_SECRET_KEY, VERIFY_EMAIL_CALLBACK_PATH } from '@app/constants'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const url = new URL(req.url); + const res = new NextResponse(); + + const appEmailConfirmationUrl = `${url.origin}${VERIFY_EMAIL_CALLBACK_PATH}`; + + const body = req.body as unknown as IRegisterDataAPI; + + const noRecaptchaArray = ['email', 'name', 'team']; + + const withRecaptchaArray = [...noRecaptchaArray, 'recaptcha']; + + const validationFields = RECAPTCHA_SECRET_KEY ? withRecaptchaArray : noRecaptchaArray; + + const { errors, valid: formValid } = authFormValidate(validationFields, body); + + if (!formValid) { + return NextResponse.json({ errors }); + } + + if (RECAPTCHA_SECRET_KEY) { + const { success } = await recaptchaVerification({ + secret: RECAPTCHA_SECRET_KEY || '', + response: body.recaptcha ? body.recaptcha : '' + }); + + if (!success) { + return NextResponse.json({ errors: { recaptcha: 'Invalid reCAPTCHA. Please try again' } }); + } + } + /** + * Verify if the SMTP has been configured + */ + // const hasSMTPConfig = validSMTPConfig(); + + // if (0 && hasSMTPConfig) { + // return NextResponse.json({ + // status: 400, + // message: 'Unable to find SMTP configuration', + // }); + // } + + // General a random password with 8 chars + const password = generateToken(8); + const names = body.name.split(' '); + + // Register user + const { data: user } = await registerUserRequest({ + password: password, + confirmPassword: password, + user: { + firstName: names[0], + lastName: names[1] || '', + email: body.email, + timeZone: body.timezone as string + }, + appEmailConfirmationUrl + }); + // User Login, get the access token + const { data: loginRes } = await loginUserRequest(body.email, password); + let auth_token = loginRes.token; + + // Create user tenant + const { data: tenant } = await createTenantRequest(body.team, auth_token); + + // Create tenant SMTP + await createTenantSmtpRequest({ + access_token: auth_token, + tenantId: tenant.id + }); + + // Create user organization + const { data: organization } = await createOrganizationRequest( + { + currency: 'USD', + name: body.team, + tenantId: tenant.id, + invitesAllowed: true + }, + auth_token + ); + + // Create employee + const { data: employee } = await createEmployeeFromUser( + { + organizationId: organization.id, + startedWorkOn: new Date().toISOString(), + tenantId: tenant.id, + userId: user.id + }, + auth_token + ); + + // Create user organization team + const { data: team } = await createOrganizationTeamRequest( + { + name: body.team, + tenantId: tenant.id, + organizationId: organization.id, + managerIds: [employee.id], + public: true // By default team should be public, + }, + auth_token + ); + + const { data: refreshTokenRes } = await refreshTokenRequest(loginRes.refresh_token); + auth_token = refreshTokenRes.token; + + setAuthCookies( + { + access_token: auth_token, + refresh_token: { + token: loginRes.refresh_token + }, + timezone: body['timezone'], + teamId: team.id, + tenantId: tenant.id, + organizationId: organization.id, + languageId: 'en', // TODO: not sure what should be here + userId: user.id + }, + req, + res + ); + + NextResponse.json({ loginRes, team, employee }); +} diff --git a/apps/web/app/api/auth/send-code/route.ts b/apps/web/app/api/auth/send-code/route.ts new file mode 100644 index 000000000..219a32ad7 --- /dev/null +++ b/apps/web/app/api/auth/send-code/route.ts @@ -0,0 +1,29 @@ +import { INVITE_CALLBACK_PATH } from '@app/constants'; +import { authFormValidate } from '@app/helpers/validations'; +import { sendAuthCodeRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const url = new URL(req.url); + const callbackUrl = `${url.origin}${INVITE_CALLBACK_PATH}`; + + const body = req.body as unknown as { email: string }; + + const { errors, valid: formValid } = authFormValidate(['email'], body as any); + + if (!formValid) { + return NextResponse.json({ errors }); + } + + const codeSendRes = await sendAuthCodeRequest(body.email, callbackUrl).catch(() => void 0); + + if (!codeSendRes) { + return NextResponse.json({ + errors: { + email: "We couldn't find any account associated to this email" + } + }); + } + + return NextResponse.json(codeSendRes.data); +} diff --git a/apps/web/app/api/auth/signin-email-confirm/route.ts b/apps/web/app/api/auth/signin-email-confirm/route.ts new file mode 100644 index 000000000..731ee07a7 --- /dev/null +++ b/apps/web/app/api/auth/signin-email-confirm/route.ts @@ -0,0 +1,129 @@ +import { generateToken, setAuthCookies, setNoTeamPopupShowCookie } from '@app/helpers'; +import { authFormValidate } from '@app/helpers/validations'; +import { ILoginResponse } from '@app/interfaces'; +import { + acceptInviteRequest, + getAllOrganizationTeamRequest, + getUserOrganizationsRequest, + signInEmailConfirmRequest, + verifyInviteCodeRequest +} from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const res = new NextResponse(); + + const body = req.body as unknown as { email: string; code: string }; + let loginResponse: ILoginResponse | null = null; + + const { errors, valid: formValid } = authFormValidate(['email', 'code'], body as any); + + if (!formValid) { + return NextResponse.json({ errors }); + } + + // Accept Invite Flow Start + /** + * Verify first if match with invite code + */ + const inviteReq = await verifyInviteCodeRequest({ + email: body.email, + code: body.code + }).catch(() => void 0); + + // General a random password with 8 chars + if (inviteReq && inviteReq.data.fullName) { + const password = generateToken(8); + console.log('inviteReq', inviteReq.data); + + const names = inviteReq.data.fullName.split(' '); + const acceptInviteRes = await acceptInviteRequest({ + code: body.code, + email: body.email, + password: password, + user: { + firstName: names[0], + lastName: names[1] || '', + email: body.email + } + }).catch(() => void 0); + + if ( + !acceptInviteRes || + !acceptInviteRes.response.ok || + acceptInviteRes.response.status === 401 || + acceptInviteRes.response.status === 400 || + (acceptInviteRes.data as any).response?.statusCode + ) { + return NextResponse.json({ + errors: { + email: 'Authentication code or email address invalid' + } + }); + } + loginResponse = acceptInviteRes.data; + + if (!loginResponse) { + return NextResponse.json({ + errors: { + email: 'Authentication code or email address invalid' + } + }); + } + } + if (loginResponse) { + console.log('loginResponse>>>', loginResponse); + + /** + * Get the first team from first organization + */ + const tenantId = loginResponse.user?.tenantId || ''; + const access_token = loginResponse.token; + const userId = loginResponse.user?.id; + + const { data: organizations } = await getUserOrganizationsRequest({ tenantId, userId }, access_token); + const organization = organizations?.items[0]; + + if (!organization) { + return NextResponse.json({ + errors: { + email: 'Your account is not yet ready to be used on the Ever Teams Platform' + } + }); + } + const { data: teams } = await getAllOrganizationTeamRequest( + { tenantId, organizationId: organization.organizationId }, + access_token + ); + + const team = teams.items[0]; + if (!team) { + setNoTeamPopupShowCookie(true); + } + setAuthCookies( + { + access_token: loginResponse.token, + refresh_token: { + token: loginResponse.refresh_token + }, + teamId: team?.id, + tenantId, + organizationId: organization?.organizationId, + languageId: 'en', // TODO: not sure what should be here + noTeamPopup: true, + userId + }, + req, + res + ); + return NextResponse.json({ team, loginResponse }); + } + // Accept Invite Flow End + + const { data } = await signInEmailConfirmRequest({ + code: body.code, + email: body.email + }); + + return NextResponse.json(data); +} diff --git a/apps/web/app/api/auth/signin-email/route.ts b/apps/web/app/api/auth/signin-email/route.ts new file mode 100644 index 000000000..3591d5c5b --- /dev/null +++ b/apps/web/app/api/auth/signin-email/route.ts @@ -0,0 +1,30 @@ +import { INVITE_CALLBACK_PATH } from '@app/constants'; +import { authFormValidate } from '@app/helpers/validations'; +import { signInEmailRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const url = new URL(req.url); + + const callbackUrl = `${url}${INVITE_CALLBACK_PATH}`; + + const body = req.body as unknown as { email: string }; + + const { errors, valid: formValid } = authFormValidate(['email'], body as any); + + if (!formValid) { + return NextResponse.json({ errors }); + } + + const codeSendRes = await signInEmailRequest(body.email, callbackUrl).catch(() => void 0); + + if (!codeSendRes) { + return NextResponse.json({ + errors: { + email: "We couldn't find any account associated to this email" + } + }); + } + + NextResponse.json(codeSendRes.data); +} diff --git a/apps/web/app/api/auth/signin-workspace/route.ts b/apps/web/app/api/auth/signin-workspace/route.ts new file mode 100644 index 000000000..7aaf890ef --- /dev/null +++ b/apps/web/app/api/auth/signin-workspace/route.ts @@ -0,0 +1,166 @@ +import { authFormValidate } from '@app/helpers/validations'; +import { + acceptInviteRequest, + getAllOrganizationTeamRequest, + getUserOrganizationsRequest, + signInWorkspaceRequest, + verifyInviteCodeRequest +} from '@app/services/server/requests'; +import { generateToken, setAuthCookies, setNoTeamPopupShowCookie } from '@app/helpers'; +import { ILoginResponse } from '@app/interfaces'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const res = new NextResponse(); + + const body = req.body as unknown as { + email: string; + token: string; + teamId: string; + code: string; + }; + let loginResponse: ILoginResponse | null = null; + + const { errors, valid: formValid } = authFormValidate(['email'], body as any); + + if (!formValid) { + return NextResponse.json({ errors }); + } + + // Accept Invite Flow Start + /** + * Verify first if match with invite code + */ + const inviteReq = await verifyInviteCodeRequest({ + email: body.email, + code: body.code + }).catch(() => void 0); + + // General a random password with 8 chars + if (inviteReq && inviteReq.data.fullName) { + const password = generateToken(8); + + const names = inviteReq.data.fullName.split(' '); + const acceptInviteRes = await acceptInviteRequest({ + code: body.code, + email: body.email, + password: password, + user: { + firstName: names[0], + lastName: names[1] || '', + email: body.email + } + }).catch(() => void 0); + + if ( + !acceptInviteRes || + !acceptInviteRes.response.ok || + acceptInviteRes.response.status === 401 || + acceptInviteRes.response.status === 400 || + (acceptInviteRes.data as any).response?.statusCode + ) { + return NextResponse.json({ + errors: { + email: 'Authentication code or email address invalid' + } + }); + } + loginResponse = acceptInviteRes.data; + + if (!loginResponse) { + return NextResponse.json({ + errors: { + email: 'Authentication code or email address invalid' + } + }); + } + } + if (loginResponse) { + console.log('loginResponse>>>', loginResponse); + + /** + * Get the first team from first organization + */ + const tenantId = loginResponse.user?.tenantId || ''; + const access_token = loginResponse.token; + const userId = loginResponse.user?.id; + + const { data: organizations } = await getUserOrganizationsRequest({ tenantId, userId }, access_token); + const organization = organizations?.items[0]; + + if (!organization) { + return NextResponse.json({ + errors: { + email: 'Your account is not yet ready to be used on the Ever Teams Platform' + } + }); + } + const { data: teams } = await getAllOrganizationTeamRequest( + { tenantId, organizationId: organization.organizationId }, + access_token + ); + + const team = teams.items[0]; + if (!team) { + setNoTeamPopupShowCookie(true); + } + setAuthCookies( + { + access_token: loginResponse.token, + refresh_token: { + token: loginResponse.refresh_token + }, + teamId: team?.id, + tenantId, + organizationId: organization?.organizationId, + languageId: 'en', // TODO: not sure what should be here + noTeamPopup: true, + userId + }, + req, + res + ); + return NextResponse.json({ team, loginResponse }); + } + // Accept Invite Flow End + + const { data } = await signInWorkspaceRequest(body.email, body.token); + + /** + * Get the first team from first organization + */ + const tenantId = data.user?.tenantId || ''; + const access_token = data.token; + const userId = data.user?.id; + + const { data: organizations } = await getUserOrganizationsRequest({ tenantId, userId }, access_token); + + const organization = organizations?.items[0]; + + if (!organization) { + return NextResponse.json({ + errors: { + email: 'Your account is not yet ready to be used on the Ever Teams Platform' + } + }); + } + + setAuthCookies( + { + access_token: data.token, + refresh_token: { + token: data.refresh_token + }, + teamId: body.teamId, + tenantId, + organizationId: organization?.organizationId, + languageId: 'en', // TODO: not sure what should be here + noTeamPopup: true, + userId + }, + req, + res + ); + + NextResponse.json({ loginResponse: data }); +} diff --git a/apps/web/app/api/auth/verify/code/route.ts b/apps/web/app/api/auth/verify/code/route.ts new file mode 100644 index 000000000..736add27d --- /dev/null +++ b/apps/web/app/api/auth/verify/code/route.ts @@ -0,0 +1,28 @@ +import { authFormValidate } from '@app/helpers/validations'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { verifyUserEmailByCodeRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('unauthorized'); + + const body = req.body as unknown as { code: string }; + + const { errors, valid: formValid } = authFormValidate(['code'], body as any); + + if (!formValid) { + return NextResponse.json({ errors }); + } + + const { data } = await verifyUserEmailByCodeRequest({ + bearer_token: access_token, + tenantId, + code: body.code, + email: user.email + }); + + $res(data); +} diff --git a/apps/web/app/api/auth/verify/resend-link/route.ts b/apps/web/app/api/auth/verify/resend-link/route.ts new file mode 100644 index 000000000..3b7bd6524 --- /dev/null +++ b/apps/web/app/api/auth/verify/resend-link/route.ts @@ -0,0 +1,24 @@ +import { VERIFY_EMAIL_CALLBACK_PATH } from '@app/constants'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { resentVerifyUserLinkRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const res = new NextResponse(); + const url = new URL(req.url); + + const appEmailConfirmationUrl = `${url.origin}${VERIFY_EMAIL_CALLBACK_PATH}`; + + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { data } = await resentVerifyUserLinkRequest({ + bearer_token: access_token, + tenantId, + email: user.email, + appEmailConfirmationUrl + }); + + $res(data); +} diff --git a/apps/web/app/api/auth/verify/token/route.ts b/apps/web/app/api/auth/verify/token/route.ts new file mode 100644 index 000000000..f0c880ebc --- /dev/null +++ b/apps/web/app/api/auth/verify/token/route.ts @@ -0,0 +1,20 @@ +import { authFormValidate } from '@app/helpers/validations'; +import { verifyUserEmailByTokenRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const body = req.body as unknown as { email: string; token: string }; + + const { errors, valid: formValid } = authFormValidate(['email', 'token'], body as any); + + if (!formValid) { + return NextResponse.json({ errors }); + } + + const { data } = await verifyUserEmailByTokenRequest({ + token: body.token, + email: body.email + }); + + NextResponse.json(data); +} 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 0075e9d5b..4cb5d488a 100644 --- a/apps/web/app/api/public/team/[profileLink]/[teamId]/route.ts +++ b/apps/web/app/api/public/team/[profileLink]/[teamId]/route.ts @@ -2,8 +2,9 @@ import { getPublicOrganizationTeamMiscDataRequest, getPublicOrganizationTeamRequest } from '@app/services/server/requests/public-organization-team'; +import { NextResponse } from 'next/server'; -export default async function GET(req: Request) { +export async function GET(req: Request) { const { searchParams } = new URL(req.url); const { profileLink, teamId, type }: { profileLink: string; teamId: string; type: string } = searchParams as unknown as { @@ -13,14 +14,14 @@ export default async function GET(req: Request) { }; if (type === 'misc') { - return Response.json( + return NextResponse.json( await getPublicOrganizationTeamMiscDataRequest({ profileLink: profileLink, teamId }) ); } - return Response.json( + return NextResponse.json( await getPublicOrganizationTeamRequest({ profileLink: profileLink, teamId diff --git a/apps/web/app/api/timer/start/route.ts b/apps/web/app/api/timer/start/route.ts index f782a7d2b..bb5fa6595 100644 --- a/apps/web/app/api/timer/start/route.ts +++ b/apps/web/app/api/timer/start/route.ts @@ -3,7 +3,7 @@ import { authenticatedGuard } from '@app/services/server/guards/authenticated-gu import { getTimerStatusRequest, startTimerRequest } from '@app/services/server/requests'; import { NextResponse } from 'next/server'; -export default async function POST(req: Request) { +export async function POST(req: Request) { const res = new NextResponse(); const { $res, diff --git a/apps/web/app/api/timer/timesheet/route.ts b/apps/web/app/api/timer/timesheet/route.ts index b3eb30d0d..4ab1a8c61 100644 --- a/apps/web/app/api/timer/timesheet/route.ts +++ b/apps/web/app/api/timer/timesheet/route.ts @@ -1,7 +1,7 @@ import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { NextResponse } from 'next/server'; -export default async function GET(req: Request) { +export async function GET(req: Request) { const res = new NextResponse(); const { $res, user } = await authenticatedGuard(req, res); if (!user) return $res('unauthorized'); diff --git a/apps/web/app/api/timer/toogle/route.ts b/apps/web/app/api/timer/toogle/route.ts index 62c80b565..e8b2d3b72 100644 --- a/apps/web/app/api/timer/toogle/route.ts +++ b/apps/web/app/api/timer/toogle/route.ts @@ -2,7 +2,7 @@ import { authenticatedGuard } from '@app/services/server/guards/authenticated-gu import { getTimerStatusRequest, stopTimerRequest, toggleTimerRequest } from '@app/services/server/requests'; import { NextResponse } from 'next/server'; -export default async function POST(req: Request) { +export async function POST(req: Request) { const res = new NextResponse(); const { $res, user, tenantId, access_token, organizationId, taskId } = await authenticatedGuard(req, res); if (!user) return $res(''); diff --git a/apps/web/app/api/user/me/route.ts b/apps/web/app/api/user/me/route.ts index e76e83312..484ec1bba 100644 --- a/apps/web/app/api/user/me/route.ts +++ b/apps/web/app/api/user/me/route.ts @@ -1,7 +1,7 @@ import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { NextResponse } from 'next/server'; -export default async function GET(req: Request) { +export async function GET(req: Request) { const res = new NextResponse(); const { $res, user } = await authenticatedGuard(req, res); if (!user) return $res('Unauthorized'); diff --git a/apps/web/app/services/server/guards/authenticated-guard-app.ts b/apps/web/app/services/server/guards/authenticated-guard-app.ts index ba8702923..cbd88cb28 100644 --- a/apps/web/app/services/server/guards/authenticated-guard-app.ts +++ b/apps/web/app/services/server/guards/authenticated-guard-app.ts @@ -24,13 +24,13 @@ export async function authenticatedGuard(req: Request, res: NextResponse Response.json({ statusCode: 401, message: data }), + $res: (data: any) => NextResponse.json({ statusCode: 401, message: data }), user: null }; } return { - $res: (data: any) => Response.json(data), + $res: (data: any) => NextResponse.json(data), user: r_res.data, access_token: access_token as string, tenantId, diff --git a/apps/web/pages/api/auth/login.ts b/apps/web/pages/api/_moved/auth/login.ts similarity index 100% rename from apps/web/pages/api/auth/login.ts rename to apps/web/pages/api/_moved/auth/login.ts diff --git a/apps/web/pages/api/auth/meet/jwt.ts b/apps/web/pages/api/_moved/auth/meet/jwt.ts similarity index 100% rename from apps/web/pages/api/auth/meet/jwt.ts rename to apps/web/pages/api/_moved/auth/meet/jwt.ts diff --git a/apps/web/pages/api/auth/refresh.ts b/apps/web/pages/api/_moved/auth/refresh.ts similarity index 100% rename from apps/web/pages/api/auth/refresh.ts rename to apps/web/pages/api/_moved/auth/refresh.ts diff --git a/apps/web/pages/api/auth/register.ts b/apps/web/pages/api/_moved/auth/register.ts similarity index 100% rename from apps/web/pages/api/auth/register.ts rename to apps/web/pages/api/_moved/auth/register.ts diff --git a/apps/web/pages/api/auth/send-code.ts b/apps/web/pages/api/_moved/auth/send-code.ts similarity index 100% rename from apps/web/pages/api/auth/send-code.ts rename to apps/web/pages/api/_moved/auth/send-code.ts diff --git a/apps/web/pages/api/auth/signin-email-confirm.ts b/apps/web/pages/api/_moved/auth/signin-email-confirm.ts similarity index 100% rename from apps/web/pages/api/auth/signin-email-confirm.ts rename to apps/web/pages/api/_moved/auth/signin-email-confirm.ts diff --git a/apps/web/pages/api/auth/signin-email.ts b/apps/web/pages/api/_moved/auth/signin-email.ts similarity index 100% rename from apps/web/pages/api/auth/signin-email.ts rename to apps/web/pages/api/_moved/auth/signin-email.ts diff --git a/apps/web/pages/api/auth/signin-workspace.ts b/apps/web/pages/api/_moved/auth/signin-workspace.ts similarity index 100% rename from apps/web/pages/api/auth/signin-workspace.ts rename to apps/web/pages/api/_moved/auth/signin-workspace.ts diff --git a/apps/web/pages/api/auth/verify/code.ts b/apps/web/pages/api/_moved/auth/verify/code.ts similarity index 100% rename from apps/web/pages/api/auth/verify/code.ts rename to apps/web/pages/api/_moved/auth/verify/code.ts diff --git a/apps/web/pages/api/auth/verify/resend-link.ts b/apps/web/pages/api/_moved/auth/verify/resend-link.ts similarity index 100% rename from apps/web/pages/api/auth/verify/resend-link.ts rename to apps/web/pages/api/_moved/auth/verify/resend-link.ts diff --git a/apps/web/pages/api/auth/verify/token.ts b/apps/web/pages/api/_moved/auth/verify/token.ts similarity index 100% rename from apps/web/pages/api/auth/verify/token.ts rename to apps/web/pages/api/_moved/auth/verify/token.ts From 8541f008b3c5b2bb0115757b0b53728fb07d5ee1 Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Sat, 6 Jan 2024 19:09:39 +0200 Subject: [PATCH 10/22] fix:parser req body --- .../app/api/auth/_signin-workspace/route.ts | 192 ++++++++++++++++++ apps/web/app/api/auth/login/login.ts | 5 +- apps/web/app/api/auth/meet/jwt/route.ts | 2 +- apps/web/app/api/auth/refresh/route.ts | 2 +- apps/web/app/api/auth/register/route.ts | 4 +- apps/web/app/api/auth/send-code/route.ts | 2 +- .../api/auth/signin-email-confirm/route.ts | 2 +- apps/web/app/api/auth/signin-email/route.ts | 17 +- apps/web/app/api/auth/verify/code/route.ts | 4 +- .../app/api/auth/verify/resend-link/route.ts | 2 +- apps/web/app/api/auth/verify/token/route.ts | 4 +- .../web/app/api/task-priorities/[id]/route.ts | 2 +- apps/web/app/api/task-priorities/route.ts | 2 +- .../task-related-issue-types/[id]/route.ts | 2 +- .../app/api/task-related-issue-types/route.ts | 2 +- apps/web/app/api/task-sizes/[id]/route.ts | 2 +- apps/web/app/api/task-sizes/route.ts | 2 +- apps/web/app/api/task-statuses/[id]/route.ts | 2 +- apps/web/app/api/task-statuses/route.ts | 2 +- apps/web/app/api/task-versions/[id]/route.ts | 2 +- apps/web/app/api/task-versions/route.ts | 2 +- apps/web/app/api/tasks/[id]/route.ts | 4 +- .../api/tasks/employee/[employeeId]/route.ts | 2 +- .../app/api/tasks/task-linked-issue/route.ts | 9 +- apps/web/app/api/tasks/team/route.ts | 4 +- apps/web/app/api/timer/status/route.ts | 2 +- apps/web/app/api/timer/stop/route.ts | 2 +- apps/web/app/api/timer/sync/route.ts | 2 +- apps/web/app/api/timer/toogle/route.ts | 2 +- apps/web/app/api/user/[id]/route.ts | 2 +- apps/web/app/api/user/me/route.ts | 2 +- apps/web/app/services/server/requests/auth.ts | 3 +- .../api/auth/signin-workspace.ts} | 24 ++- 33 files changed, 255 insertions(+), 59 deletions(-) create mode 100644 apps/web/app/api/auth/_signin-workspace/route.ts rename apps/web/{app/api/auth/signin-workspace/route.ts => pages/api/auth/signin-workspace.ts} (87%) diff --git a/apps/web/app/api/auth/_signin-workspace/route.ts b/apps/web/app/api/auth/_signin-workspace/route.ts new file mode 100644 index 000000000..69a7f7954 --- /dev/null +++ b/apps/web/app/api/auth/_signin-workspace/route.ts @@ -0,0 +1,192 @@ +import { authFormValidate } from '@app/helpers/validations'; +import { + acceptInviteRequest, + getAllOrganizationTeamRequest, + getUserOrganizationsRequest, + signInWorkspaceRequest, + verifyInviteCodeRequest +} from '@app/services/server/requests'; +import { generateToken, setAuthCookies, setNoTeamPopupShowCookie } from '@app/helpers'; +import { ILoginResponse } from '@app/interfaces'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + try { + const res = new NextResponse(); + + const body = (await req.json()) as unknown as { + email: string; + token: string; + teamId: string; + code: string; + }; + let loginResponse: ILoginResponse | null = null; + + const { errors, valid: formValid } = authFormValidate(['email'], body as any); + + if (!formValid) { + return NextResponse.json({ errors }, { status: 400 }); + } + + // Accept Invite Flow Start + /** + * Verify first if match with invite code + */ + const inviteReq = await verifyInviteCodeRequest({ + email: body.email, + code: body.code + }).catch((err) => console.log(err)); + + // General a random password with 8 chars + if (inviteReq && inviteReq.data.fullName) { + const password = generateToken(8); + + const names = inviteReq.data.fullName.split(' '); + const acceptInviteRes = await acceptInviteRequest({ + code: body.code, + email: body.email, + password: password, + user: { + firstName: names[0], + lastName: names[1] || '', + email: body.email + } + }).catch(() => void 0); + + if ( + !acceptInviteRes || + !acceptInviteRes.response.ok || + acceptInviteRes.response.status === 401 || + acceptInviteRes.response.status === 400 || + (acceptInviteRes.data as any).response?.statusCode + ) { + return NextResponse.json( + { + errors: { + email: 'Authentication code or email address invalid' + } + }, + { status: 401 } + ); + } + loginResponse = acceptInviteRes.data; + + if (!loginResponse) { + return NextResponse.json( + { + errors: { + email: 'Authentication code or email address invalid' + } + }, + { status: 401 } + ); + } + } + if (loginResponse) { + console.log('loginResponse>>>', loginResponse); + + /** + * Get the first team from first organization + */ + const tenantId = loginResponse.user?.tenantId || ''; + const access_token = loginResponse.token; + const userId = loginResponse.user?.id; + + const { data: organizations } = await getUserOrganizationsRequest({ tenantId, userId }, access_token); + const organization = organizations?.items[0]; + + console.log({ t: 5, organization }); + + if (!organization) { + return NextResponse.json( + { + errors: { + email: 'Your account is not yet ready to be used on the Ever Teams Platform' + } + }, + { status: 401 } + ); + } + const { data: teams } = await getAllOrganizationTeamRequest( + { tenantId, organizationId: organization.organizationId }, + access_token + ); + + const team = teams.items[0]; + if (!team) { + setNoTeamPopupShowCookie(true); + } + setAuthCookies( + { + access_token: loginResponse.token, + refresh_token: { + token: loginResponse.refresh_token + }, + teamId: team?.id, + tenantId, + organizationId: organization?.organizationId, + languageId: 'en', // TODO: not sure what should be here + noTeamPopup: true, + userId + }, + req, + res + ); + return NextResponse.json({ team, loginResponse }); + } + // Accept Invite Flow End + + const { data } = await signInWorkspaceRequest(body.email, body.token); + + /** + * Get the first team from first organization + */ + const tenantId = data.user?.tenantId || ''; + const access_token = data.token; + const userId = data.user?.id; + + const { data: organizations } = await getUserOrganizationsRequest({ tenantId, userId }, access_token); + + const organization = organizations?.items[0]; + + if (!organization) { + return NextResponse.json( + { + errors: { + email: 'Your account is not yet ready to be used on the Ever Teams Platform' + } + }, + { status: 400 } + ); + } + + setAuthCookies( + { + access_token: data.token, + refresh_token: { + token: data.refresh_token + }, + teamId: body.teamId, + tenantId, + organizationId: organization?.organizationId, + languageId: 'en', // TODO: not sure what should be here + noTeamPopup: true, + userId + }, + req, + res + ); + + return NextResponse.json({ loginResponse: data }); + } catch (err) { + console.log({ err }); + return NextResponse.json( + { + errors: { + err + } + }, + { status: 400 } + ); + } +} diff --git a/apps/web/app/api/auth/login/login.ts b/apps/web/app/api/auth/login/login.ts index dc3d31233..79e954e79 100644 --- a/apps/web/app/api/auth/login/login.ts +++ b/apps/web/app/api/auth/login/login.ts @@ -13,8 +13,7 @@ import { NextResponse } from 'next/server'; export async function POST(req: Request) { const res = new NextResponse(); - const body = req.body as unknown as ILoginDataAPI; - console.log(body); + const body = (await req.json()) as unknown as ILoginDataAPI; let loginResponse: ILoginResponse | null = null; const { errors, valid: formValid } = authFormValidate(['email', 'code'], body as any); @@ -150,5 +149,5 @@ export async function POST(req: Request) { res ); - NextResponse.json({ team, loginResponse }); + return NextResponse.json({ team, loginResponse }); } diff --git a/apps/web/app/api/auth/meet/jwt/route.ts b/apps/web/app/api/auth/meet/jwt/route.ts index 93608591d..40e5c6473 100644 --- a/apps/web/app/api/auth/meet/jwt/route.ts +++ b/apps/web/app/api/auth/meet/jwt/route.ts @@ -74,5 +74,5 @@ export async function GET(req: Request) { // We don't use this cookie for now // setMeetJwtSessionCookie(new_token, { req, res }); - NextResponse.json({ token: new_token }); + return NextResponse.json({ token: new_token }); } diff --git a/apps/web/app/api/auth/refresh/route.ts b/apps/web/app/api/auth/refresh/route.ts index 3e3e9ec1b..13c4b1a81 100644 --- a/apps/web/app/api/auth/refresh/route.ts +++ b/apps/web/app/api/auth/refresh/route.ts @@ -6,7 +6,7 @@ import { NextResponse } from 'next/server'; export async function POST(req: Request) { const res = new NextResponse(); - const body = req.body as { refresh_token: string } | null; + const body = (await req.json()) as { refresh_token: string } | null; const refresh_token = body?.refresh_token; if (!refresh_token || refresh_token.trim().length < 2) { diff --git a/apps/web/app/api/auth/register/route.ts b/apps/web/app/api/auth/register/route.ts index 3642c4a6d..e8de8e086 100644 --- a/apps/web/app/api/auth/register/route.ts +++ b/apps/web/app/api/auth/register/route.ts @@ -22,7 +22,7 @@ export async function POST(req: Request) { const appEmailConfirmationUrl = `${url.origin}${VERIFY_EMAIL_CALLBACK_PATH}`; - const body = req.body as unknown as IRegisterDataAPI; + const body = (await req.json()) as unknown as IRegisterDataAPI; const noRecaptchaArray = ['email', 'name', 'team']; @@ -141,5 +141,5 @@ export async function POST(req: Request) { res ); - NextResponse.json({ loginRes, team, employee }); + return NextResponse.json({ loginRes, team, employee }); } diff --git a/apps/web/app/api/auth/send-code/route.ts b/apps/web/app/api/auth/send-code/route.ts index 219a32ad7..861608981 100644 --- a/apps/web/app/api/auth/send-code/route.ts +++ b/apps/web/app/api/auth/send-code/route.ts @@ -7,7 +7,7 @@ export async function POST(req: Request) { const url = new URL(req.url); const callbackUrl = `${url.origin}${INVITE_CALLBACK_PATH}`; - const body = req.body as unknown as { email: string }; + const body = (await req.json()) as unknown as { email: string }; const { errors, valid: formValid } = authFormValidate(['email'], body as any); diff --git a/apps/web/app/api/auth/signin-email-confirm/route.ts b/apps/web/app/api/auth/signin-email-confirm/route.ts index 731ee07a7..579d701d4 100644 --- a/apps/web/app/api/auth/signin-email-confirm/route.ts +++ b/apps/web/app/api/auth/signin-email-confirm/route.ts @@ -13,7 +13,7 @@ import { NextResponse } from 'next/server'; export async function POST(req: Request) { const res = new NextResponse(); - const body = req.body as unknown as { email: string; code: string }; + const body = (await req.json()) as unknown as { email: string; code: string }; let loginResponse: ILoginResponse | null = null; const { errors, valid: formValid } = authFormValidate(['email', 'code'], body as any); diff --git a/apps/web/app/api/auth/signin-email/route.ts b/apps/web/app/api/auth/signin-email/route.ts index 3591d5c5b..b13a9fa44 100644 --- a/apps/web/app/api/auth/signin-email/route.ts +++ b/apps/web/app/api/auth/signin-email/route.ts @@ -8,7 +8,7 @@ export async function POST(req: Request) { const callbackUrl = `${url}${INVITE_CALLBACK_PATH}`; - const body = req.body as unknown as { email: string }; + const body = (await req.json()) as unknown as { email: string }; const { errors, valid: formValid } = authFormValidate(['email'], body as any); @@ -19,12 +19,15 @@ export async function POST(req: Request) { const codeSendRes = await signInEmailRequest(body.email, callbackUrl).catch(() => void 0); if (!codeSendRes) { - return NextResponse.json({ - errors: { - email: "We couldn't find any account associated to this email" - } - }); + return NextResponse.json( + { + errors: { + email: "We couldn't find any account associated to this email" + } + }, + { status: 400 } + ); } - NextResponse.json(codeSendRes.data); + return NextResponse.json(codeSendRes.data); } diff --git a/apps/web/app/api/auth/verify/code/route.ts b/apps/web/app/api/auth/verify/code/route.ts index 736add27d..ffbecc257 100644 --- a/apps/web/app/api/auth/verify/code/route.ts +++ b/apps/web/app/api/auth/verify/code/route.ts @@ -9,7 +9,7 @@ export async function POST(req: Request) { if (!user) return $res('unauthorized'); - const body = req.body as unknown as { code: string }; + const body = (await req.json()) as unknown as { code: string }; const { errors, valid: formValid } = authFormValidate(['code'], body as any); @@ -24,5 +24,5 @@ export async function POST(req: Request) { email: user.email }); - $res(data); + return $res(data); } diff --git a/apps/web/app/api/auth/verify/resend-link/route.ts b/apps/web/app/api/auth/verify/resend-link/route.ts index 3b7bd6524..125acf18d 100644 --- a/apps/web/app/api/auth/verify/resend-link/route.ts +++ b/apps/web/app/api/auth/verify/resend-link/route.ts @@ -20,5 +20,5 @@ export async function POST(req: Request) { appEmailConfirmationUrl }); - $res(data); + return $res(data); } diff --git a/apps/web/app/api/auth/verify/token/route.ts b/apps/web/app/api/auth/verify/token/route.ts index f0c880ebc..6d3df80af 100644 --- a/apps/web/app/api/auth/verify/token/route.ts +++ b/apps/web/app/api/auth/verify/token/route.ts @@ -3,7 +3,7 @@ import { verifyUserEmailByTokenRequest } from '@app/services/server/requests'; import { NextResponse } from 'next/server'; export async function POST(req: Request) { - const body = req.body as unknown as { email: string; token: string }; + const body = (await req.json()) as unknown as { email: string; token: string }; const { errors, valid: formValid } = authFormValidate(['email', 'token'], body as any); @@ -16,5 +16,5 @@ export async function POST(req: Request) { email: body.email }); - NextResponse.json(data); + return NextResponse.json(data); } diff --git a/apps/web/app/api/task-priorities/[id]/route.ts b/apps/web/app/api/task-priorities/[id]/route.ts index c634bb93d..78d749467 100644 --- a/apps/web/app/api/task-priorities/[id]/route.ts +++ b/apps/web/app/api/task-priorities/[id]/route.ts @@ -12,7 +12,7 @@ export async function PUT(req: Request) { const { searchParams } = new URL(req.url); const { id } = searchParams as unknown as { id: string }; - const datas = req.body as unknown as ITaskPrioritiesCreate; + const datas = (await req.json()) as unknown as ITaskPrioritiesCreate; return $res( await editTaskPrioritiesRequest({ id, diff --git a/apps/web/app/api/task-priorities/route.ts b/apps/web/app/api/task-priorities/route.ts index 21b69deb3..28147c244 100644 --- a/apps/web/app/api/task-priorities/route.ts +++ b/apps/web/app/api/task-priorities/route.ts @@ -28,7 +28,7 @@ export async function POST(req: Request) { if (!user) return $res('Unauthorized'); - const body = req.body as unknown as ITaskPrioritiesCreate; + const body = (await req.json()) as unknown as ITaskPrioritiesCreate; return $res(await createPrioritiesRequest(body, access_token, body?.tenantId)); } 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 011bd13b8..bcd4adc15 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 @@ -15,7 +15,7 @@ export async function PUT(req: Request) { const { searchParams } = new URL(req.url); const { id } = searchParams as unknown as { id: string }; - const datas = req.body as unknown as ITaskRelatedIssueTypeCreate; + const datas = (await req.json()) as unknown as ITaskRelatedIssueTypeCreate; return $res( await editTaskRelatedIssueTypeRequest({ id, 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 63b43ea9e..d2b791d4d 100644 --- a/apps/web/app/api/task-related-issue-types/route.ts +++ b/apps/web/app/api/task-related-issue-types/route.ts @@ -31,7 +31,7 @@ export async function POST(req: Request) { if (!user) return $res('Unauthorized'); - const body = req.body as unknown as ITaskRelatedIssueTypeCreate; + const body = (await req.json()) as unknown as ITaskRelatedIssueTypeCreate; return $res(await createRelatedIssueTypeRequest(body, access_token, body?.tenantId)); } diff --git a/apps/web/app/api/task-sizes/[id]/route.ts b/apps/web/app/api/task-sizes/[id]/route.ts index 498f19343..43e63176e 100644 --- a/apps/web/app/api/task-sizes/[id]/route.ts +++ b/apps/web/app/api/task-sizes/[id]/route.ts @@ -12,7 +12,7 @@ export async function PUT(req: Request) { const { searchParams } = new URL(req.url); const { id } = searchParams as unknown as { id: string }; - const datas = req.body as unknown as ITaskSizesCreate; + const datas = (await req.json()) as unknown as ITaskSizesCreate; return $res( await editTaskSizesRequest({ id, diff --git a/apps/web/app/api/task-sizes/route.ts b/apps/web/app/api/task-sizes/route.ts index 6063a9325..30d9381e8 100644 --- a/apps/web/app/api/task-sizes/route.ts +++ b/apps/web/app/api/task-sizes/route.ts @@ -28,7 +28,7 @@ export async function POST(req: Request) { if (!user) return $res('Unauthorized'); - const body = req.body as unknown as ITaskSizesCreate; + const body = (await req.json()) as unknown as ITaskSizesCreate; return $res(await createSizesRequest(body, access_token, body?.tenantId)); } diff --git a/apps/web/app/api/task-statuses/[id]/route.ts b/apps/web/app/api/task-statuses/[id]/route.ts index 245ecf602..ef377b0a8 100644 --- a/apps/web/app/api/task-statuses/[id]/route.ts +++ b/apps/web/app/api/task-statuses/[id]/route.ts @@ -12,7 +12,7 @@ export async function PUT(req: Request) { const { searchParams } = new URL(req.url); const { id } = searchParams as unknown as { id: string }; - const datas = req.body as unknown as ITaskStatusCreate; + const datas = (await req.json()) as unknown as ITaskStatusCreate; return $res( await editTaskStatusRequest({ id, diff --git a/apps/web/app/api/task-statuses/route.ts b/apps/web/app/api/task-statuses/route.ts index f307de118..8910dd1e6 100644 --- a/apps/web/app/api/task-statuses/route.ts +++ b/apps/web/app/api/task-statuses/route.ts @@ -28,7 +28,7 @@ export async function POST(req: Request) { if (!user) return $res('Unauthorized'); - const body = req.body as unknown as ITaskStatusCreate; + const body = (await req.json()) as unknown as ITaskStatusCreate; return $res(await createStatusRequest(body, access_token, body?.tenantId)); } diff --git a/apps/web/app/api/task-versions/[id]/route.ts b/apps/web/app/api/task-versions/[id]/route.ts index 155a04cfa..3b3661803 100644 --- a/apps/web/app/api/task-versions/[id]/route.ts +++ b/apps/web/app/api/task-versions/[id]/route.ts @@ -12,7 +12,7 @@ export async function PUT(req: Request) { const { searchParams } = new URL(req.url); const { id } = searchParams as unknown as { id: string }; - const datas = req.body as unknown as ITaskVersionCreate; + const datas = (await req.json()) as unknown as ITaskVersionCreate; return $res( await editTaskVersionRequest({ id, diff --git a/apps/web/app/api/task-versions/route.ts b/apps/web/app/api/task-versions/route.ts index d04d94151..a680437be 100644 --- a/apps/web/app/api/task-versions/route.ts +++ b/apps/web/app/api/task-versions/route.ts @@ -28,7 +28,7 @@ export async function POST(req: Request) { if (!user) return $res('Unauthorized'); - const body = req.body as unknown as ITaskVersionCreate; + const body = (await req.json()) as unknown as ITaskVersionCreate; return $res(await createVersionRequest(body, access_token, body?.tenantId)); } diff --git a/apps/web/app/api/tasks/[id]/route.ts b/apps/web/app/api/tasks/[id]/route.ts index e9504e9e7..18b89220c 100644 --- a/apps/web/app/api/tasks/[id]/route.ts +++ b/apps/web/app/api/tasks/[id]/route.ts @@ -33,7 +33,7 @@ export async function PUT(req: Request) { const { searchParams } = new URL(req.url); const { id: taskId } = searchParams as unknown as { id: string }; - const body = req.body as unknown as ITeamTask; + const body = (await req.json()) as unknown as ITeamTask; delete body.selectedTeam; delete body.rootEpic; @@ -54,6 +54,6 @@ export async function PUT(req: Request) { bearer_token: access_token }); - $res(tasks); + return $res(tasks); } // Unauthorized; diff --git a/apps/web/app/api/tasks/employee/[employeeId]/route.ts b/apps/web/app/api/tasks/employee/[employeeId]/route.ts index c012dd2df..524ed0fa3 100644 --- a/apps/web/app/api/tasks/employee/[employeeId]/route.ts +++ b/apps/web/app/api/tasks/employee/[employeeId]/route.ts @@ -14,7 +14,7 @@ export async function DELETE(req: Request) { organizationTeamId: string; }; - $res( + return $res( await deleteEmployeeFromTasksRequest({ tenantId, employeeId, diff --git a/apps/web/app/api/tasks/task-linked-issue/route.ts b/apps/web/app/api/tasks/task-linked-issue/route.ts index 2af790fd3..64b3c5aa7 100644 --- a/apps/web/app/api/tasks/task-linked-issue/route.ts +++ b/apps/web/app/api/tasks/task-linked-issue/route.ts @@ -8,10 +8,10 @@ export async function POST(req: Request) { const { $res, user, tenantId, access_token } = await authenticatedGuard(req, res); if (!user) return $res('Unauthorized'); - const body = req.body as unknown as ITaskLinkedIssue; + const body = (await req.json()) as unknown as ITaskLinkedIssue; const response = await createTaskLinkedIsssue(body, access_token, tenantId); - $res(response.data); + return $res(response.data); } export async function PUT(req: Request) { @@ -19,9 +19,8 @@ export async function PUT(req: Request) { const { $res, user, tenantId, access_token } = await authenticatedGuard(req, res); if (!user) return $res('Unauthorized'); - const body = req.body as unknown as LinkedTaskIssue; + const body = (await req.json()) as unknown as LinkedTaskIssue; const response = await updateTaskLinkedIssue(body, access_token, tenantId); - $res(response.data); - return; + return $res(response.data); } diff --git a/apps/web/app/api/tasks/team/route.ts b/apps/web/app/api/tasks/team/route.ts index 2b250afaa..a7fdaf055 100644 --- a/apps/web/app/api/tasks/team/route.ts +++ b/apps/web/app/api/tasks/team/route.ts @@ -11,7 +11,7 @@ export async function POST(req: Request) { ); if (!user) return $res('Unauthorized'); - const body: Record = req.body || {}; + const body: Record = (await req.json()) || {}; const title = body.title?.trim() || ''; if (title.trim().length < 2) { @@ -48,5 +48,5 @@ export async function POST(req: Request) { bearer_token: access_token }); - $res(tasks); + return $res(tasks); } diff --git a/apps/web/app/api/timer/status/route.ts b/apps/web/app/api/timer/status/route.ts index a123a3e06..e4a19c36b 100644 --- a/apps/web/app/api/timer/status/route.ts +++ b/apps/web/app/api/timer/status/route.ts @@ -9,5 +9,5 @@ export async function GET(req: Request) { const { data } = await getTimerStatusRequest({ tenantId, organizationId }, access_token); - $res(data); + return $res(data); } diff --git a/apps/web/app/api/timer/stop/route.ts b/apps/web/app/api/timer/stop/route.ts index c37bf401b..d8aae0900 100644 --- a/apps/web/app/api/timer/stop/route.ts +++ b/apps/web/app/api/timer/stop/route.ts @@ -8,7 +8,7 @@ export async function POST(req: Request) { const { $res, user, tenantId, access_token, organizationId, taskId } = await authenticatedGuard(req, res); if (!user) return $res('Unauthorized'); - const body = req.body as unknown as { source: any }; + const body = (await req.json()) as unknown as { source: any }; const { source } = body; await stopTimerRequest( { diff --git a/apps/web/app/api/timer/sync/route.ts b/apps/web/app/api/timer/sync/route.ts index b91fbb2e1..6d36ec3ac 100644 --- a/apps/web/app/api/timer/sync/route.ts +++ b/apps/web/app/api/timer/sync/route.ts @@ -7,7 +7,7 @@ export async function POST(req: Request) { const { $res, user, tenantId, access_token, organizationId } = await authenticatedGuard(req, res); if (!user) return $res('Unauthorized'); - const body = req.body as unknown as { source: any }; + const body = (await req.json()) as unknown as { source: any }; const { source } = body; await syncTimeSlotRequest( { diff --git a/apps/web/app/api/timer/toogle/route.ts b/apps/web/app/api/timer/toogle/route.ts index e8b2d3b72..63a380aac 100644 --- a/apps/web/app/api/timer/toogle/route.ts +++ b/apps/web/app/api/timer/toogle/route.ts @@ -7,7 +7,7 @@ export async function POST(req: Request) { const { $res, user, tenantId, access_token, organizationId, taskId } = await authenticatedGuard(req, res); if (!user) return $res(''); - const body = req.body as unknown as { source: any }; + const body = (await req.json()) as unknown as { source: any }; const { source } = body; await toggleTimerRequest( diff --git a/apps/web/app/api/user/[id]/route.ts b/apps/web/app/api/user/[id]/route.ts index 1793d2bf0..c55dbc8c1 100644 --- a/apps/web/app/api/user/[id]/route.ts +++ b/apps/web/app/api/user/[id]/route.ts @@ -26,7 +26,7 @@ export async function POST(req: Request) { const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); if (!user) return $res('Unauthorized'); - const body = req.body as unknown as IUser; + const body = (await req.json()) as unknown as IUser; return $res( await updateUserAvatarRequest( diff --git a/apps/web/app/api/user/me/route.ts b/apps/web/app/api/user/me/route.ts index 484ec1bba..22148570a 100644 --- a/apps/web/app/api/user/me/route.ts +++ b/apps/web/app/api/user/me/route.ts @@ -6,5 +6,5 @@ export async function GET(req: Request) { const { $res, user } = await authenticatedGuard(req, res); if (!user) return $res('Unauthorized'); - $res(user); + return $res(user); } diff --git a/apps/web/app/services/server/requests/auth.ts b/apps/web/app/services/server/requests/auth.ts index 82bed4974..9e32cd8be 100644 --- a/apps/web/app/services/server/requests/auth.ts +++ b/apps/web/app/services/server/requests/auth.ts @@ -52,7 +52,8 @@ export function signInWorkspaceRequest(email: string, token: string) { return serverFetch({ path: '/auth/signin.workspace', method: 'POST', - body: { email, token } + body: { email, token }, + bearer_token: token }); } diff --git a/apps/web/app/api/auth/signin-workspace/route.ts b/apps/web/pages/api/auth/signin-workspace.ts similarity index 87% rename from apps/web/app/api/auth/signin-workspace/route.ts rename to apps/web/pages/api/auth/signin-workspace.ts index 7aaf890ef..25dbdd672 100644 --- a/apps/web/app/api/auth/signin-workspace/route.ts +++ b/apps/web/pages/api/auth/signin-workspace.ts @@ -1,4 +1,5 @@ import { authFormValidate } from '@app/helpers/validations'; +import { NextApiRequest, NextApiResponse } from 'next'; import { acceptInviteRequest, getAllOrganizationTeamRequest, @@ -8,12 +9,13 @@ import { } from '@app/services/server/requests'; import { generateToken, setAuthCookies, setNoTeamPopupShowCookie } from '@app/helpers'; import { ILoginResponse } from '@app/interfaces'; -import { NextResponse } from 'next/server'; -export async function POST(req: Request) { - const res = new NextResponse(); +export default async function handler(req: NextApiRequest, res: NextApiResponse) { + if (req.method !== 'POST') { + return res.status(405).json({ status: 'fail' }); + } - const body = req.body as unknown as { + const body = req.body as { email: string; token: string; teamId: string; @@ -24,7 +26,7 @@ export async function POST(req: Request) { const { errors, valid: formValid } = authFormValidate(['email'], body as any); if (!formValid) { - return NextResponse.json({ errors }); + return res.status(400).json({ errors }); } // Accept Invite Flow Start @@ -59,7 +61,7 @@ export async function POST(req: Request) { acceptInviteRes.response.status === 400 || (acceptInviteRes.data as any).response?.statusCode ) { - return NextResponse.json({ + return res.status(400).json({ errors: { email: 'Authentication code or email address invalid' } @@ -68,7 +70,7 @@ export async function POST(req: Request) { loginResponse = acceptInviteRes.data; if (!loginResponse) { - return NextResponse.json({ + return res.status(400).json({ errors: { email: 'Authentication code or email address invalid' } @@ -89,7 +91,7 @@ export async function POST(req: Request) { const organization = organizations?.items[0]; if (!organization) { - return NextResponse.json({ + return res.status(400).json({ errors: { email: 'Your account is not yet ready to be used on the Ever Teams Platform' } @@ -120,7 +122,7 @@ export async function POST(req: Request) { req, res ); - return NextResponse.json({ team, loginResponse }); + return res.status(200).json({ team, loginResponse }); } // Accept Invite Flow End @@ -138,7 +140,7 @@ export async function POST(req: Request) { const organization = organizations?.items[0]; if (!organization) { - return NextResponse.json({ + return res.status(400).json({ errors: { email: 'Your account is not yet ready to be used on the Ever Teams Platform' } @@ -162,5 +164,5 @@ export async function POST(req: Request) { res ); - NextResponse.json({ loginResponse: data }); + res.status(200).json({ loginResponse: data }); } From cac24d4f3286323319f7499541d737c9ef1a38c1 Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Sat, 6 Jan 2024 20:27:23 +0200 Subject: [PATCH 11/22] feat: move tags and employee API routes to app --- .../email-reset/request-change-email/route.ts | 20 +++++++++ .../email-reset/verify-change-email/route.ts | 20 +++++++++ apps/web/app/api/employee/working/route.ts | 13 ++++++ apps/web/app/api/tags/[id]/route.ts | 42 +++++++++++++++++++ apps/web/app/api/tags/level/route.ts | 22 ++++++++++ apps/web/app/api/tags/route.ts | 34 +++++++++++++++ apps/web/app/api/timer/start/route.ts | 1 + .../email-reset/request-change-email.ts | 0 .../email-reset/verify-change-email.ts | 0 .../api/{ => _moved}/employee/working.ts | 0 apps/web/pages/api/{ => _moved}/tags/[id].ts | 0 .../web/pages/api/{ => _moved}/tags/index.tsx | 0 apps/web/pages/api/{ => _moved}/tags/level.ts | 0 13 files changed, 152 insertions(+) create mode 100644 apps/web/app/api/email-reset/request-change-email/route.ts create mode 100644 apps/web/app/api/email-reset/verify-change-email/route.ts create mode 100644 apps/web/app/api/employee/working/route.ts create mode 100644 apps/web/app/api/tags/[id]/route.ts create mode 100644 apps/web/app/api/tags/level/route.ts create mode 100644 apps/web/app/api/tags/route.ts rename apps/web/pages/api/{ => _moved}/email-reset/request-change-email.ts (100%) rename apps/web/pages/api/{ => _moved}/email-reset/verify-change-email.ts (100%) rename apps/web/pages/api/{ => _moved}/employee/working.ts (100%) rename apps/web/pages/api/{ => _moved}/tags/[id].ts (100%) rename apps/web/pages/api/{ => _moved}/tags/index.tsx (100%) rename apps/web/pages/api/{ => _moved}/tags/level.ts (100%) diff --git a/apps/web/app/api/email-reset/request-change-email/route.ts b/apps/web/app/api/email-reset/request-change-email/route.ts new file mode 100644 index 000000000..4c929a74f --- /dev/null +++ b/apps/web/app/api/email-reset/request-change-email/route.ts @@ -0,0 +1,20 @@ +import { IEmail } from '@app/interfaces/IUserData'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { emailResetRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + if (!user) return NextResponse.json({ error: 'unauthorized' }, { status: 401 }); + + const { email } = (await req.json()) as IEmail; + + return $res( + await emailResetRequest({ + email, + tenantId, + bearer_token: access_token + }) + ); +} diff --git a/apps/web/app/api/email-reset/verify-change-email/route.ts b/apps/web/app/api/email-reset/verify-change-email/route.ts new file mode 100644 index 000000000..382970eb3 --- /dev/null +++ b/apps/web/app/api/email-reset/verify-change-email/route.ts @@ -0,0 +1,20 @@ +import { ICode } from '@app/interfaces/IUserData'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { verifyChangemailRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + if (!user) return NextResponse.json({ error: 'unauthorized' }, { status: 401 }); + + const { code } = (await req.json()) as ICode; + + return $res( + await verifyChangemailRequest({ + code, + tenantId, + bearer_token: access_token + }) + ); +} diff --git a/apps/web/app/api/employee/working/route.ts b/apps/web/app/api/employee/working/route.ts new file mode 100644 index 000000000..be5643a38 --- /dev/null +++ b/apps/web/app/api/employee/working/route.ts @@ -0,0 +1,13 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { getOrganizationEmployees } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); + + const { data } = await getOrganizationEmployees(access_token, tenantId, organizationId); + + $res(data); +} diff --git a/apps/web/app/api/tags/[id]/route.ts b/apps/web/app/api/tags/[id]/route.ts new file mode 100644 index 000000000..56ffec477 --- /dev/null +++ b/apps/web/app/api/tags/[id]/route.ts @@ -0,0 +1,42 @@ +import { ITaskLabelsCreate } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { deleteTaskLabelsRequest, editTaskLabelsRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function DELETE(req: Request) { + const { searchParams } = new URL(req.url); + 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 } = searchParams as unknown as { id: string }; + + return $res( + await deleteTaskLabelsRequest({ + id, + bearer_token: access_token, + tenantId + }) + ); +} + +export async function PUT(req: Request) { + const { searchParams } = new URL(req.url); + const body = (await req.json()) as unknown as ITaskLabelsCreate; + 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 } = searchParams as unknown as { id: string }; + + return $res( + await editTaskLabelsRequest({ + id, + datas: body, + bearer_token: access_token, + tenantId + }) + ); +} diff --git a/apps/web/app/api/tags/level/route.ts b/apps/web/app/api/tags/level/route.ts new file mode 100644 index 000000000..e0f5ebffa --- /dev/null +++ b/apps/web/app/api/tags/level/route.ts @@ -0,0 +1,22 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { getTaskLabelsListRequest } from '@app/services/server/requests/task-labels'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { searchParams } = new URL(req.url); + + const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + + if (!user) return NextResponse.json({ error: 'unauthorized' }); + + const { organizationTeamId } = searchParams as unknown as { organizationTeamId: string }; + + const par = { + tenantId, + organizationId, + organizationTeamId: (organizationTeamId as string) || null + }; + + return $res(await getTaskLabelsListRequest(par, access_token)); +} diff --git a/apps/web/app/api/tags/route.ts b/apps/web/app/api/tags/route.ts new file mode 100644 index 000000000..ca58d9480 --- /dev/null +++ b/apps/web/app/api/tags/route.ts @@ -0,0 +1,34 @@ +import { ITaskLabelsCreate } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { createLabelsRequest, getTaskLabelsListRequest } from '@app/services/server/requests/task-labels'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { searchParams } = new URL(req.url); + + const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + + if (!user) return NextResponse.json({ error: 'unathorized' }, { status: 401 }); + + const { organizationTeamId } = searchParams as unknown as { organizationTeamId: string }; + + const par = { + tenantId, + organizationId, + organizationTeamId: (organizationTeamId as string) || null + }; + + return $res(await getTaskLabelsListRequest(par, access_token)); +} + +export async function POST(req: Request) { + const res = new NextResponse(); + const body = (await req.json()) as ITaskLabelsCreate; + + const { $res, user, access_token } = await authenticatedGuard(req, res); + + if (!user) return NextResponse.json({ error: 'unathorized' }, { status: 401 }); + + return $res(await createLabelsRequest(body, access_token, body?.tenantId)); +} diff --git a/apps/web/app/api/timer/start/route.ts b/apps/web/app/api/timer/start/route.ts index bb5fa6595..175421893 100644 --- a/apps/web/app/api/timer/start/route.ts +++ b/apps/web/app/api/timer/start/route.ts @@ -14,6 +14,7 @@ export async function POST(req: Request) { taskId, teamId: organizationTeamId } = await authenticatedGuard(req, res); + console.log({ user, tenantId, taskId}) if (!user) return $res('Unauthorized'); await startTimerRequest( diff --git a/apps/web/pages/api/email-reset/request-change-email.ts b/apps/web/pages/api/_moved/email-reset/request-change-email.ts similarity index 100% rename from apps/web/pages/api/email-reset/request-change-email.ts rename to apps/web/pages/api/_moved/email-reset/request-change-email.ts diff --git a/apps/web/pages/api/email-reset/verify-change-email.ts b/apps/web/pages/api/_moved/email-reset/verify-change-email.ts similarity index 100% rename from apps/web/pages/api/email-reset/verify-change-email.ts rename to apps/web/pages/api/_moved/email-reset/verify-change-email.ts diff --git a/apps/web/pages/api/employee/working.ts b/apps/web/pages/api/_moved/employee/working.ts similarity index 100% rename from apps/web/pages/api/employee/working.ts rename to apps/web/pages/api/_moved/employee/working.ts diff --git a/apps/web/pages/api/tags/[id].ts b/apps/web/pages/api/_moved/tags/[id].ts similarity index 100% rename from apps/web/pages/api/tags/[id].ts rename to apps/web/pages/api/_moved/tags/[id].ts diff --git a/apps/web/pages/api/tags/index.tsx b/apps/web/pages/api/_moved/tags/index.tsx similarity index 100% rename from apps/web/pages/api/tags/index.tsx rename to apps/web/pages/api/_moved/tags/index.tsx diff --git a/apps/web/pages/api/tags/level.ts b/apps/web/pages/api/_moved/tags/level.ts similarity index 100% rename from apps/web/pages/api/tags/level.ts rename to apps/web/pages/api/_moved/tags/level.ts From 7a4fc218d5acaaf56a255b3620b4bd062ac72395 Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Sat, 6 Jan 2024 20:51:45 +0200 Subject: [PATCH 12/22] feat: move roles routes to /app folder --- .../app/api/role-permissions/[id]/route.ts | 42 +++++++++++++++++++ apps/web/app/api/roles/[id]/route.ts | 39 +++++++++++++++++ apps/web/app/api/roles/route.ts | 40 ++++++++++++++++++ .../api/{ => _moved}/role-permissions/[id].ts | 0 apps/web/pages/api/{ => _moved}/roles/[id].ts | 0 .../web/pages/api/{ => _moved}/roles/index.ts | 0 6 files changed, 121 insertions(+) create mode 100644 apps/web/app/api/role-permissions/[id]/route.ts create mode 100644 apps/web/app/api/roles/[id]/route.ts create mode 100644 apps/web/app/api/roles/route.ts rename apps/web/pages/api/{ => _moved}/role-permissions/[id].ts (100%) rename apps/web/pages/api/{ => _moved}/roles/[id].ts (100%) rename apps/web/pages/api/{ => _moved}/roles/index.ts (100%) diff --git a/apps/web/app/api/role-permissions/[id]/route.ts b/apps/web/app/api/role-permissions/[id]/route.ts new file mode 100644 index 000000000..17113ffaa --- /dev/null +++ b/apps/web/app/api/role-permissions/[id]/route.ts @@ -0,0 +1,42 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { getRolePermissionsRequest, updateRolePermissionRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('unauthorized'); + + const { searchParams } = new URL(req.url); + const { id } = searchParams as unknown as { id: string }; + + return $res( + ( + await getRolePermissionsRequest({ + bearer_token: access_token, + tenantId, + roleId: id as string + }) + ).data + ); +} + +export async function PUT(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('unauthorized'); + + const body = await req.json(); + + return $res( + ( + await updateRolePermissionRequest({ + bearer_token: access_token, + tenantId, + data: body + }) + ).data + ); +} diff --git a/apps/web/app/api/roles/[id]/route.ts b/apps/web/app/api/roles/[id]/route.ts new file mode 100644 index 000000000..537532d81 --- /dev/null +++ b/apps/web/app/api/roles/[id]/route.ts @@ -0,0 +1,39 @@ +import { IRole } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { deleteRoleRequest, updateRoleRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function PUT(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('unauthorized'); + const body = (await req.json()) as IRole; + + return $res( + await updateRoleRequest({ + bearer_token: access_token, + tenantId, + data: body + }) + ); +} + +export async function DELETE(req: Request) { + const res = new NextResponse(); + + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('unauthorized'); + const { searchParams } = new URL(req.url); + + const { id } = searchParams as unknown as { id: string }; + + return $res( + await deleteRoleRequest({ + id: id as string, + bearer_token: access_token, + tenantId + }) + ); +} diff --git a/apps/web/app/api/roles/route.ts b/apps/web/app/api/roles/route.ts new file mode 100644 index 000000000..cc4a1fe87 --- /dev/null +++ b/apps/web/app/api/roles/route.ts @@ -0,0 +1,40 @@ +import { IRole } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; + +import { createRoleRequest, getRolesRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + 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 + ); +} + +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 + ); +} diff --git a/apps/web/pages/api/role-permissions/[id].ts b/apps/web/pages/api/_moved/role-permissions/[id].ts similarity index 100% rename from apps/web/pages/api/role-permissions/[id].ts rename to apps/web/pages/api/_moved/role-permissions/[id].ts diff --git a/apps/web/pages/api/roles/[id].ts b/apps/web/pages/api/_moved/roles/[id].ts similarity index 100% rename from apps/web/pages/api/roles/[id].ts rename to apps/web/pages/api/_moved/roles/[id].ts diff --git a/apps/web/pages/api/roles/index.ts b/apps/web/pages/api/_moved/roles/index.ts similarity index 100% rename from apps/web/pages/api/roles/index.ts rename to apps/web/pages/api/_moved/roles/index.ts From db7d92c03230869421393b172c8f5229c7b24533 Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Sat, 6 Jan 2024 22:23:54 +0200 Subject: [PATCH 13/22] feat: move organisation-team-join route to app --- .../[id]/[action]/route.ts | 25 +++++++++++++++++++ .../resend-code/route.ts | 9 +++++++ .../app/api/organization-team-join/route.ts | 21 ++++++++++++++++ .../organization-team-join/validate/route.ts | 9 +++++++ .../organization-team-join/[id]/[action].ts | 0 .../organization-team-join/index.ts | 0 .../organization-team-join/resend-code.ts | 0 .../organization-team-join/validate.ts | 0 8 files changed, 64 insertions(+) create mode 100644 apps/web/app/api/organization-team-join/[id]/[action]/route.ts create mode 100644 apps/web/app/api/organization-team-join/resend-code/route.ts create mode 100644 apps/web/app/api/organization-team-join/route.ts create mode 100644 apps/web/app/api/organization-team-join/validate/route.ts rename apps/web/pages/api/{ => _moved}/organization-team-join/[id]/[action].ts (100%) rename apps/web/pages/api/{ => _moved}/organization-team-join/index.ts (100%) rename apps/web/pages/api/{ => _moved}/organization-team-join/resend-code.ts (100%) rename apps/web/pages/api/{ => _moved}/organization-team-join/validate.ts (100%) 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 new file mode 100644 index 000000000..477a21f46 --- /dev/null +++ b/apps/web/app/api/organization-team-join/[id]/[action]/route.ts @@ -0,0 +1,25 @@ +import { IRequestToJoinActionEnum } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { acceptRejectRequestToJoinRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function PUT(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + if (!user) return $res('unauthorized'); + + const { searchParams } = new URL(req.url); + + const { id, action } = searchParams as unknown as { id: string; action: string }; + + if (id) { + return $res( + await acceptRejectRequestToJoinRequest({ + id: id as string, + bearer_token: access_token, + tenantId, + action: action as IRequestToJoinActionEnum + }) + ); + } +} 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 new file mode 100644 index 000000000..18ff21df6 --- /dev/null +++ b/apps/web/app/api/organization-team-join/resend-code/route.ts @@ -0,0 +1,9 @@ +import { IRequestToJoinCreate } from '@app/interfaces'; +import { resendCodeRequestToJoinRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const body = (await req.json()) as IRequestToJoinCreate; + + return NextResponse.json(await resendCodeRequestToJoinRequest(body)); +} diff --git a/apps/web/app/api/organization-team-join/route.ts b/apps/web/app/api/organization-team-join/route.ts new file mode 100644 index 000000000..097d58a53 --- /dev/null +++ b/apps/web/app/api/organization-team-join/route.ts @@ -0,0 +1,21 @@ +import { IRequestToJoinCreate } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { getRequestToJoinRequest, requestToJoinRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + + const requestToJoinData = await getRequestToJoinRequest({ + bearer_token: access_token, + tenantId, + organizationId + }); + return NextResponse.json(requestToJoinData.data); +} + +export async function POST(req: Request) { + const body = (await req.json()) as IRequestToJoinCreate; + return NextResponse.json(await requestToJoinRequest(body)); +} diff --git a/apps/web/app/api/organization-team-join/validate/route.ts b/apps/web/app/api/organization-team-join/validate/route.ts new file mode 100644 index 000000000..8ef997a76 --- /dev/null +++ b/apps/web/app/api/organization-team-join/validate/route.ts @@ -0,0 +1,9 @@ +import { IValidateRequestToJoin } from '@app/interfaces'; +import { validateRequestToJoinRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const body = (await req.json()) as IValidateRequestToJoin; + + return NextResponse.json(await validateRequestToJoinRequest(body)); +} diff --git a/apps/web/pages/api/organization-team-join/[id]/[action].ts b/apps/web/pages/api/_moved/organization-team-join/[id]/[action].ts similarity index 100% rename from apps/web/pages/api/organization-team-join/[id]/[action].ts rename to apps/web/pages/api/_moved/organization-team-join/[id]/[action].ts diff --git a/apps/web/pages/api/organization-team-join/index.ts b/apps/web/pages/api/_moved/organization-team-join/index.ts similarity index 100% rename from apps/web/pages/api/organization-team-join/index.ts rename to apps/web/pages/api/_moved/organization-team-join/index.ts diff --git a/apps/web/pages/api/organization-team-join/resend-code.ts b/apps/web/pages/api/_moved/organization-team-join/resend-code.ts similarity index 100% rename from apps/web/pages/api/organization-team-join/resend-code.ts rename to apps/web/pages/api/_moved/organization-team-join/resend-code.ts diff --git a/apps/web/pages/api/organization-team-join/validate.ts b/apps/web/pages/api/_moved/organization-team-join/validate.ts similarity index 100% rename from apps/web/pages/api/organization-team-join/validate.ts rename to apps/web/pages/api/_moved/organization-team-join/validate.ts From 9a9596d542fb27910f082e18c05ec83864688679 Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Sun, 7 Jan 2024 13:20:29 +0200 Subject: [PATCH 14/22] fix: get dynamic params --- apps/web/app/api/auth/login/{login.ts => route.ts} | 0 .../organization-team-join/[id]/[action]/route.ts | 4 ++-- .../api/public/team/[profileLink]/[teamId]/route.ts | 11 ++++------- apps/web/app/api/role-permissions/[id]/route.ts | 5 ++--- apps/web/app/api/roles/[id]/route.ts | 5 ++--- apps/web/app/api/tags/[id]/route.ts | 10 ++++------ apps/web/app/api/task-priorities/[id]/route.ts | 12 ++++++------ .../app/api/task-related-issue-types/[id]/route.ts | 12 ++++++------ apps/web/app/api/task-sizes/[id]/route.ts | 10 ++++------ apps/web/app/api/task-statuses/[id]/route.ts | 10 ++++------ apps/web/app/api/task-versions/[id]/route.ts | 10 ++++------ apps/web/app/api/tasks/[id]/route.ts | 10 ++++------ .../web/app/api/tasks/employee/[employeeId]/route.ts | 6 +++--- apps/web/app/api/user/[id]/route.ts | 5 ++--- 14 files changed, 47 insertions(+), 63 deletions(-) rename apps/web/app/api/auth/login/{login.ts => route.ts} (100%) diff --git a/apps/web/app/api/auth/login/login.ts b/apps/web/app/api/auth/login/route.ts similarity index 100% rename from apps/web/app/api/auth/login/login.ts rename to apps/web/app/api/auth/login/route.ts 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 477a21f46..edfb1f0b9 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 @@ -3,14 +3,14 @@ import { authenticatedGuard } from '@app/services/server/guards/authenticated-gu import { acceptRejectRequestToJoinRequest } from '@app/services/server/requests'; import { NextResponse } from 'next/server'; -export async function PUT(req: Request) { +export async function PUT(req: Request, { params }: { params : { id: string; action: string}}) { const res = new NextResponse(); const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); if (!user) return $res('unauthorized'); const { searchParams } = new URL(req.url); - const { id, action } = searchParams as unknown as { id: string; action: string }; + const { id, action } = params; if (id) { return $res( 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 4cb5d488a..ae8430811 100644 --- a/apps/web/app/api/public/team/[profileLink]/[teamId]/route.ts +++ b/apps/web/app/api/public/team/[profileLink]/[teamId]/route.ts @@ -4,14 +4,11 @@ import { } from '@app/services/server/requests/public-organization-team'; import { NextResponse } from 'next/server'; -export async function GET(req: Request) { +export async function GET(req: Request, { params }: { params: { profileLink: string; teamId: string } }) { const { searchParams } = new URL(req.url); - const { profileLink, teamId, type }: { profileLink: string; teamId: string; type: string } = - searchParams as unknown as { - profileLink: string; - teamId: string; - type: string; - }; + + const { profileLink, teamId, } = params; + const { type } = searchParams as unknown as {type: string;}; if (type === 'misc') { return NextResponse.json( diff --git a/apps/web/app/api/role-permissions/[id]/route.ts b/apps/web/app/api/role-permissions/[id]/route.ts index 17113ffaa..4dea0195c 100644 --- a/apps/web/app/api/role-permissions/[id]/route.ts +++ b/apps/web/app/api/role-permissions/[id]/route.ts @@ -2,14 +2,13 @@ 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) { +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 { searchParams } = new URL(req.url); - const { id } = searchParams as unknown as { id: string }; + const { id } = params; return $res( ( diff --git a/apps/web/app/api/roles/[id]/route.ts b/apps/web/app/api/roles/[id]/route.ts index 537532d81..1654f262f 100644 --- a/apps/web/app/api/roles/[id]/route.ts +++ b/apps/web/app/api/roles/[id]/route.ts @@ -19,15 +19,14 @@ export async function PUT(req: Request) { ); } -export async function DELETE(req: Request) { +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 { searchParams } = new URL(req.url); - const { id } = searchParams as unknown as { id: string }; + const { id } = params return $res( await deleteRoleRequest({ diff --git a/apps/web/app/api/tags/[id]/route.ts b/apps/web/app/api/tags/[id]/route.ts index 56ffec477..cc2703a2d 100644 --- a/apps/web/app/api/tags/[id]/route.ts +++ b/apps/web/app/api/tags/[id]/route.ts @@ -3,14 +3,13 @@ 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) { - const { searchParams } = new URL(req.url); +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 } = searchParams as unknown as { id: string }; + const { id } = params; return $res( await deleteTaskLabelsRequest({ @@ -21,15 +20,14 @@ export async function DELETE(req: Request) { ); } -export async function PUT(req: Request) { - const { searchParams } = new URL(req.url); +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); if (!user) return NextResponse.json({ error: 'unauthorized' }, { status: 401 }); - const { id } = searchParams as unknown as { id: string }; + const { id } = params; return $res( await editTaskLabelsRequest({ diff --git a/apps/web/app/api/task-priorities/[id]/route.ts b/apps/web/app/api/task-priorities/[id]/route.ts index 78d749467..36396543f 100644 --- a/apps/web/app/api/task-priorities/[id]/route.ts +++ b/apps/web/app/api/task-priorities/[id]/route.ts @@ -3,14 +3,14 @@ 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) { +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 { searchParams } = new URL(req.url); - const { id } = searchParams as unknown as { id: string }; + + const { id } = params; const datas = (await req.json()) as unknown as ITaskPrioritiesCreate; return $res( @@ -23,14 +23,14 @@ export async function PUT(req: Request) { ); } -export async function DELETE(req: Request) { +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 { searchParams } = new URL(req.url); - const { id } = searchParams as unknown as { id: string }; + + const { id } = params; return $res( await deleteTaskPrioritiesRequest({ 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 bcd4adc15..86e9f972f 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,14 +6,14 @@ import { } from '@app/services/server/requests/task-related-issue-type'; import { NextResponse } from 'next/server'; -export async function PUT(req: Request) { +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 { searchParams } = new URL(req.url); - const { id } = searchParams as unknown as { id: string }; + + const { id } = params; const datas = (await req.json()) as unknown as ITaskRelatedIssueTypeCreate; return $res( @@ -26,14 +26,14 @@ export async function PUT(req: Request) { ); } -export async function DELETE(req: Request) { +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 { searchParams } = new URL(req.url); - const { id } = searchParams as unknown as { id: string }; + + const { id } = params; return $res( await deleteTaskRelatedIssueTypeRequest({ diff --git a/apps/web/app/api/task-sizes/[id]/route.ts b/apps/web/app/api/task-sizes/[id]/route.ts index 43e63176e..d54aba1a0 100644 --- a/apps/web/app/api/task-sizes/[id]/route.ts +++ b/apps/web/app/api/task-sizes/[id]/route.ts @@ -3,14 +3,13 @@ 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) { +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 { searchParams } = new URL(req.url); - const { id } = searchParams as unknown as { id: string }; + const { id } = params const datas = (await req.json()) as unknown as ITaskSizesCreate; return $res( @@ -23,14 +22,13 @@ export async function PUT(req: Request) { ); } -export async function DELETE(req: Request) { +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 { searchParams } = new URL(req.url); - const { id } = searchParams as unknown as { id: string }; + const { id } = params return $res( await deleteTaskSizesRequest({ diff --git a/apps/web/app/api/task-statuses/[id]/route.ts b/apps/web/app/api/task-statuses/[id]/route.ts index ef377b0a8..64e656609 100644 --- a/apps/web/app/api/task-statuses/[id]/route.ts +++ b/apps/web/app/api/task-statuses/[id]/route.ts @@ -3,14 +3,13 @@ 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) { +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 { searchParams } = new URL(req.url); - const { id } = searchParams as unknown as { id: string }; + const { id } = params; const datas = (await req.json()) as unknown as ITaskStatusCreate; return $res( @@ -23,14 +22,13 @@ export async function PUT(req: Request) { ); } -export async function DELETE(req: Request) { +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 { searchParams } = new URL(req.url); - const { id } = searchParams as unknown as { id: string }; + const { id } = params; return $res( await deleteTaskStatusRequest({ diff --git a/apps/web/app/api/task-versions/[id]/route.ts b/apps/web/app/api/task-versions/[id]/route.ts index 3b3661803..fb78de3c8 100644 --- a/apps/web/app/api/task-versions/[id]/route.ts +++ b/apps/web/app/api/task-versions/[id]/route.ts @@ -3,14 +3,13 @@ import { authenticatedGuard } from '@app/services/server/guards/authenticated-gu import { deleteTaskVersionRequest, editTaskVersionRequest } from '@app/services/server/requests/task-version'; import { NextResponse } from 'next/server'; -export async function PUT(req: Request) { +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 { searchParams } = new URL(req.url); - const { id } = searchParams as unknown as { id: string }; + const { id } = params; const datas = (await req.json()) as unknown as ITaskVersionCreate; return $res( @@ -23,14 +22,13 @@ export async function PUT(req: Request) { ); } -export async function DELETE(req: Request) { +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 { searchParams } = new URL(req.url); - const { id } = searchParams as unknown as { id: string }; + const { id } = params; return $res( await deleteTaskVersionRequest({ diff --git a/apps/web/app/api/tasks/[id]/route.ts b/apps/web/app/api/tasks/[id]/route.ts index 18b89220c..7a1e366b2 100644 --- a/apps/web/app/api/tasks/[id]/route.ts +++ b/apps/web/app/api/tasks/[id]/route.ts @@ -3,14 +3,14 @@ import { authenticatedGuard } from '@app/services/server/guards/authenticated-gu import { getTeamTasksRequest, updateTaskRequest, getTaskByIdRequest } from '@app/services/server/requests'; import { NextResponse } from 'next/server'; -export async function GET(req: Request) { +export async function GET(req: Request, { params }: { params: { id: string } }) { const res = new NextResponse(); const { $res, user, tenantId, access_token, organizationId } = await authenticatedGuard(req, res); if (!user) return $res('Unauthorized'); const { searchParams } = new URL(req.url); - const { id: taskId } = searchParams as unknown as { id: string }; + const { id: taskId } = params return $res( await getTaskByIdRequest({ @@ -22,7 +22,7 @@ export async function GET(req: Request) { ); } -export async function PUT(req: Request) { +export async function PUT(req: Request, { params }: { params: { id: string } }) { const res = new NextResponse(); const { $res, user, tenantId, access_token, organizationId, projectId, teamId } = await authenticatedGuard( req, @@ -30,9 +30,7 @@ export async function PUT(req: Request) { ); if (!user) return $res('Unauthorized'); - const { searchParams } = new URL(req.url); - - const { id: taskId } = searchParams as unknown as { id: string }; + const { id: taskId } = params const body = (await req.json()) as unknown as ITeamTask; delete body.selectedTeam; diff --git a/apps/web/app/api/tasks/employee/[employeeId]/route.ts b/apps/web/app/api/tasks/employee/[employeeId]/route.ts index 524ed0fa3..4f2b8eb82 100644 --- a/apps/web/app/api/tasks/employee/[employeeId]/route.ts +++ b/apps/web/app/api/tasks/employee/[employeeId]/route.ts @@ -2,15 +2,15 @@ import { authenticatedGuard } from '@app/services/server/guards/authenticated-gu import { deleteEmployeeFromTasksRequest } from '@app/services/server/requests'; import { NextResponse } from 'next/server'; -export async function DELETE(req: Request) { +export async function DELETE(req: Request, { params }: { params: { employeeId: string } }) { const res = new NextResponse(); const { $res, user, tenantId, access_token: bearer_token } = await authenticatedGuard(req, res); if (!user) return $res('Unauthorized'); const { searchParams } = new URL(req.url); - const { employeeId, organizationTeamId } = searchParams as unknown as { - employeeId: string; + const { employeeId} = params + const { organizationTeamId } = searchParams as unknown as { organizationTeamId: string; }; diff --git a/apps/web/app/api/user/[id]/route.ts b/apps/web/app/api/user/[id]/route.ts index c55dbc8c1..e0aab649a 100644 --- a/apps/web/app/api/user/[id]/route.ts +++ b/apps/web/app/api/user/[id]/route.ts @@ -4,14 +4,13 @@ import { getTaskCreator, updateUserAvatarRequest } from '@app/services/server/re import { deleteUserRequest } from '@app/services/server/requests/user'; import { NextResponse } from 'next/server'; -export async function GET(req: Request) { +export async function GET(req: Request, { params }: { params: { id: string } }) { const res = new NextResponse(); - const { searchParams } = new URL(req.url); const { $res, user, access_token } = await authenticatedGuard(req, res); if (!user) return $res('Unauthorized'); - const { id: userId } = searchParams as unknown as { id: string }; + const { id: userId } = params; return $res( await getTaskCreator({ userId: userId as string, From eca60e38801c6567ef40826fe5425545f17ae9d3 Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Sun, 7 Jan 2024 13:39:16 +0200 Subject: [PATCH 15/22] feat: move /organization-team-employee route --- .../[id]/active-task/route.ts | 28 ++++++++++ .../organization-team-employee/[id]/route.ts | 52 +++++++++++++++++++ .../[id]/[action]/route.ts | 4 +- apps/web/app/api/tasks/[id]/route.ts | 10 ++-- .../[id]/active-task.ts | 0 .../organization-team-employee/[id]/index.tsx | 0 6 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 apps/web/app/api/organization-team-employee/[id]/active-task/route.ts create mode 100644 apps/web/app/api/organization-team-employee/[id]/route.ts rename apps/web/pages/api/{ => _moved}/organization-team-employee/[id]/active-task.ts (100%) rename apps/web/pages/api/{ => _moved}/organization-team-employee/[id]/index.tsx (100%) 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 new file mode 100644 index 000000000..d266a056f --- /dev/null +++ b/apps/web/app/api/organization-team-employee/[id]/active-task/route.ts @@ -0,0 +1,28 @@ +import { IOrganizationTeamEmployeeUpdate } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { updateOrganizationTeamEmployeeActiveTaskRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +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 NextResponse.json({ error: 'unauthorized' }, { status: 401 }); + + const { id } = params; + const body = (await req.json()) as IOrganizationTeamEmployeeUpdate; + + switch (req.method) { + case 'PUT': + if (id) { + return $res( + await updateOrganizationTeamEmployeeActiveTaskRequest({ + id: id as string, + bearer_token: access_token, + tenantId, + body + }) + ); + } + break; + } +} diff --git a/apps/web/app/api/organization-team-employee/[id]/route.ts b/apps/web/app/api/organization-team-employee/[id]/route.ts new file mode 100644 index 000000000..654aebb94 --- /dev/null +++ b/apps/web/app/api/organization-team-employee/[id]/route.ts @@ -0,0 +1,52 @@ +import { IOrganizationTeamEmployeeUpdate } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { + deleteOrganizationTeamEmployeeRequest, + updateOrganizationTeamEmployeeRequest +} from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +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 body = (await req.json()) as IOrganizationTeamEmployeeUpdate; + + const { id } = params; + + if (id) { + return $res( + await updateOrganizationTeamEmployeeRequest({ + id: id as string, + bearer_token: access_token, + tenantId, + body: body + }) + ); + } +} + +export async function DELETE(req: Request, { params }: { params: { id: string } }) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId, teamId } = await authenticatedGuard(req, res); + if (!user) return $res('Unauthorized'); + + const { searchParams } = new URL(req.url); + + const { employeeId } = searchParams as unknown as { employeeId: string }; + const { id } = params; + + if (id) { + return $res( + await deleteOrganizationTeamEmployeeRequest({ + id: id as string, + bearer_token: access_token, + tenantId, + organizationId, + employeeId: employeeId as string, + organizationTeamId: teamId + }) + ); + } +} 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 edfb1f0b9..d649458b3 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 @@ -3,13 +3,11 @@ import { authenticatedGuard } from '@app/services/server/guards/authenticated-gu import { acceptRejectRequestToJoinRequest } from '@app/services/server/requests'; import { NextResponse } from 'next/server'; -export async function PUT(req: Request, { params }: { params : { id: string; action: string}}) { +export async function PUT(req: Request, { params }: { params: { id: string; action: string } }) { const res = new NextResponse(); const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); if (!user) return $res('unauthorized'); - const { searchParams } = new URL(req.url); - const { id, action } = params; if (id) { diff --git a/apps/web/app/api/tasks/[id]/route.ts b/apps/web/app/api/tasks/[id]/route.ts index 7a1e366b2..6c62f0a9b 100644 --- a/apps/web/app/api/tasks/[id]/route.ts +++ b/apps/web/app/api/tasks/[id]/route.ts @@ -3,14 +3,12 @@ import { authenticatedGuard } from '@app/services/server/guards/authenticated-gu import { getTeamTasksRequest, updateTaskRequest, getTaskByIdRequest } 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, tenantId, access_token, organizationId } = await authenticatedGuard(req, res); if (!user) return $res('Unauthorized'); - const { searchParams } = new URL(req.url); - - const { id: taskId } = params + const { id: taskId } = params; return $res( await getTaskByIdRequest({ @@ -22,7 +20,7 @@ export async function GET(req: Request, { params }: { params: { id: string } }) ); } -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, tenantId, access_token, organizationId, projectId, teamId } = await authenticatedGuard( req, @@ -30,7 +28,7 @@ export async function PUT(req: Request, { params }: { params: { id: string } }) ); if (!user) return $res('Unauthorized'); - const { id: taskId } = params + const { id: taskId } = params; const body = (await req.json()) as unknown as ITeamTask; delete body.selectedTeam; diff --git a/apps/web/pages/api/organization-team-employee/[id]/active-task.ts b/apps/web/pages/api/_moved/organization-team-employee/[id]/active-task.ts similarity index 100% rename from apps/web/pages/api/organization-team-employee/[id]/active-task.ts rename to apps/web/pages/api/_moved/organization-team-employee/[id]/active-task.ts diff --git a/apps/web/pages/api/organization-team-employee/[id]/index.tsx b/apps/web/pages/api/_moved/organization-team-employee/[id]/index.tsx similarity index 100% rename from apps/web/pages/api/organization-team-employee/[id]/index.tsx rename to apps/web/pages/api/_moved/organization-team-employee/[id]/index.tsx From ba7d3e443c6e88ae80b1c3bade83e09423790ca4 Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Sun, 7 Jan 2024 13:54:25 +0200 Subject: [PATCH 16/22] feat: move issues-type and languages routes --- apps/web/app/api/issue-types/[id]/route.ts | 38 +++++++++++++++++++ apps/web/app/api/issue-types/route.ts | 33 ++++++++++++++++ apps/web/app/api/languages/route.ts | 17 +++++++++ .../[id]/active-task/route.ts | 22 +++++------ .../api/{ => _moved}/issue-types/[id].ts | 0 .../api/{ => _moved}/issue-types/index.tsx | 0 .../pages/api/{ => _moved}/languages/index.ts | 0 7 files changed, 97 insertions(+), 13 deletions(-) create mode 100644 apps/web/app/api/issue-types/[id]/route.ts create mode 100644 apps/web/app/api/issue-types/route.ts create mode 100644 apps/web/app/api/languages/route.ts rename apps/web/pages/api/{ => _moved}/issue-types/[id].ts (100%) rename apps/web/pages/api/{ => _moved}/issue-types/index.tsx (100%) rename apps/web/pages/api/{ => _moved}/languages/index.ts (100%) diff --git a/apps/web/app/api/issue-types/[id]/route.ts b/apps/web/app/api/issue-types/[id]/route.ts new file mode 100644 index 000000000..5403cbe95 --- /dev/null +++ b/apps/web/app/api/issue-types/[id]/route.ts @@ -0,0 +1,38 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { deleteIssueTypesRequest, editIssueTypesRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +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 NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); + + const { id } = params; + const body = await req.json(); + + return $res( + await editIssueTypesRequest({ + id, + datas: body, + bearer_token: access_token, + tenantId + }) + ); +} + +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 deleteIssueTypesRequest({ + id, + bearer_token: access_token, + tenantId + }) + ); +} diff --git a/apps/web/app/api/issue-types/route.ts b/apps/web/app/api/issue-types/route.ts new file mode 100644 index 000000000..fe2729dcd --- /dev/null +++ b/apps/web/app/api/issue-types/route.ts @@ -0,0 +1,33 @@ +import { IIssueTypesCreate } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { createIssueTypeRequest, getIssueTypesListRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + + if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); + + const { searchParams } = new URL(req.url); + const { organizationTeamId } = searchParams as unknown as { organizationTeamId: string }; + + const par = { + tenantId, + organizationId, + organizationTeamId: (organizationTeamId as string) || null + }; + + return $res(await getIssueTypesListRequest(par, access_token)); +} + +export async function POST(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token } = await authenticatedGuard(req, res); + + if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); + + const body = (await req.json()) as IIssueTypesCreate; + + return $res(await createIssueTypeRequest(body, access_token, body?.tenantId)); +} diff --git a/apps/web/app/api/languages/route.ts b/apps/web/app/api/languages/route.ts new file mode 100644 index 000000000..bf2e8e31b --- /dev/null +++ b/apps/web/app/api/languages/route.ts @@ -0,0 +1,17 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { getLanguageListRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); + + const par = { + is_system: user.role.isSystem as boolean, + tenantId + }; + + return $res(await getLanguageListRequest(par, access_token)); +} 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 d266a056f..fddf8fbd6 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 @@ -11,18 +11,14 @@ export async function PUT(req: Request, { params }: { params: { id: string } }) const { id } = params; const body = (await req.json()) as IOrganizationTeamEmployeeUpdate; - switch (req.method) { - case 'PUT': - if (id) { - return $res( - await updateOrganizationTeamEmployeeActiveTaskRequest({ - id: id as string, - bearer_token: access_token, - tenantId, - body - }) - ); - } - break; + if (id) { + return $res( + await updateOrganizationTeamEmployeeActiveTaskRequest({ + id: id as string, + bearer_token: access_token, + tenantId, + body + }) + ); } } diff --git a/apps/web/pages/api/issue-types/[id].ts b/apps/web/pages/api/_moved/issue-types/[id].ts similarity index 100% rename from apps/web/pages/api/issue-types/[id].ts rename to apps/web/pages/api/_moved/issue-types/[id].ts diff --git a/apps/web/pages/api/issue-types/index.tsx b/apps/web/pages/api/_moved/issue-types/index.tsx similarity index 100% rename from apps/web/pages/api/issue-types/index.tsx rename to apps/web/pages/api/_moved/issue-types/index.tsx diff --git a/apps/web/pages/api/languages/index.ts b/apps/web/pages/api/_moved/languages/index.ts similarity index 100% rename from apps/web/pages/api/languages/index.ts rename to apps/web/pages/api/_moved/languages/index.ts From 271d106a7d275787f61c426088d44289a233d27e Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Sun, 7 Jan 2024 14:55:50 +0200 Subject: [PATCH 17/22] feat move /invite/* /integrtion-tenant/* routes --- .../app/api/integration-tenant/[id]/route.ts | 17 +++++ .../remember/state/route.ts | 23 ++++++ apps/web/app/api/invite/[id]/route.ts | 75 +++++++++++++++++++ apps/web/app/api/invite/emails/route.ts | 69 +++++++++++++++++ apps/web/app/api/invite/resend/route.ts | 36 +++++++++ apps/web/app/api/invite/route.ts | 21 ++++++ .../app/api/invite/validate-by-code/route.ts | 19 +++++ .../api/organization-projects/[id]/route.ts | 22 ++++++ .../setting/[id]/route.ts | 24 ++++++ .../web/pages/api/{ => _moved}/invite/[id].ts | 0 .../pages/api/{ => _moved}/invite/emails.ts | 0 .../pages/api/{ => _moved}/invite/index.ts | 0 .../pages/api/{ => _moved}/invite/resend.ts | 0 .../{ => _moved}/invite/validate-by-code.ts | 0 .../organization-projects/[id].ts | 0 .../organization-projects/setting/[id].ts | 0 16 files changed, 306 insertions(+) create mode 100644 apps/web/app/api/integration-tenant/[id]/route.ts create mode 100644 apps/web/app/api/integration-tenant/remember/state/route.ts create mode 100644 apps/web/app/api/invite/[id]/route.ts create mode 100644 apps/web/app/api/invite/emails/route.ts create mode 100644 apps/web/app/api/invite/resend/route.ts create mode 100644 apps/web/app/api/invite/route.ts create mode 100644 apps/web/app/api/invite/validate-by-code/route.ts create mode 100644 apps/web/app/api/organization-projects/[id]/route.ts create mode 100644 apps/web/app/api/organization-projects/setting/[id]/route.ts rename apps/web/pages/api/{ => _moved}/invite/[id].ts (100%) rename apps/web/pages/api/{ => _moved}/invite/emails.ts (100%) rename apps/web/pages/api/{ => _moved}/invite/index.ts (100%) rename apps/web/pages/api/{ => _moved}/invite/resend.ts (100%) rename apps/web/pages/api/{ => _moved}/invite/validate-by-code.ts (100%) rename apps/web/pages/api/{ => _moved}/organization-projects/[id].ts (100%) rename apps/web/pages/api/{ => _moved}/organization-projects/setting/[id].ts (100%) diff --git a/apps/web/app/api/integration-tenant/[id]/route.ts b/apps/web/app/api/integration-tenant/[id]/route.ts new file mode 100644 index 000000000..5ad00af5f --- /dev/null +++ b/apps/web/app/api/integration-tenant/[id]/route.ts @@ -0,0 +1,17 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { deleteIntegrationTenantRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function DELETE(req: Request, { params }: { params: { id: string } }) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); + + const { id } = params; + + if (id) { + const response = await deleteIntegrationTenantRequest(id as string, tenantId, organizationId, access_token); + + return $res(response); + } +} diff --git a/apps/web/app/api/integration-tenant/remember/state/route.ts b/apps/web/app/api/integration-tenant/remember/state/route.ts new file mode 100644 index 000000000..a0c6b021c --- /dev/null +++ b/apps/web/app/api/integration-tenant/remember/state/route.ts @@ -0,0 +1,23 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { getIntegrationTenantRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); + + const { searchParams } = new URL(req.url); + const { name } = searchParams as unknown as { name: string }; + + const response = await getIntegrationTenantRequest( + { + tenantId, + organizationId, + name: name as string + }, + access_token + ); + + return $res(response); +} diff --git a/apps/web/app/api/invite/[id]/route.ts b/apps/web/app/api/invite/[id]/route.ts new file mode 100644 index 000000000..14d462881 --- /dev/null +++ b/apps/web/app/api/invite/[id]/route.ts @@ -0,0 +1,75 @@ +/* eslint-disable no-case-declarations */ +import { MyInvitationActionEnum } from '@app/interfaces'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { + getTeamInvitationsRequest, + removeTeamInvitationsRequest, + getMyInvitationsRequest, + acceptRejectMyInvitationsRequest +} from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +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 NextResponse.json({}, { status: 401 }); + + if (params.id) { + return NextResponse.json({}, { status: 400 }); + } + + const { data: invitationData } = await getMyInvitationsRequest(tenantId, access_token); + return $res(invitationData); +} + +export async function DELETE(req: Request, { params }: { params: { id: string } }) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId, teamId } = await authenticatedGuard(req, res); + if (!user) return NextResponse.json({}, { status: 401 }); + + const invitationId = params.id; + + if (params.id) { + return NextResponse.json({}, { status: 400 }); + } + + await removeTeamInvitationsRequest({ + bearer_token: access_token, + tenantId: tenantId, + invitationId + }); + + const { data } = await getTeamInvitationsRequest( + { + tenantId, + teamId, + organizationId, + role: 'EMPLOYEE' + }, + access_token + ); + + return $res(data); +} + +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 NextResponse.json({}, { status: 401 }); + + const invitationId = params.id; + + const { searchParams } = new URL(req.url); + const { action } = searchParams as unknown as { action: string }; + + if (params.id) { + return NextResponse.json({}, { status: 400 }); + } + + if (!action) { + return NextResponse.json({}, { status: 400 }); + } + return $res( + await acceptRejectMyInvitationsRequest(tenantId, access_token, invitationId, action as MyInvitationActionEnum) + ); +} diff --git a/apps/web/app/api/invite/emails/route.ts b/apps/web/app/api/invite/emails/route.ts new file mode 100644 index 000000000..0afd5221b --- /dev/null +++ b/apps/web/app/api/invite/emails/route.ts @@ -0,0 +1,69 @@ +import { INVITE_CALLBACK_URL, INVITE_CALLBACK_PATH } from '@app/constants'; +import { validateForm } from '@app/helpers/validations'; +import { IInviteRequest } from '@app/interfaces/IInvite'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { + getEmployeeRoleRequest, + getTeamInvitationsRequest, + inviteByEmailsRequest +} from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const res = new NextResponse(); + const { $res, user, organizationId, access_token, teamId, tenantId } = await authenticatedGuard(req, res); + if (!user) return NextResponse.json({ errors: 'Unauthorized' }, { status: 401 }); + + const { origin } = new URL(req.url); + + const callbackUrl = `${origin}${INVITE_CALLBACK_PATH}`; + + const body = (await req.json()) as IInviteRequest; + + const { errors, isValid: formValid } = validateForm(['email', 'name'], body); + + if (!formValid) { + return NextResponse.json({ errors }, { status: 400 }); + } + + const { data: employeeRole } = await getEmployeeRoleRequest({ + tenantId, + role: 'EMPLOYEE', + bearer_token: access_token + }); + + const date = new Date(); + date.setDate(date.getDate() - 1); + + await inviteByEmailsRequest( + { + emailIds: [body.email], + projectIds: [], + departmentIds: [], + organizationContactIds: [], + teamIds: [teamId], + roleId: employeeRole?.id || '', + invitationExpirationPeriod: 'Never', + inviteType: 'TEAM', + appliedDate: null, + fullName: body.name, + callbackUrl: INVITE_CALLBACK_URL || callbackUrl, + organizationId, + tenantId, + startedWorkOn: date.toISOString() + }, + access_token + ); + + const { data } = await getTeamInvitationsRequest( + { + tenantId, + teamId, + organizationId, + role: 'EMPLOYEE' + }, + access_token + ); + + $res(data); +} diff --git a/apps/web/app/api/invite/resend/route.ts b/apps/web/app/api/invite/resend/route.ts new file mode 100644 index 000000000..38887c4d8 --- /dev/null +++ b/apps/web/app/api/invite/resend/route.ts @@ -0,0 +1,36 @@ +import { INVITE_CALLBACK_PATH, INVITE_CALLBACK_URL } from '@app/constants'; +import { validateForm } from '@app/helpers/validations'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { resendInvitationEmailRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + if (!user) return NextResponse.json({}, { status: 401 }); + + const url = new URL(req.url); + + const callbackUrl = `${url.origin}${INVITE_CALLBACK_PATH}`; + + const body = (await req.json()) as { inviteId: string }; + + const { errors, isValid: formValid } = validateForm(['inviteId'], body); + + if (!formValid) { + return NextResponse.json({ errors }, { status: 400 }); + } + + const { data } = await resendInvitationEmailRequest( + { + tenantId, + inviteId: body.inviteId, + inviteType: 'TEAM', + organizationId, + callbackUrl: INVITE_CALLBACK_URL || callbackUrl + }, + access_token + ); + + $res(data); +} diff --git a/apps/web/app/api/invite/route.ts b/apps/web/app/api/invite/route.ts new file mode 100644 index 000000000..7ffec62c9 --- /dev/null +++ b/apps/web/app/api/invite/route.ts @@ -0,0 +1,21 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { getTeamInvitationsRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId, teamId } = await authenticatedGuard(req, res); + if (!user) return NextResponse.json({ error: 'Unauthorized' }); + + const { data } = await getTeamInvitationsRequest( + { + tenantId, + teamId, + organizationId, + role: 'EMPLOYEE' + }, + access_token + ); + + $res(data); +} diff --git a/apps/web/app/api/invite/validate-by-code/route.ts b/apps/web/app/api/invite/validate-by-code/route.ts new file mode 100644 index 000000000..5338481c2 --- /dev/null +++ b/apps/web/app/api/invite/validate-by-code/route.ts @@ -0,0 +1,19 @@ +import { validateForm } from '@app/helpers/validations'; +import { IInviteVerifyCode } from '@app/interfaces/IInvite'; +import { verifyInviteCodeRequest } from '@app/services/server/requests'; + +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const body = (await req.json()) as IInviteVerifyCode; + + const { errors, isValid: formValid } = validateForm(['code', 'email'], body as any); + + if (!formValid) { + return NextResponse.json({ errors }, { status: 400 }); + } + + const { data } = await verifyInviteCodeRequest(body); + + NextResponse.json(data, { status: 200 }); +} diff --git a/apps/web/app/api/organization-projects/[id]/route.ts b/apps/web/app/api/organization-projects/[id]/route.ts new file mode 100644 index 000000000..88a982d9c --- /dev/null +++ b/apps/web/app/api/organization-projects/[id]/route.ts @@ -0,0 +1,22 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; + +import { editOrganizationProjectsRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +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 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 + }) + ); +} diff --git a/apps/web/app/api/organization-projects/setting/[id]/route.ts b/apps/web/app/api/organization-projects/setting/[id]/route.ts new file mode 100644 index 000000000..93c6816d2 --- /dev/null +++ b/apps/web/app/api/organization-projects/setting/[id]/route.ts @@ -0,0 +1,24 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; + +import { editOrganizationProjectsSettingsRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +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 NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); + + 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 + }) + ); + } +} diff --git a/apps/web/pages/api/invite/[id].ts b/apps/web/pages/api/_moved/invite/[id].ts similarity index 100% rename from apps/web/pages/api/invite/[id].ts rename to apps/web/pages/api/_moved/invite/[id].ts diff --git a/apps/web/pages/api/invite/emails.ts b/apps/web/pages/api/_moved/invite/emails.ts similarity index 100% rename from apps/web/pages/api/invite/emails.ts rename to apps/web/pages/api/_moved/invite/emails.ts diff --git a/apps/web/pages/api/invite/index.ts b/apps/web/pages/api/_moved/invite/index.ts similarity index 100% rename from apps/web/pages/api/invite/index.ts rename to apps/web/pages/api/_moved/invite/index.ts diff --git a/apps/web/pages/api/invite/resend.ts b/apps/web/pages/api/_moved/invite/resend.ts similarity index 100% rename from apps/web/pages/api/invite/resend.ts rename to apps/web/pages/api/_moved/invite/resend.ts diff --git a/apps/web/pages/api/invite/validate-by-code.ts b/apps/web/pages/api/_moved/invite/validate-by-code.ts similarity index 100% rename from apps/web/pages/api/invite/validate-by-code.ts rename to apps/web/pages/api/_moved/invite/validate-by-code.ts diff --git a/apps/web/pages/api/organization-projects/[id].ts b/apps/web/pages/api/_moved/organization-projects/[id].ts similarity index 100% rename from apps/web/pages/api/organization-projects/[id].ts rename to apps/web/pages/api/_moved/organization-projects/[id].ts diff --git a/apps/web/pages/api/organization-projects/setting/[id].ts b/apps/web/pages/api/_moved/organization-projects/setting/[id].ts similarity index 100% rename from apps/web/pages/api/organization-projects/setting/[id].ts rename to apps/web/pages/api/_moved/organization-projects/setting/[id].ts From 32100e0e1c7b03611aa8a12cc987e5a639dfc2d9 Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Sun, 7 Jan 2024 16:19:15 +0200 Subject: [PATCH 18/22] feat: move integration routes to /app --- .../api/integration/github/install/route.ts | 23 ++++ .../api/integration/github/metadata/route.ts | 24 ++++ .../app/api/integration/github/oauth/route.ts | 24 ++++ .../integration/github/repositories/route.ts | 24 ++++ .../github/repository/sync/route.ts | 22 ++++ apps/web/app/api/integration/types/route.ts | 18 +++ .../app/api/organization-team/[id]/route.ts | 71 ++++++++++++ .../organization-team/employee/[id]/route.ts | 52 +++++++++ apps/web/app/api/organization-team/route.ts | 103 ++++++++++++++++++ .../api/organization-team/teams/[id]/route.ts | 20 ++++ .../{ => _moved}/integration-tenant/[id].ts | 0 .../remember/state/index.ts | 0 .../integration/github/install.ts | 0 .../integration/github/metadata.ts | 0 .../{ => _moved}/integration/github/oauth.ts | 0 .../integration/github/repositories.ts | 0 .../integration/github/repository/sync.ts | 0 .../{ => _moved}/integration/types/index.ts | 0 .../{ => _moved}/organization-team/[id].ts | 0 .../organization-team/employee/[id].ts | 0 .../{ => _moved}/organization-team/index.ts | 0 .../organization-team/teams/[id].ts | 0 22 files changed, 381 insertions(+) create mode 100644 apps/web/app/api/integration/github/install/route.ts create mode 100644 apps/web/app/api/integration/github/metadata/route.ts create mode 100644 apps/web/app/api/integration/github/oauth/route.ts create mode 100644 apps/web/app/api/integration/github/repositories/route.ts create mode 100644 apps/web/app/api/integration/github/repository/sync/route.ts create mode 100644 apps/web/app/api/integration/types/route.ts create mode 100644 apps/web/app/api/organization-team/[id]/route.ts create mode 100644 apps/web/app/api/organization-team/employee/[id]/route.ts create mode 100644 apps/web/app/api/organization-team/route.ts create mode 100644 apps/web/app/api/organization-team/teams/[id]/route.ts rename apps/web/pages/api/{ => _moved}/integration-tenant/[id].ts (100%) rename apps/web/pages/api/{ => _moved}/integration-tenant/remember/state/index.ts (100%) rename apps/web/pages/api/{ => _moved}/integration/github/install.ts (100%) rename apps/web/pages/api/{ => _moved}/integration/github/metadata.ts (100%) rename apps/web/pages/api/{ => _moved}/integration/github/oauth.ts (100%) rename apps/web/pages/api/{ => _moved}/integration/github/repositories.ts (100%) rename apps/web/pages/api/{ => _moved}/integration/github/repository/sync.ts (100%) rename apps/web/pages/api/{ => _moved}/integration/types/index.ts (100%) rename apps/web/pages/api/{ => _moved}/organization-team/[id].ts (100%) rename apps/web/pages/api/{ => _moved}/organization-team/employee/[id].ts (100%) rename apps/web/pages/api/{ => _moved}/organization-team/index.ts (100%) rename apps/web/pages/api/{ => _moved}/organization-team/teams/[id].ts (100%) diff --git a/apps/web/app/api/integration/github/install/route.ts b/apps/web/app/api/integration/github/install/route.ts new file mode 100644 index 000000000..c6270ae1e --- /dev/null +++ b/apps/web/app/api/integration/github/install/route.ts @@ -0,0 +1,23 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { installGitHubIntegration } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + if (!user) return NextResponse.json({}, { status: 401 }); + + const { installation_id, setup_action } = await req.json(); + + const response = await installGitHubIntegration( + { + tenantId, + organizationId, + installation_id, + setup_action + }, + access_token + ); + + return $res(response); +} diff --git a/apps/web/app/api/integration/github/metadata/route.ts b/apps/web/app/api/integration/github/metadata/route.ts new file mode 100644 index 000000000..c136907a1 --- /dev/null +++ b/apps/web/app/api/integration/github/metadata/route.ts @@ -0,0 +1,24 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { getGithubIntegrationMetadataRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + if (!user) return NextResponse.json({}, { status: 401 }); + + const { searchParams } = new URL(req.url); + + const { integrationId } = searchParams as unknown as { integrationId: string }; + + const response = await getGithubIntegrationMetadataRequest( + { + tenantId, + organizationId, + integrationId: integrationId as string + }, + access_token + ); + + return $res(response); +} diff --git a/apps/web/app/api/integration/github/oauth/route.ts b/apps/web/app/api/integration/github/oauth/route.ts new file mode 100644 index 000000000..c6e543aa1 --- /dev/null +++ b/apps/web/app/api/integration/github/oauth/route.ts @@ -0,0 +1,24 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { oAuthEndpointAuthorization } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + if (!user) return NextResponse.json({}, { status: 401 }); + + const { installation_id, setup_action, code } = await req.json(); + + const response = await oAuthEndpointAuthorization( + { + tenantId, + organizationId, + installation_id, + setup_action, + code + }, + access_token + ); + + return $res(response); +} diff --git a/apps/web/app/api/integration/github/repositories/route.ts b/apps/web/app/api/integration/github/repositories/route.ts new file mode 100644 index 000000000..6e9628caa --- /dev/null +++ b/apps/web/app/api/integration/github/repositories/route.ts @@ -0,0 +1,24 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { getGithubIntegrationRepositoriesRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + if (!user) return NextResponse.json({}, { status: 401 }); + + const { searchParams } = new URL(req.url); + + const { integrationId } = searchParams as unknown as { integrationId: string }; + + const response = await getGithubIntegrationRepositoriesRequest( + { + tenantId, + organizationId, + integrationId: integrationId as string + }, + access_token + ); + + return $res(response); +} diff --git a/apps/web/app/api/integration/github/repository/sync/route.ts b/apps/web/app/api/integration/github/repository/sync/route.ts new file mode 100644 index 000000000..25735cd72 --- /dev/null +++ b/apps/web/app/api/integration/github/repository/sync/route.ts @@ -0,0 +1,22 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { projectRepositorySyncRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + if (!user) return NextResponse.json({}, { status: 401 }); + + const body = await req.json(); + + const response = await projectRepositorySyncRequest( + { + ...body, + tenantId, + organizationId + }, + access_token + ); + + return $res(response); +} diff --git a/apps/web/app/api/integration/types/route.ts b/apps/web/app/api/integration/types/route.ts new file mode 100644 index 000000000..dc7e8b44f --- /dev/null +++ b/apps/web/app/api/integration/types/route.ts @@ -0,0 +1,18 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { getIntegrationTypesRequest } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + if (!user) return NextResponse.json({}, { status: 401 }); + + const response = await getIntegrationTypesRequest( + { + tenantId + }, + access_token + ); + + return $res(response); +} diff --git a/apps/web/app/api/organization-team/[id]/route.ts b/apps/web/app/api/organization-team/[id]/route.ts new file mode 100644 index 000000000..e5991bf80 --- /dev/null +++ b/apps/web/app/api/organization-team/[id]/route.ts @@ -0,0 +1,71 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; + +import { + deleteOrganizationTeamRequest, + getOrganizationTeamRequest, + updateOrganizationTeamRequest +} from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user, organizationId, access_token, tenantId, teamId } = await authenticatedGuard(req, res); + if (!user) return NextResponse.json({}, { status: 400 }); + + const getTeamStatus = async () => { + const { data: team } = await getOrganizationTeamRequest( + { + organizationId, + tenantId, + teamId: teamId + }, + access_token + ); + + return team; + }; + + return $res(await getTeamStatus()); +} + +export async function PUT(req: Request) { + const res = new NextResponse(); + const { $res, user, organizationId, access_token, tenantId, teamId } = await authenticatedGuard(req, res); + if (!user) return NextResponse.json({}, { status: 400 }); + + const body = await req.json(); + const getTeamStatus = async () => { + const { data: team } = await getOrganizationTeamRequest( + { + organizationId, + tenantId, + teamId: teamId + }, + access_token + ); + + return team; + }; + + await updateOrganizationTeamRequest(body, access_token); + return $res(await getTeamStatus()); +} + +export async function DELETE(req: Request, { params }: { params: { id: string } }) { + const res = new NextResponse(); + const { $res, user, organizationId, access_token, tenantId } = await authenticatedGuard(req, res); + if (!user) return NextResponse.json({}, { status: 400 }); + + const { id } = params; + + if (id) { + return $res( + await deleteOrganizationTeamRequest({ + id: id as string, + bearer_token: access_token, + tenantId, + organizationId + }) + ); + } +} diff --git a/apps/web/app/api/organization-team/employee/[id]/route.ts b/apps/web/app/api/organization-team/employee/[id]/route.ts new file mode 100644 index 000000000..951673599 --- /dev/null +++ b/apps/web/app/api/organization-team/employee/[id]/route.ts @@ -0,0 +1,52 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { + addEmployeeOrganizationTeamOrderRequest, + removeEmployeeOrganizationTeamRequest +} from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +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({}, { status: 401 }); + + const { id } = params; + + if (!id) { + return NextResponse.json({}, { status: 405 }); + } + + return $res( + await removeEmployeeOrganizationTeamRequest({ + bearer_token: access_token, + tenantId, + employeeId: id.toString() + }) + ); +} + +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 NextResponse.json({}, { status: 401 }); + + const body = await req.json(); + + const { id } = params; + const order = body.order; + + if (!id) { + return NextResponse.json({}, { status: 405 }); + } + + return $res( + await addEmployeeOrganizationTeamOrderRequest({ + bearer_token: access_token, + tenantId, + employeeId: id.toString(), + order, + organizationTeamId: body.organizationTeamId, + organizationId: body.organizationId + }) + ); +} diff --git a/apps/web/app/api/organization-team/route.ts b/apps/web/app/api/organization-team/route.ts new file mode 100644 index 000000000..047fb5e90 --- /dev/null +++ b/apps/web/app/api/organization-team/route.ts @@ -0,0 +1,103 @@ +import { IUserOrganization } from '@app/interfaces/IOrganization'; +import { IOrganizationTeamList } from '@app/interfaces/IOrganizationTeam'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; +import { + createOrganizationTeamRequest, + getAllOrganizationTeamRequest, + getUserOrganizationsRequest +} from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); + + if (!user) return NextResponse.json({}, { status: 401 }); + + if (req.method === 'POST') { + const body = req.body as { name?: string }; + const $name = body.name?.trim() || ''; + if ($name.trim().length < 2) { + return NextResponse.json({ errors: { name: 'Invalid team name !' } }, { status: 400 }); + } + await createOrganizationTeamRequest( + { + name: $name, + tenantId, + organizationId, + managerIds: user?.employee?.id ? [user.employee.id] : [], + public: true // By default team should be public + }, + access_token + ); + } + + const { data: organizations } = await getUserOrganizationsRequest({ tenantId, userId: user.id }, access_token); + + const organizationsItems = organizations.items; + + const filteredOrganization = organizationsItems.reduce((acc, org) => { + if (!acc.find((o) => o.organizationId === org.organizationId)) { + acc.push(org); + } + return acc; + }, [] as IUserOrganization[]); + + const call_teams = filteredOrganization.map((item) => { + return getAllOrganizationTeamRequest({ tenantId, organizationId: item.organizationId }, access_token); + }); + + const teams = await Promise.all(call_teams).then((tms) => { + return tms.reduce( + (acc, { data }) => { + if (data && data.items) { + acc.items.push(...data.items); + acc.total += data.total; + } + + return acc; + }, + { items: [] as IOrganizationTeamList[], total: 0 } + ); + }); + + return $res(teams); +} + +export async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return NextResponse.json({}, { status: 401 }); + + const { data: organizations } = await getUserOrganizationsRequest({ tenantId, userId: user.id }, access_token); + + const organizationsItems = organizations.items; + + const filteredOrganization = organizationsItems.reduce((acc, org) => { + if (!acc.find((o) => o.organizationId === org.organizationId)) { + acc.push(org); + } + return acc; + }, [] as IUserOrganization[]); + + const call_teams = filteredOrganization.map((item) => { + return getAllOrganizationTeamRequest({ tenantId, organizationId: item.organizationId }, access_token); + }); + + const teams = await Promise.all(call_teams).then((tms) => { + return tms.reduce( + (acc, { data }) => { + if (data && data.items) { + acc.items.push(...data.items); + acc.total += data.total; + } + + return acc; + }, + { items: [] as IOrganizationTeamList[], total: 0 } + ); + }); + + return $res(teams); +} diff --git a/apps/web/app/api/organization-team/teams/[id]/route.ts b/apps/web/app/api/organization-team/teams/[id]/route.ts new file mode 100644 index 000000000..95e84bbc4 --- /dev/null +++ b/apps/web/app/api/organization-team/teams/[id]/route.ts @@ -0,0 +1,20 @@ +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; + +import { removeUserFromAllTeam } from '@app/services/server/requests'; +import { NextResponse } from 'next/server'; + +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({}, { status: 401 }); + + const { id } = params; + if (!id) return NextResponse.json({}, { status: 400 }); + return $res( + await removeUserFromAllTeam({ + userId: id as string, + bearer_token: access_token, + tenantId + }) + ); +} diff --git a/apps/web/pages/api/integration-tenant/[id].ts b/apps/web/pages/api/_moved/integration-tenant/[id].ts similarity index 100% rename from apps/web/pages/api/integration-tenant/[id].ts rename to apps/web/pages/api/_moved/integration-tenant/[id].ts diff --git a/apps/web/pages/api/integration-tenant/remember/state/index.ts b/apps/web/pages/api/_moved/integration-tenant/remember/state/index.ts similarity index 100% rename from apps/web/pages/api/integration-tenant/remember/state/index.ts rename to apps/web/pages/api/_moved/integration-tenant/remember/state/index.ts diff --git a/apps/web/pages/api/integration/github/install.ts b/apps/web/pages/api/_moved/integration/github/install.ts similarity index 100% rename from apps/web/pages/api/integration/github/install.ts rename to apps/web/pages/api/_moved/integration/github/install.ts diff --git a/apps/web/pages/api/integration/github/metadata.ts b/apps/web/pages/api/_moved/integration/github/metadata.ts similarity index 100% rename from apps/web/pages/api/integration/github/metadata.ts rename to apps/web/pages/api/_moved/integration/github/metadata.ts diff --git a/apps/web/pages/api/integration/github/oauth.ts b/apps/web/pages/api/_moved/integration/github/oauth.ts similarity index 100% rename from apps/web/pages/api/integration/github/oauth.ts rename to apps/web/pages/api/_moved/integration/github/oauth.ts diff --git a/apps/web/pages/api/integration/github/repositories.ts b/apps/web/pages/api/_moved/integration/github/repositories.ts similarity index 100% rename from apps/web/pages/api/integration/github/repositories.ts rename to apps/web/pages/api/_moved/integration/github/repositories.ts diff --git a/apps/web/pages/api/integration/github/repository/sync.ts b/apps/web/pages/api/_moved/integration/github/repository/sync.ts similarity index 100% rename from apps/web/pages/api/integration/github/repository/sync.ts rename to apps/web/pages/api/_moved/integration/github/repository/sync.ts diff --git a/apps/web/pages/api/integration/types/index.ts b/apps/web/pages/api/_moved/integration/types/index.ts similarity index 100% rename from apps/web/pages/api/integration/types/index.ts rename to apps/web/pages/api/_moved/integration/types/index.ts diff --git a/apps/web/pages/api/organization-team/[id].ts b/apps/web/pages/api/_moved/organization-team/[id].ts similarity index 100% rename from apps/web/pages/api/organization-team/[id].ts rename to apps/web/pages/api/_moved/organization-team/[id].ts diff --git a/apps/web/pages/api/organization-team/employee/[id].ts b/apps/web/pages/api/_moved/organization-team/employee/[id].ts similarity index 100% rename from apps/web/pages/api/organization-team/employee/[id].ts rename to apps/web/pages/api/_moved/organization-team/employee/[id].ts diff --git a/apps/web/pages/api/organization-team/index.ts b/apps/web/pages/api/_moved/organization-team/index.ts similarity index 100% rename from apps/web/pages/api/organization-team/index.ts rename to apps/web/pages/api/_moved/organization-team/index.ts diff --git a/apps/web/pages/api/organization-team/teams/[id].ts b/apps/web/pages/api/_moved/organization-team/teams/[id].ts similarity index 100% rename from apps/web/pages/api/organization-team/teams/[id].ts rename to apps/web/pages/api/_moved/organization-team/teams/[id].ts From 1d18dfe2617cd663a167a8114b43b48377c7b79b Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Sun, 7 Jan 2024 16:35:15 +0200 Subject: [PATCH 19/22] fix: deepscan errors --- apps/web/app/api/tags/route.ts | 4 +- .../pages/api/_moved/auth/signin-workspace.ts | 168 ------------------ 2 files changed, 2 insertions(+), 170 deletions(-) delete mode 100644 apps/web/pages/api/_moved/auth/signin-workspace.ts diff --git a/apps/web/app/api/tags/route.ts b/apps/web/app/api/tags/route.ts index ca58d9480..c86ebf135 100644 --- a/apps/web/app/api/tags/route.ts +++ b/apps/web/app/api/tags/route.ts @@ -9,7 +9,7 @@ export async function GET(req: Request) { const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return NextResponse.json({ error: 'unathorized' }, { status: 401 }); + if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); const { organizationTeamId } = searchParams as unknown as { organizationTeamId: string }; @@ -28,7 +28,7 @@ export async function POST(req: Request) { const { $res, user, access_token } = await authenticatedGuard(req, res); - if (!user) return NextResponse.json({ error: 'unathorized' }, { status: 401 }); + if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); return $res(await createLabelsRequest(body, access_token, body?.tenantId)); } diff --git a/apps/web/pages/api/_moved/auth/signin-workspace.ts b/apps/web/pages/api/_moved/auth/signin-workspace.ts deleted file mode 100644 index 25dbdd672..000000000 --- a/apps/web/pages/api/_moved/auth/signin-workspace.ts +++ /dev/null @@ -1,168 +0,0 @@ -import { authFormValidate } from '@app/helpers/validations'; -import { NextApiRequest, NextApiResponse } from 'next'; -import { - acceptInviteRequest, - getAllOrganizationTeamRequest, - getUserOrganizationsRequest, - signInWorkspaceRequest, - verifyInviteCodeRequest -} from '@app/services/server/requests'; -import { generateToken, setAuthCookies, setNoTeamPopupShowCookie } from '@app/helpers'; -import { ILoginResponse } from '@app/interfaces'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - if (req.method !== 'POST') { - return res.status(405).json({ status: 'fail' }); - } - - const body = req.body as { - email: string; - token: string; - teamId: string; - code: string; - }; - let loginResponse: ILoginResponse | null = null; - - const { errors, valid: formValid } = authFormValidate(['email'], body as any); - - if (!formValid) { - return res.status(400).json({ errors }); - } - - // Accept Invite Flow Start - /** - * Verify first if match with invite code - */ - const inviteReq = await verifyInviteCodeRequest({ - email: body.email, - code: body.code - }).catch(() => void 0); - - // General a random password with 8 chars - if (inviteReq && inviteReq.data.fullName) { - const password = generateToken(8); - - const names = inviteReq.data.fullName.split(' '); - const acceptInviteRes = await acceptInviteRequest({ - code: body.code, - email: body.email, - password: password, - user: { - firstName: names[0], - lastName: names[1] || '', - email: body.email - } - }).catch(() => void 0); - - if ( - !acceptInviteRes || - !acceptInviteRes.response.ok || - acceptInviteRes.response.status === 401 || - acceptInviteRes.response.status === 400 || - (acceptInviteRes.data as any).response?.statusCode - ) { - return res.status(400).json({ - errors: { - email: 'Authentication code or email address invalid' - } - }); - } - loginResponse = acceptInviteRes.data; - - if (!loginResponse) { - return res.status(400).json({ - errors: { - email: 'Authentication code or email address invalid' - } - }); - } - } - if (loginResponse) { - console.log('loginResponse>>>', loginResponse); - - /** - * Get the first team from first organization - */ - const tenantId = loginResponse.user?.tenantId || ''; - const access_token = loginResponse.token; - const userId = loginResponse.user?.id; - - const { data: organizations } = await getUserOrganizationsRequest({ tenantId, userId }, access_token); - const organization = organizations?.items[0]; - - if (!organization) { - return res.status(400).json({ - errors: { - email: 'Your account is not yet ready to be used on the Ever Teams Platform' - } - }); - } - const { data: teams } = await getAllOrganizationTeamRequest( - { tenantId, organizationId: organization.organizationId }, - access_token - ); - - const team = teams.items[0]; - if (!team) { - setNoTeamPopupShowCookie(true); - } - setAuthCookies( - { - access_token: loginResponse.token, - refresh_token: { - token: loginResponse.refresh_token - }, - teamId: team?.id, - tenantId, - organizationId: organization?.organizationId, - languageId: 'en', // TODO: not sure what should be here - noTeamPopup: true, - userId - }, - req, - res - ); - return res.status(200).json({ team, loginResponse }); - } - // Accept Invite Flow End - - const { data } = await signInWorkspaceRequest(body.email, body.token); - - /** - * Get the first team from first organization - */ - const tenantId = data.user?.tenantId || ''; - const access_token = data.token; - const userId = data.user?.id; - - const { data: organizations } = await getUserOrganizationsRequest({ tenantId, userId }, access_token); - - const organization = organizations?.items[0]; - - if (!organization) { - return res.status(400).json({ - errors: { - email: 'Your account is not yet ready to be used on the Ever Teams Platform' - } - }); - } - - setAuthCookies( - { - access_token: data.token, - refresh_token: { - token: data.refresh_token - }, - teamId: body.teamId, - tenantId, - organizationId: organization?.organizationId, - languageId: 'en', // TODO: not sure what should be here - noTeamPopup: true, - userId - }, - req, - res - ); - - res.status(200).json({ loginResponse: data }); -} From 3161e43d4c70917d307f5e5cebb7bb1b96425a6e Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Sun, 7 Jan 2024 16:43:55 +0200 Subject: [PATCH 20/22] fix: deepscan errors --- .../app/api/auth/_signin-workspace/route.ts | 2 +- .../api/auth/signin-email-confirm/route.ts | 2 +- apps/web/pages/api/_moved/auth/register.ts | 19 ++++++++----------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/apps/web/app/api/auth/_signin-workspace/route.ts b/apps/web/app/api/auth/_signin-workspace/route.ts index 69a7f7954..5a4eafb5f 100644 --- a/apps/web/app/api/auth/_signin-workspace/route.ts +++ b/apps/web/app/api/auth/_signin-workspace/route.ts @@ -58,7 +58,7 @@ export async function POST(req: Request) { !acceptInviteRes.response.ok || acceptInviteRes.response.status === 401 || acceptInviteRes.response.status === 400 || - (acceptInviteRes.data as any).response?.statusCode + (acceptInviteRes?.data as any).response.statusCode ) { return NextResponse.json( { diff --git a/apps/web/app/api/auth/signin-email-confirm/route.ts b/apps/web/app/api/auth/signin-email-confirm/route.ts index 579d701d4..c7ed9cba7 100644 --- a/apps/web/app/api/auth/signin-email-confirm/route.ts +++ b/apps/web/app/api/auth/signin-email-confirm/route.ts @@ -53,7 +53,7 @@ export async function POST(req: Request) { !acceptInviteRes.response.ok || acceptInviteRes.response.status === 401 || acceptInviteRes.response.status === 400 || - (acceptInviteRes.data as any).response?.statusCode + (acceptInviteRes?.data as any).response?.statusCode ) { return NextResponse.json({ errors: { diff --git a/apps/web/pages/api/_moved/auth/register.ts b/apps/web/pages/api/_moved/auth/register.ts index 55b40f051..97efa9c27 100644 --- a/apps/web/pages/api/_moved/auth/register.ts +++ b/apps/web/pages/api/_moved/auth/register.ts @@ -27,28 +27,25 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const noRecaptchaArray = ['email', 'name', 'team']; - const withRecaptchaArray = [...noRecaptchaArray, "recaptcha"]; + const withRecaptchaArray = [...noRecaptchaArray, 'recaptcha']; - const validationFields = RECAPTCHA_SECRET_KEY ? withRecaptchaArray : noRecaptchaArray + const validationFields = RECAPTCHA_SECRET_KEY ? withRecaptchaArray : noRecaptchaArray; - const { errors, valid: formValid } = authFormValidate( - validationFields, - body - ); + const { errors, valid: formValid } = authFormValidate(validationFields, body); if (!formValid) { return res.status(400).json({ errors }); } - if(RECAPTCHA_SECRET_KEY) { + if (RECAPTCHA_SECRET_KEY) { const { success } = await recaptchaVerification({ - secret: RECAPTCHA_SECRET_KEY || '', + secret: RECAPTCHA_SECRET_KEY, response: body.recaptcha ? body.recaptcha : '' }); - if (!success) { - return res.status(400).json({ errors: { recaptcha: 'Invalid reCAPTCHA. Please try again' } }); - } + if (!success) { + return res.status(400).json({ errors: { recaptcha: 'Invalid reCAPTCHA. Please try again' } }); + } } /** * Verify if the SMTP has been configured From 51531de149597fa42efcc7150afdfecb0fe4c86f Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Sun, 7 Jan 2024 16:46:47 +0200 Subject: [PATCH 21/22] fix: deepscan errors --- apps/web/app/api/auth/register/route.ts | 2 +- apps/web/pages/api/_moved/auth/signin-email-confirm.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/web/app/api/auth/register/route.ts b/apps/web/app/api/auth/register/route.ts index e8de8e086..ad0efada8 100644 --- a/apps/web/app/api/auth/register/route.ts +++ b/apps/web/app/api/auth/register/route.ts @@ -38,7 +38,7 @@ export async function POST(req: Request) { if (RECAPTCHA_SECRET_KEY) { const { success } = await recaptchaVerification({ - secret: RECAPTCHA_SECRET_KEY || '', + secret: RECAPTCHA_SECRET_KEY, response: body.recaptcha ? body.recaptcha : '' }); diff --git a/apps/web/pages/api/_moved/auth/signin-email-confirm.ts b/apps/web/pages/api/_moved/auth/signin-email-confirm.ts index 49cd61cb9..b5f01fdf1 100644 --- a/apps/web/pages/api/_moved/auth/signin-email-confirm.ts +++ b/apps/web/pages/api/_moved/auth/signin-email-confirm.ts @@ -55,7 +55,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) !acceptInviteRes.response.ok || acceptInviteRes.response.status === 401 || acceptInviteRes.response.status === 400 || - (acceptInviteRes.data as any).response?.statusCode + (acceptInviteRes?.data as any).response?.statusCode ) { return res.status(400).json({ errors: { From d083f6a6edbbe16e9aa2a179fd6361636b5343cf Mon Sep 17 00:00:00 2001 From: cedric karungu Date: Sun, 7 Jan 2024 17:31:48 +0200 Subject: [PATCH 22/22] fix: delete unused files --- apps/web/app/api/auth/signin-email/route.ts | 2 +- apps/web/pages/api/_moved/auth/login.ts | 152 ------------------ apps/web/pages/api/_moved/auth/meet/jwt.ts | 77 --------- apps/web/pages/api/_moved/auth/refresh.ts | 34 ---- apps/web/pages/api/_moved/auth/register.ts | 146 ----------------- apps/web/pages/api/_moved/auth/send-code.ts | 32 ---- .../api/_moved/auth/signin-email-confirm.ts | 131 --------------- .../web/pages/api/_moved/auth/signin-email.ts | 32 ---- apps/web/pages/api/_moved/auth/verify/code.ts | 31 ---- .../api/_moved/auth/verify/resend-link.ts | 25 --- .../web/pages/api/_moved/auth/verify/token.ts | 24 --- .../email-reset/request-change-email.ts | 22 --- .../_moved/email-reset/verify-change-email.ts | 22 --- apps/web/pages/api/_moved/employee/working.ts | 12 -- .../api/_moved/integration-tenant/[id].ts | 20 --- .../remember/state/index.ts | 25 --- .../api/_moved/integration/github/install.ts | 26 --- .../api/_moved/integration/github/metadata.ts | 25 --- .../api/_moved/integration/github/oauth.ts | 27 ---- .../_moved/integration/github/repositories.ts | 25 --- .../integration/github/repository/sync.ts | 23 --- .../api/_moved/integration/types/index.ts | 21 --- apps/web/pages/api/_moved/invite/[id].ts | 59 ------- apps/web/pages/api/_moved/invite/emails.ts | 66 -------- apps/web/pages/api/_moved/invite/index.ts | 20 --- apps/web/pages/api/_moved/invite/resend.ts | 33 ---- .../api/_moved/invite/validate-by-code.ts | 19 --- apps/web/pages/api/_moved/issue-types/[id].ts | 32 ---- .../pages/api/_moved/issue-types/index.tsx | 24 --- apps/web/pages/api/_moved/languages/index.ts | 19 --- .../api/_moved/organization-projects/[id].ts | 22 --- .../organization-projects/setting/[id].ts | 22 --- .../[id]/active-task.ts | 25 --- .../organization-team-employee/[id]/index.tsx | 43 ----- .../organization-team-join/[id]/[action].ts | 26 --- .../_moved/organization-team-join/index.ts | 24 --- .../organization-team-join/resend-code.ts | 12 -- .../_moved/organization-team-join/validate.ts | 12 -- .../api/_moved/organization-team/[id].ts | 48 ------ .../_moved/organization-team/employee/[id].ts | 41 ----- .../api/_moved/organization-team/index.ts | 64 -------- .../_moved/organization-team/teams/[id].ts | 23 --- .../public/team/[profileLink]/[teamId].ts | 31 ---- .../pages/api/_moved/role-permissions/[id].ts | 39 ----- apps/web/pages/api/_moved/roles/[id].ts | 35 ---- apps/web/pages/api/_moved/roles/index.ts | 34 ---- apps/web/pages/api/_moved/tags/[id].ts | 31 ---- apps/web/pages/api/_moved/tags/index.tsx | 24 --- apps/web/pages/api/_moved/tags/level.ts | 22 --- .../pages/api/_moved/task-priorities/[id].ts | 31 ---- .../api/_moved/task-priorities/index.tsx | 24 --- .../_moved/task-related-issue-types/[id].ts | 34 ---- .../_moved/task-related-issue-types/index.ts | 27 ---- apps/web/pages/api/_moved/task-sizes/[id].ts | 32 ---- .../web/pages/api/_moved/task-sizes/index.tsx | 24 --- .../pages/api/_moved/task-statuses/[id].ts | 31 ---- .../pages/api/_moved/task-statuses/index.tsx | 24 --- .../pages/api/_moved/task-versions/[id].ts | 31 ---- .../pages/api/_moved/task-versions/index.tsx | 24 --- apps/web/pages/api/_moved/tasks/[id].ts | 47 ------ .../api/_moved/tasks/employee/[employeeId].ts | 26 --- .../api/_moved/tasks/task-linked-issue.ts | 26 --- apps/web/pages/api/_moved/tasks/team.ts | 50 ------ apps/web/pages/api/_moved/timer/start.ts | 34 ---- apps/web/pages/api/_moved/timer/status.ts | 12 -- apps/web/pages/api/_moved/timer/stop.ts | 31 ---- apps/web/pages/api/_moved/timer/sync.ts | 30 ---- .../timer/timesheet/all-statistics-tasks.ts | 20 --- .../pages/api/_moved/timer/timesheet/index.ts | 7 - .../timer/timesheet/statistics-tasks.ts | 47 ------ apps/web/pages/api/_moved/timer/toggle.ts | 42 ----- apps/web/pages/api/_moved/user/[id].ts | 41 ----- apps/web/pages/api/_moved/user/me.ts | 9 -- apps/web/pages/api/_moved/user/reset.ts | 19 --- apps/web/pages/api/auth/signin-workspace.ts | 2 +- 75 files changed, 2 insertions(+), 2507 deletions(-) delete mode 100644 apps/web/pages/api/_moved/auth/login.ts delete mode 100644 apps/web/pages/api/_moved/auth/meet/jwt.ts delete mode 100644 apps/web/pages/api/_moved/auth/refresh.ts delete mode 100644 apps/web/pages/api/_moved/auth/register.ts delete mode 100644 apps/web/pages/api/_moved/auth/send-code.ts delete mode 100644 apps/web/pages/api/_moved/auth/signin-email-confirm.ts delete mode 100644 apps/web/pages/api/_moved/auth/signin-email.ts delete mode 100644 apps/web/pages/api/_moved/auth/verify/code.ts delete mode 100644 apps/web/pages/api/_moved/auth/verify/resend-link.ts delete mode 100644 apps/web/pages/api/_moved/auth/verify/token.ts delete mode 100644 apps/web/pages/api/_moved/email-reset/request-change-email.ts delete mode 100644 apps/web/pages/api/_moved/email-reset/verify-change-email.ts delete mode 100644 apps/web/pages/api/_moved/employee/working.ts delete mode 100644 apps/web/pages/api/_moved/integration-tenant/[id].ts delete mode 100644 apps/web/pages/api/_moved/integration-tenant/remember/state/index.ts delete mode 100644 apps/web/pages/api/_moved/integration/github/install.ts delete mode 100644 apps/web/pages/api/_moved/integration/github/metadata.ts delete mode 100644 apps/web/pages/api/_moved/integration/github/oauth.ts delete mode 100644 apps/web/pages/api/_moved/integration/github/repositories.ts delete mode 100644 apps/web/pages/api/_moved/integration/github/repository/sync.ts delete mode 100644 apps/web/pages/api/_moved/integration/types/index.ts delete mode 100644 apps/web/pages/api/_moved/invite/[id].ts delete mode 100644 apps/web/pages/api/_moved/invite/emails.ts delete mode 100644 apps/web/pages/api/_moved/invite/index.ts delete mode 100644 apps/web/pages/api/_moved/invite/resend.ts delete mode 100644 apps/web/pages/api/_moved/invite/validate-by-code.ts delete mode 100644 apps/web/pages/api/_moved/issue-types/[id].ts delete mode 100644 apps/web/pages/api/_moved/issue-types/index.tsx delete mode 100644 apps/web/pages/api/_moved/languages/index.ts delete mode 100644 apps/web/pages/api/_moved/organization-projects/[id].ts delete mode 100644 apps/web/pages/api/_moved/organization-projects/setting/[id].ts delete mode 100644 apps/web/pages/api/_moved/organization-team-employee/[id]/active-task.ts delete mode 100644 apps/web/pages/api/_moved/organization-team-employee/[id]/index.tsx delete mode 100644 apps/web/pages/api/_moved/organization-team-join/[id]/[action].ts delete mode 100644 apps/web/pages/api/_moved/organization-team-join/index.ts delete mode 100644 apps/web/pages/api/_moved/organization-team-join/resend-code.ts delete mode 100644 apps/web/pages/api/_moved/organization-team-join/validate.ts delete mode 100644 apps/web/pages/api/_moved/organization-team/[id].ts delete mode 100644 apps/web/pages/api/_moved/organization-team/employee/[id].ts delete mode 100644 apps/web/pages/api/_moved/organization-team/index.ts delete mode 100644 apps/web/pages/api/_moved/organization-team/teams/[id].ts delete mode 100644 apps/web/pages/api/_moved/public/team/[profileLink]/[teamId].ts delete mode 100644 apps/web/pages/api/_moved/role-permissions/[id].ts delete mode 100644 apps/web/pages/api/_moved/roles/[id].ts delete mode 100644 apps/web/pages/api/_moved/roles/index.ts delete mode 100644 apps/web/pages/api/_moved/tags/[id].ts delete mode 100644 apps/web/pages/api/_moved/tags/index.tsx delete mode 100644 apps/web/pages/api/_moved/tags/level.ts delete mode 100644 apps/web/pages/api/_moved/task-priorities/[id].ts delete mode 100644 apps/web/pages/api/_moved/task-priorities/index.tsx delete mode 100644 apps/web/pages/api/_moved/task-related-issue-types/[id].ts delete mode 100644 apps/web/pages/api/_moved/task-related-issue-types/index.ts delete mode 100644 apps/web/pages/api/_moved/task-sizes/[id].ts delete mode 100644 apps/web/pages/api/_moved/task-sizes/index.tsx delete mode 100644 apps/web/pages/api/_moved/task-statuses/[id].ts delete mode 100644 apps/web/pages/api/_moved/task-statuses/index.tsx delete mode 100644 apps/web/pages/api/_moved/task-versions/[id].ts delete mode 100644 apps/web/pages/api/_moved/task-versions/index.tsx delete mode 100644 apps/web/pages/api/_moved/tasks/[id].ts delete mode 100644 apps/web/pages/api/_moved/tasks/employee/[employeeId].ts delete mode 100644 apps/web/pages/api/_moved/tasks/task-linked-issue.ts delete mode 100644 apps/web/pages/api/_moved/tasks/team.ts delete mode 100644 apps/web/pages/api/_moved/timer/start.ts delete mode 100644 apps/web/pages/api/_moved/timer/status.ts delete mode 100644 apps/web/pages/api/_moved/timer/stop.ts delete mode 100644 apps/web/pages/api/_moved/timer/sync.ts delete mode 100644 apps/web/pages/api/_moved/timer/timesheet/all-statistics-tasks.ts delete mode 100644 apps/web/pages/api/_moved/timer/timesheet/index.ts delete mode 100644 apps/web/pages/api/_moved/timer/timesheet/statistics-tasks.ts delete mode 100644 apps/web/pages/api/_moved/timer/toggle.ts delete mode 100644 apps/web/pages/api/_moved/user/[id].ts delete mode 100644 apps/web/pages/api/_moved/user/me.ts delete mode 100644 apps/web/pages/api/_moved/user/reset.ts diff --git a/apps/web/app/api/auth/signin-email/route.ts b/apps/web/app/api/auth/signin-email/route.ts index b13a9fa44..b7f7c0968 100644 --- a/apps/web/app/api/auth/signin-email/route.ts +++ b/apps/web/app/api/auth/signin-email/route.ts @@ -13,7 +13,7 @@ export async function POST(req: Request) { const { errors, valid: formValid } = authFormValidate(['email'], body as any); if (!formValid) { - return NextResponse.json({ errors }); + return NextResponse.json({ errors }, { status: 400 }); } const codeSendRes = await signInEmailRequest(body.email, callbackUrl).catch(() => void 0); diff --git a/apps/web/pages/api/_moved/auth/login.ts b/apps/web/pages/api/_moved/auth/login.ts deleted file mode 100644 index e2c22b7a2..000000000 --- a/apps/web/pages/api/_moved/auth/login.ts +++ /dev/null @@ -1,152 +0,0 @@ -import { setAuthCookies, setNoTeamPopupShowCookie } from '@app/helpers/cookies'; -import { generateToken } from '@app/helpers/generate-token'; -import { authFormValidate } from '@app/helpers/validations'; -import { ILoginDataAPI, ILoginResponse as ILoginResponse } from '@app/interfaces/IAuthentication'; -import { - acceptInviteRequest, - getAllOrganizationTeamRequest, - getUserOrganizationsRequest, - verifyAuthCodeRequest, - verifyInviteCodeRequest -} from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const body = req.body as ILoginDataAPI; - let loginResponse: ILoginResponse | null = null; - - const { errors, valid: formValid } = authFormValidate(['email', 'code'], body as any); - - if (!formValid) { - return res.status(400).json({ errors }); - } - - /** - * Verify first if matches with invite code - */ - const inviteReq = await verifyInviteCodeRequest({ - email: body.email, - code: body.code - }).catch(() => void 0); - /** - * If the invite code verification failed then try again with the Auth code - */ - if (!inviteReq || !inviteReq.response.ok || (inviteReq.data as any).response?.statusCode) { - try { - const authReq = await verifyAuthCodeRequest(body.email, body.code); - if ( - !authReq.response.ok || - (authReq.data as any).status === 404 || - (authReq.data as any).status === 400 || - (authReq.data as any).status === 401 - ) { - return res.status(200).json({ - errors: { - email: 'Authentication code or email address invalid' - } - }); - } - - loginResponse = authReq.data; - } catch (error) { - // return notFound(res); - return res.status(200).json({ - errors: { - email: 'Authentication code or email address invalid' - } - }); - } - - /** - * If the provided code is an invite code and - * verified then accept and register the related user - */ - } else { - // General a random password with 8 chars - const password = generateToken(8); - const names = inviteReq.data.fullName.split(' '); - const acceptInviteRes = await acceptInviteRequest({ - code: body.code, - email: inviteReq.data.email, - password: password, - user: { - firstName: names[0], - lastName: names[1] || '', - email: body.email - } - }).catch(() => void 0); - - if ( - !acceptInviteRes || - !acceptInviteRes.response.ok || - acceptInviteRes.response.status === 401 || - acceptInviteRes.response.status === 400 || - (acceptInviteRes.data as any).response?.statusCode - ) { - return res.status(400).json({ - errors: { - email: 'Authentication code or email address invalid' - } - }); - } - - loginResponse = acceptInviteRes.data; - } - - if (!loginResponse) { - return res.status(400).json({ - errors: { - email: 'Authentication code or email address invalid' - } - }); - } - - /** - * Get the first team from the first organization - */ - const tenantId = loginResponse.user?.tenantId || ''; - const access_token = loginResponse.token; - const userId = loginResponse.user?.id; - - const { data: organizations } = await getUserOrganizationsRequest({ tenantId, userId }, access_token); - - const organization = organizations?.items[0]; - - if (!organization) { - return res.status(400).json({ - errors: { - email: 'Your account is not yet ready to be used on the Ever Teams Platform' - } - }); - } - - const { data: teams } = await getAllOrganizationTeamRequest( - { tenantId, organizationId: organization.organizationId }, - access_token - ); - - const team = teams.items[0]; - - if (!team) { - setNoTeamPopupShowCookie(true); - } - - setAuthCookies( - { - access_token: loginResponse.token, - refresh_token: { - token: loginResponse.refresh_token - }, - teamId: team?.id, - tenantId, - organizationId: organization?.organizationId, - languageId: 'en', // TODO: not sure what should be here - noTeamPopup: true, - userId - }, - req, - res - ); - - res.status(200).json({ team, loginResponse }); -} diff --git a/apps/web/pages/api/_moved/auth/meet/jwt.ts b/apps/web/pages/api/_moved/auth/meet/jwt.ts deleted file mode 100644 index 06dddc445..000000000 --- a/apps/web/pages/api/_moved/auth/meet/jwt.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { MEET_DOMAIN, MEET_JWT_APP_ID, MEET_JWT_APP_SECRET } from '@app/constants'; -// import { -// // getMeetJwtSessionCookie, -// setMeetJwtSessionCookie, -// } from '@app/helpers'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import jwt from 'jsonwebtoken'; - -import { NextApiRequest, NextApiResponse } from 'next'; - -const algo: jwt.SignOptions = { algorithm: 'HS256' }; -type Params = { - name: string; - email: string; - room: string; - appid: string; - appkey: string; - domain: string; - audience: string; - avatar: string | null; - id: string; -}; - -function generateToken(params: Params): string { - const payload = { - context: { - user: { - id: params.id, - avatar: params.avatar, - name: params.name, - email: params.email - } - }, - aud: params.audience, - iss: params.appid, - sub: params.domain, - room: params.room - }; - - return jwt.sign(payload, params.appkey, algo); -} - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user } = await authenticatedGuard(req, res); - if (!user) return $res(); - - if (!MEET_JWT_APP_SECRET || !MEET_JWT_APP_ID || !MEET_DOMAIN) { - return $res.status(400).json('Invalid configuration !'); - } - - // Check if existing token from cookie is valid - // const existing_token = getMeetJwtSessionCookie({ req, res }); - // if ( - // existing_token && - // jwt.verify(existing_token, MEET_JWT_APP_SECRET, algo) - // ) { - // return $res.json({ token: existing_token }); - // } - - // Generate new token - const new_token = generateToken({ - id: user.id, - name: user.name || user.email.split('@')[0], - email: user.email, - avatar: user.imageUrl, - audience: 'jitsi', - room: '*', - domain: MEET_DOMAIN.value, - appid: MEET_JWT_APP_ID, - appkey: MEET_JWT_APP_SECRET - }); - - // We don't use this cookie for now - // setMeetJwtSessionCookie(new_token, { req, res }); - - res.status(200).json({ token: new_token }); -} diff --git a/apps/web/pages/api/_moved/auth/refresh.ts b/apps/web/pages/api/_moved/auth/refresh.ts deleted file mode 100644 index d0dc4137e..000000000 --- a/apps/web/pages/api/_moved/auth/refresh.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { setAccessTokenCookie } from '@app/helpers/cookies'; -import { hasErrors } from '@app/helpers/validations'; -import { currentAuthenticatedUserRequest, refreshTokenRequest } from '@app/services/server/requests/auth'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - if (req.method !== 'POST') { - return res.status(405).send({}); - } - - const body = req.body as { refresh_token: string } | null; - const refresh_token = body?.refresh_token; - - if (!refresh_token || refresh_token.trim().length < 2) { - return res.status(401).json( - hasErrors({ - refresh_token: 'The refresh token must be provided on the request body' - }) - ); - } - - const { data } = await refreshTokenRequest(refresh_token); - if (!data) { - return res.status(401); - } - - const { data: user } = await currentAuthenticatedUserRequest({ - bearer_token: data.token - }); - - setAccessTokenCookie(data.token, { res, req }); - - res.status(200).json({ user, token: data.token }); -} diff --git a/apps/web/pages/api/_moved/auth/register.ts b/apps/web/pages/api/_moved/auth/register.ts deleted file mode 100644 index 97efa9c27..000000000 --- a/apps/web/pages/api/_moved/auth/register.ts +++ /dev/null @@ -1,146 +0,0 @@ -import { generateToken } from '@app/helpers/generate-token'; -import { authFormValidate } from '@app/helpers/validations'; -import { IRegisterDataAPI } from '@app/interfaces/IAuthentication'; -import { - createEmployeeFromUser, - createOrganizationRequest, - createOrganizationTeamRequest, - createTenantRequest, - createTenantSmtpRequest, - loginUserRequest, - registerUserRequest, - refreshTokenRequest -} from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; -import { setAuthCookies } from '@app/helpers/cookies'; -import { recaptchaVerification } from '@app/services/server/recaptcha'; -import { RECAPTCHA_SECRET_KEY, VERIFY_EMAIL_CALLBACK_PATH } from '@app/constants'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - if (req.method !== 'POST') { - return res.status(405).json({}); - } - - const appEmailConfirmationUrl = `${req.headers.origin}${VERIFY_EMAIL_CALLBACK_PATH}`; - - const body = req.body as IRegisterDataAPI; - - const noRecaptchaArray = ['email', 'name', 'team']; - - const withRecaptchaArray = [...noRecaptchaArray, 'recaptcha']; - - const validationFields = RECAPTCHA_SECRET_KEY ? withRecaptchaArray : noRecaptchaArray; - - const { errors, valid: formValid } = authFormValidate(validationFields, body); - - if (!formValid) { - return res.status(400).json({ errors }); - } - - if (RECAPTCHA_SECRET_KEY) { - const { success } = await recaptchaVerification({ - secret: RECAPTCHA_SECRET_KEY, - response: body.recaptcha ? body.recaptcha : '' - }); - - if (!success) { - return res.status(400).json({ errors: { recaptcha: 'Invalid reCAPTCHA. Please try again' } }); - } - } - /** - * Verify if the SMTP has been configured - */ - // const hasSMTPConfig = validSMTPConfig(); - - // if (0 && hasSMTPConfig) { - // return res.status(400).json({ - // status: 400, - // message: 'Unable to find SMTP configuration', - // }); - // } - - // General a random password with 8 chars - const password = generateToken(8); - const names = body.name.split(' '); - - // Register user - const { data: user } = await registerUserRequest({ - password: password, - confirmPassword: password, - user: { - firstName: names[0], - lastName: names[1] || '', - email: body.email, - timeZone: body.timezone as string - }, - appEmailConfirmationUrl - }); - // User Login, get the access token - const { data: loginRes } = await loginUserRequest(body.email, password); - let auth_token = loginRes.token; - - // Create user tenant - const { data: tenant } = await createTenantRequest(body.team, auth_token); - - // Create tenant SMTP - await createTenantSmtpRequest({ - access_token: auth_token, - tenantId: tenant.id - }); - - // Create user organization - const { data: organization } = await createOrganizationRequest( - { - currency: 'USD', - name: body.team, - tenantId: tenant.id, - invitesAllowed: true - }, - auth_token - ); - - // Create employee - const { data: employee } = await createEmployeeFromUser( - { - organizationId: organization.id, - startedWorkOn: new Date().toISOString(), - tenantId: tenant.id, - userId: user.id - }, - auth_token - ); - - // Create user organization team - const { data: team } = await createOrganizationTeamRequest( - { - name: body.team, - tenantId: tenant.id, - organizationId: organization.id, - managerIds: [employee.id], - public: true // By default team should be public, - }, - auth_token - ); - - const { data: refreshTokenRes } = await refreshTokenRequest(loginRes.refresh_token); - auth_token = refreshTokenRes.token; - - setAuthCookies( - { - access_token: auth_token, - refresh_token: { - token: loginRes.refresh_token - }, - timezone: body['timezone'], - teamId: team.id, - tenantId: tenant.id, - organizationId: organization.id, - languageId: 'en', // TODO: not sure what should be here - userId: user.id - }, - req, - res - ); - - res.status(200).json({ loginRes, team, employee }); -} diff --git a/apps/web/pages/api/_moved/auth/send-code.ts b/apps/web/pages/api/_moved/auth/send-code.ts deleted file mode 100644 index 58c005446..000000000 --- a/apps/web/pages/api/_moved/auth/send-code.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { INVITE_CALLBACK_PATH } from '@app/constants'; -import { authFormValidate } from '@app/helpers/validations'; -import { sendAuthCodeRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - if (req.method !== 'POST') { - return res.status(405).json({ status: 'fail' }); - } - - const callbackUrl = `${req.headers.origin}${INVITE_CALLBACK_PATH}`; - - const body = req.body as { email: string }; - - const { errors, valid: formValid } = authFormValidate(['email'], body as any); - - if (!formValid) { - return res.status(400).json({ errors }); - } - - const codeSendRes = await sendAuthCodeRequest(body.email, callbackUrl).catch(() => void 0); - - if (!codeSendRes) { - return res.status(400).json({ - errors: { - email: "We couldn't find any account associated to this email" - } - }); - } - - res.status(200).json(codeSendRes.data); -} diff --git a/apps/web/pages/api/_moved/auth/signin-email-confirm.ts b/apps/web/pages/api/_moved/auth/signin-email-confirm.ts deleted file mode 100644 index b5f01fdf1..000000000 --- a/apps/web/pages/api/_moved/auth/signin-email-confirm.ts +++ /dev/null @@ -1,131 +0,0 @@ -import { generateToken, setAuthCookies, setNoTeamPopupShowCookie } from '@app/helpers'; -import { authFormValidate } from '@app/helpers/validations'; -import { ILoginResponse } from '@app/interfaces'; -import { - acceptInviteRequest, - getAllOrganizationTeamRequest, - getUserOrganizationsRequest, - signInEmailConfirmRequest, - verifyInviteCodeRequest -} from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - if (req.method !== 'POST') { - return res.status(405).json({ status: 'fail' }); - } - - const body = req.body as { email: string; code: string }; - let loginResponse: ILoginResponse | null = null; - - const { errors, valid: formValid } = authFormValidate(['email', 'code'], body as any); - - if (!formValid) { - return res.status(400).json({ errors }); - } - - // Accept Invite Flow Start - /** - * Verify first if match with invite code - */ - const inviteReq = await verifyInviteCodeRequest({ - email: body.email, - code: body.code - }).catch(() => void 0); - - // General a random password with 8 chars - if (inviteReq && inviteReq.data.fullName) { - const password = generateToken(8); - console.log('inviteReq', inviteReq.data); - - const names = inviteReq.data.fullName.split(' '); - const acceptInviteRes = await acceptInviteRequest({ - code: body.code, - email: body.email, - password: password, - user: { - firstName: names[0], - lastName: names[1] || '', - email: body.email - } - }).catch(() => void 0); - - if ( - !acceptInviteRes || - !acceptInviteRes.response.ok || - acceptInviteRes.response.status === 401 || - acceptInviteRes.response.status === 400 || - (acceptInviteRes?.data as any).response?.statusCode - ) { - return res.status(400).json({ - errors: { - email: 'Authentication code or email address invalid' - } - }); - } - loginResponse = acceptInviteRes.data; - - if (!loginResponse) { - return res.status(400).json({ - errors: { - email: 'Authentication code or email address invalid' - } - }); - } - } - if (loginResponse) { - console.log('loginResponse>>>', loginResponse); - - /** - * Get the first team from first organization - */ - const tenantId = loginResponse.user?.tenantId || ''; - const access_token = loginResponse.token; - const userId = loginResponse.user?.id; - - const { data: organizations } = await getUserOrganizationsRequest({ tenantId, userId }, access_token); - const organization = organizations?.items[0]; - - if (!organization) { - return res.status(400).json({ - errors: { - email: 'Your account is not yet ready to be used on the Ever Teams Platform' - } - }); - } - const { data: teams } = await getAllOrganizationTeamRequest( - { tenantId, organizationId: organization.organizationId }, - access_token - ); - - const team = teams.items[0]; - if (!team) { - setNoTeamPopupShowCookie(true); - } - setAuthCookies( - { - access_token: loginResponse.token, - refresh_token: { - token: loginResponse.refresh_token - }, - teamId: team?.id, - tenantId, - organizationId: organization?.organizationId, - languageId: 'en', // TODO: not sure what should be here - noTeamPopup: true, - userId - }, - req, - res - ); - return res.status(200).json({ team, loginResponse }); - } - // Accept Invite Flow End - - const { data } = await signInEmailConfirmRequest({ - code: body.code, - email: body.email - }); - - res.json(data); -} diff --git a/apps/web/pages/api/_moved/auth/signin-email.ts b/apps/web/pages/api/_moved/auth/signin-email.ts deleted file mode 100644 index 1ad9c2ee9..000000000 --- a/apps/web/pages/api/_moved/auth/signin-email.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { INVITE_CALLBACK_PATH } from '@app/constants'; -import { authFormValidate } from '@app/helpers/validations'; -import { signInEmailRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - if (req.method !== 'POST') { - return res.status(405).json({ status: 'fail' }); - } - - const callbackUrl = `${req.headers.origin}${INVITE_CALLBACK_PATH}`; - - const body = req.body as { email: string }; - - const { errors, valid: formValid } = authFormValidate(['email'], body as any); - - if (!formValid) { - return res.status(400).json({ errors }); - } - - const codeSendRes = await signInEmailRequest(body.email, callbackUrl).catch(() => void 0); - - if (!codeSendRes) { - return res.status(400).json({ - errors: { - email: "We couldn't find any account associated to this email" - } - }); - } - - res.status(200).json(codeSendRes.data); -} diff --git a/apps/web/pages/api/_moved/auth/verify/code.ts b/apps/web/pages/api/_moved/auth/verify/code.ts deleted file mode 100644 index 410e15cd4..000000000 --- a/apps/web/pages/api/_moved/auth/verify/code.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { authFormValidate } from '@app/helpers/validations'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { verifyUserEmailByCodeRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - if (req.method !== 'POST') { - return res.status(405).json({ status: 'fail' }); - } - - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const body = req.body as { code: string }; - - const { errors, valid: formValid } = authFormValidate(['code'], body as any); - - if (!formValid) { - return res.status(400).json({ errors }); - } - - const { data } = await verifyUserEmailByCodeRequest({ - bearer_token: access_token, - tenantId, - code: body.code, - email: user.email - }); - - $res.json(data); -} diff --git a/apps/web/pages/api/_moved/auth/verify/resend-link.ts b/apps/web/pages/api/_moved/auth/verify/resend-link.ts deleted file mode 100644 index 69a85d3e8..000000000 --- a/apps/web/pages/api/_moved/auth/verify/resend-link.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { VERIFY_EMAIL_CALLBACK_PATH } from '@app/constants'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { resentVerifyUserLinkRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - if (req.method !== 'POST') { - return res.status(405).json({ status: 'fail' }); - } - - const appEmailConfirmationUrl = `${req.headers.origin}${VERIFY_EMAIL_CALLBACK_PATH}`; - - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const { data } = await resentVerifyUserLinkRequest({ - bearer_token: access_token, - tenantId, - email: user.email, - appEmailConfirmationUrl - }); - - $res.json(data); -} diff --git a/apps/web/pages/api/_moved/auth/verify/token.ts b/apps/web/pages/api/_moved/auth/verify/token.ts deleted file mode 100644 index d8327ee81..000000000 --- a/apps/web/pages/api/_moved/auth/verify/token.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { authFormValidate } from '@app/helpers/validations'; -import { verifyUserEmailByTokenRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - if (req.method !== 'POST') { - return res.status(405).json({ status: 'fail' }); - } - - const body = req.body as { email: string; token: string }; - - const { errors, valid: formValid } = authFormValidate(['email', 'token'], body as any); - - if (!formValid) { - return res.status(400).json({ errors }); - } - - const { data } = await verifyUserEmailByTokenRequest({ - token: body.token, - email: body.email - }); - - res.status(200).json(data); -} diff --git a/apps/web/pages/api/_moved/email-reset/request-change-email.ts b/apps/web/pages/api/_moved/email-reset/request-change-email.ts deleted file mode 100644 index cf6c4b585..000000000 --- a/apps/web/pages/api/_moved/email-reset/request-change-email.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { IEmail } from '@app/interfaces/IUserData'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { emailResetRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { email } = req.body as IEmail; - - switch (req.method) { - case 'POST': - return $res.json( - await emailResetRequest({ - email, - tenantId, - bearer_token: access_token - }) - ); - } -} diff --git a/apps/web/pages/api/_moved/email-reset/verify-change-email.ts b/apps/web/pages/api/_moved/email-reset/verify-change-email.ts deleted file mode 100644 index aa7ab23e6..000000000 --- a/apps/web/pages/api/_moved/email-reset/verify-change-email.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { ICode } from '@app/interfaces/IUserData'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { verifyChangemailRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { code } = req.body as ICode; - - switch (req.method) { - case 'POST': - return $res.json( - await verifyChangemailRequest({ - code, - tenantId, - bearer_token: access_token - }) - ); - } -} diff --git a/apps/web/pages/api/_moved/employee/working.ts b/apps/web/pages/api/_moved/employee/working.ts deleted file mode 100644 index c0b44321a..000000000 --- a/apps/web/pages/api/_moved/employee/working.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { getOrganizationEmployees } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { data } = await getOrganizationEmployees(access_token, tenantId, organizationId); - - $res.json(data); -} diff --git a/apps/web/pages/api/_moved/integration-tenant/[id].ts b/apps/web/pages/api/_moved/integration-tenant/[id].ts deleted file mode 100644 index 01ea6e4a3..000000000 --- a/apps/web/pages/api/_moved/integration-tenant/[id].ts +++ /dev/null @@ -1,20 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { deleteIntegrationTenantRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { id } = req.query; - - if (req.method !== 'DELETE') { - return $res.status(405).json({}); - } - - if (id) { - const response = await deleteIntegrationTenantRequest(id as string, tenantId, organizationId, access_token); - - return $res.status(200).json(response); - } -} diff --git a/apps/web/pages/api/_moved/integration-tenant/remember/state/index.ts b/apps/web/pages/api/_moved/integration-tenant/remember/state/index.ts deleted file mode 100644 index ac8014d53..000000000 --- a/apps/web/pages/api/_moved/integration-tenant/remember/state/index.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { getIntegrationTenantRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { name } = req.query; - - if (req.method !== 'GET') { - return $res.status(405).json({}); - } - - const response = await getIntegrationTenantRequest( - { - tenantId, - organizationId, - name: name as string - }, - access_token - ); - - return $res.status(200).json(response); -} diff --git a/apps/web/pages/api/_moved/integration/github/install.ts b/apps/web/pages/api/_moved/integration/github/install.ts deleted file mode 100644 index 8c251468b..000000000 --- a/apps/web/pages/api/_moved/integration/github/install.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { installGitHubIntegration } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { installation_id, setup_action } = req.body; - - if (req.method !== 'POST') { - return $res.status(405).json({}); - } - - const response = await installGitHubIntegration( - { - tenantId, - organizationId, - installation_id, - setup_action - }, - access_token - ); - - return $res.status(200).json(response); -} diff --git a/apps/web/pages/api/_moved/integration/github/metadata.ts b/apps/web/pages/api/_moved/integration/github/metadata.ts deleted file mode 100644 index c3c0fb866..000000000 --- a/apps/web/pages/api/_moved/integration/github/metadata.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { getGithubIntegrationMetadataRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - if (req.method !== 'GET') { - return $res.status(405).json({}); - } - - const { integrationId } = req.query; - - const response = await getGithubIntegrationMetadataRequest( - { - tenantId, - organizationId, - integrationId: integrationId as string - }, - access_token - ); - - return $res.status(200).json(response); -} diff --git a/apps/web/pages/api/_moved/integration/github/oauth.ts b/apps/web/pages/api/_moved/integration/github/oauth.ts deleted file mode 100644 index 3062d276b..000000000 --- a/apps/web/pages/api/_moved/integration/github/oauth.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { oAuthEndpointAuthorization } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { installation_id, setup_action, code } = req.body; - - if (req.method !== 'POST') { - return $res.status(405).json({}); - } - - const response = await oAuthEndpointAuthorization( - { - tenantId, - organizationId, - installation_id, - setup_action, - code - }, - access_token - ); - - return $res.status(200).json(response); -} diff --git a/apps/web/pages/api/_moved/integration/github/repositories.ts b/apps/web/pages/api/_moved/integration/github/repositories.ts deleted file mode 100644 index e0e455c41..000000000 --- a/apps/web/pages/api/_moved/integration/github/repositories.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { getGithubIntegrationRepositoriesRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - if (req.method !== 'GET') { - return $res.status(405).json({}); - } - - const { integrationId } = req.query; - - const response = await getGithubIntegrationRepositoriesRequest( - { - tenantId, - organizationId, - integrationId: integrationId as string - }, - access_token - ); - - return $res.status(200).json(response); -} diff --git a/apps/web/pages/api/_moved/integration/github/repository/sync.ts b/apps/web/pages/api/_moved/integration/github/repository/sync.ts deleted file mode 100644 index 8b860bcfa..000000000 --- a/apps/web/pages/api/_moved/integration/github/repository/sync.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { projectRepositorySyncRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - if (req.method !== 'POST') { - return $res.status(405).json({}); - } - - const response = await projectRepositorySyncRequest( - { - ...req.body, - tenantId, - organizationId - }, - access_token - ); - - return $res.status(200).json(response); -} diff --git a/apps/web/pages/api/_moved/integration/types/index.ts b/apps/web/pages/api/_moved/integration/types/index.ts deleted file mode 100644 index 07577464e..000000000 --- a/apps/web/pages/api/_moved/integration/types/index.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { getIntegrationTypesRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - if (req.method !== 'GET') { - return $res.status(405).json({}); - } - - const response = await getIntegrationTypesRequest( - { - tenantId - }, - access_token - ); - - return $res.status(200).json(response); -} diff --git a/apps/web/pages/api/_moved/invite/[id].ts b/apps/web/pages/api/_moved/invite/[id].ts deleted file mode 100644 index 4d45eaabb..000000000 --- a/apps/web/pages/api/_moved/invite/[id].ts +++ /dev/null @@ -1,59 +0,0 @@ -/* eslint-disable no-case-declarations */ -import { MyInvitationActionEnum } from '@app/interfaces'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { - getTeamInvitationsRequest, - removeTeamInvitationsRequest, - getMyInvitationsRequest, - acceptRejectMyInvitationsRequest -} from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId, teamId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const invitationId = req.query.id as string; - - if (!req.query.id) { - return $res.status(400).json({}); - } - - switch (req.method) { - case 'GET': - const { data: invitationData } = await getMyInvitationsRequest(tenantId, access_token); - return $res.json(invitationData); - - case 'DELETE': - await removeTeamInvitationsRequest({ - bearer_token: access_token, - tenantId: tenantId, - invitationId - }); - - const { data } = await getTeamInvitationsRequest( - { - tenantId, - teamId, - organizationId, - role: 'EMPLOYEE' - }, - access_token - ); - - return $res.json(data); - - case 'PUT': - if (!req.query.action) { - return $res.status(400).json({}); - } - return $res.json( - await acceptRejectMyInvitationsRequest( - tenantId, - access_token, - invitationId, - req.query.action as MyInvitationActionEnum - ) - ); - } -} diff --git a/apps/web/pages/api/_moved/invite/emails.ts b/apps/web/pages/api/_moved/invite/emails.ts deleted file mode 100644 index 1722a54e1..000000000 --- a/apps/web/pages/api/_moved/invite/emails.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { INVITE_CALLBACK_URL, INVITE_CALLBACK_PATH } from '@app/constants'; -import { validateForm } from '@app/helpers/validations'; -import { IInviteRequest } from '@app/interfaces/IInvite'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { - getEmployeeRoleRequest, - getTeamInvitationsRequest, - inviteByEmailsRequest -} from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, organizationId, access_token, teamId, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const callbackUrl = `${req.headers.origin}${INVITE_CALLBACK_PATH}`; - - const body = req.body as IInviteRequest; - - const { errors, isValid: formValid } = validateForm(['email', 'name'], body); - - if (!formValid) { - return res.status(400).json({ errors }); - } - - const { data: employeeRole } = await getEmployeeRoleRequest({ - tenantId, - role: 'EMPLOYEE', - bearer_token: access_token - }); - - const date = new Date(); - date.setDate(date.getDate() - 1); - - await inviteByEmailsRequest( - { - emailIds: [body.email], - projectIds: [], - departmentIds: [], - organizationContactIds: [], - teamIds: [teamId], - roleId: employeeRole?.id || '', - invitationExpirationPeriod: 'Never', - inviteType: 'TEAM', - appliedDate: null, - fullName: body.name, - callbackUrl: INVITE_CALLBACK_URL || callbackUrl, - organizationId, - tenantId, - startedWorkOn: date.toISOString() - }, - access_token - ); - - const { data } = await getTeamInvitationsRequest( - { - tenantId, - teamId, - organizationId, - role: 'EMPLOYEE' - }, - access_token - ); - - $res.status(200).json(data); -} diff --git a/apps/web/pages/api/_moved/invite/index.ts b/apps/web/pages/api/_moved/invite/index.ts deleted file mode 100644 index 70085e3b4..000000000 --- a/apps/web/pages/api/_moved/invite/index.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { getTeamInvitationsRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId, teamId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { data } = await getTeamInvitationsRequest( - { - tenantId, - teamId, - organizationId, - role: 'EMPLOYEE' - }, - access_token - ); - - $res.status(200).json(data); -} diff --git a/apps/web/pages/api/_moved/invite/resend.ts b/apps/web/pages/api/_moved/invite/resend.ts deleted file mode 100644 index a934c2d79..000000000 --- a/apps/web/pages/api/_moved/invite/resend.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { INVITE_CALLBACK_PATH, INVITE_CALLBACK_URL } from '@app/constants'; -import { validateForm } from '@app/helpers/validations'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { resendInvitationEmailRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const callbackUrl = `${req.headers.origin}${INVITE_CALLBACK_PATH}`; - - const body = req.body as { inviteId: string }; - - const { errors, isValid: formValid } = validateForm(['inviteId'], body); - - if (!formValid) { - return res.status(400).json({ errors }); - } - - const { data } = await resendInvitationEmailRequest( - { - tenantId, - inviteId: body.inviteId, - inviteType: 'TEAM', - organizationId, - callbackUrl: INVITE_CALLBACK_URL || callbackUrl - }, - access_token - ); - - $res.json(data); -} diff --git a/apps/web/pages/api/_moved/invite/validate-by-code.ts b/apps/web/pages/api/_moved/invite/validate-by-code.ts deleted file mode 100644 index a1440c109..000000000 --- a/apps/web/pages/api/_moved/invite/validate-by-code.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { validateForm } from '@app/helpers/validations'; -import { IInviteVerifyCode } from '@app/interfaces/IInvite'; -import { verifyInviteCodeRequest } from '@app/services/server/requests'; - -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const body = req.body as IInviteVerifyCode; - - const { errors, isValid: formValid } = validateForm(['code', 'email'], body as any); - - if (!formValid) { - return res.status(400).json({ errors }); - } - - const { data } = await verifyInviteCodeRequest(body); - - res.status(200).json(data); -} diff --git a/apps/web/pages/api/_moved/issue-types/[id].ts b/apps/web/pages/api/_moved/issue-types/[id].ts deleted file mode 100644 index d4068a393..000000000 --- a/apps/web/pages/api/_moved/issue-types/[id].ts +++ /dev/null @@ -1,32 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { deleteIssueTypesRequest, editIssueTypesRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const { id } = req.query; - - switch (req.method) { - case 'DELETE': - return $res.json( - await deleteIssueTypesRequest({ - id, - bearer_token: access_token, - tenantId - }) - ); - - case 'PUT': - return $res.json( - await editIssueTypesRequest({ - id, - datas: req.body, - bearer_token: access_token, - tenantId - }) - ); - } -} diff --git a/apps/web/pages/api/_moved/issue-types/index.tsx b/apps/web/pages/api/_moved/issue-types/index.tsx deleted file mode 100644 index cca758a0f..000000000 --- a/apps/web/pages/api/_moved/issue-types/index.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { createIssueTypeRequest, getIssueTypesListRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const { organizationTeamId } = req.query; - - const par = { - tenantId, - organizationId, - organizationTeamId: (organizationTeamId as string) || null - }; - - switch (req.method) { - case 'GET': - return $res.json(await getIssueTypesListRequest(par, access_token)); - case 'POST': - return $res.json(await createIssueTypeRequest(req.body, access_token, req.body?.tenantId)); - } -} diff --git a/apps/web/pages/api/_moved/languages/index.ts b/apps/web/pages/api/_moved/languages/index.ts deleted file mode 100644 index 7cfc8b503..000000000 --- a/apps/web/pages/api/_moved/languages/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { getLanguageListRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const par = { - is_system: user.role.isSystem as boolean, - tenantId - }; - - switch (req.method) { - case 'GET': - return $res.json(await getLanguageListRequest(par, access_token)); - } -} diff --git a/apps/web/pages/api/_moved/organization-projects/[id].ts b/apps/web/pages/api/_moved/organization-projects/[id].ts deleted file mode 100644 index 20003fcd2..000000000 --- a/apps/web/pages/api/_moved/organization-projects/[id].ts +++ /dev/null @@ -1,22 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; - -import { editOrganizationProjectsRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { id } = req.query; - switch (req.method) { - case 'PUT': - return $res.json( - await editOrganizationProjectsRequest({ - bearer_token: access_token, - id, - datas: req.body, - tenantId - }) - ); - } -} diff --git a/apps/web/pages/api/_moved/organization-projects/setting/[id].ts b/apps/web/pages/api/_moved/organization-projects/setting/[id].ts deleted file mode 100644 index e4a151b68..000000000 --- a/apps/web/pages/api/_moved/organization-projects/setting/[id].ts +++ /dev/null @@ -1,22 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; - -import { editOrganizationProjectsSettingsRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { id } = req.query; - switch (req.method) { - case 'PUT': - return $res.json( - await editOrganizationProjectsSettingsRequest({ - bearer_token: access_token, - id, - datas: req.body, - tenantId - }) - ); - } -} diff --git a/apps/web/pages/api/_moved/organization-team-employee/[id]/active-task.ts b/apps/web/pages/api/_moved/organization-team-employee/[id]/active-task.ts deleted file mode 100644 index 37f50e021..000000000 --- a/apps/web/pages/api/_moved/organization-team-employee/[id]/active-task.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { updateOrganizationTeamEmployeeActiveTaskRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { id } = req.query; - - switch (req.method) { - case 'PUT': - if (id) { - return $res.json( - await updateOrganizationTeamEmployeeActiveTaskRequest({ - id: id as string, - bearer_token: access_token, - tenantId, - body: req.body - }) - ); - } - break; - } -} diff --git a/apps/web/pages/api/_moved/organization-team-employee/[id]/index.tsx b/apps/web/pages/api/_moved/organization-team-employee/[id]/index.tsx deleted file mode 100644 index 3893a0ade..000000000 --- a/apps/web/pages/api/_moved/organization-team-employee/[id]/index.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { - deleteOrganizationTeamEmployeeRequest, - updateOrganizationTeamEmployeeRequest -} from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId, teamId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { id, employeeId } = req.query; - - switch (req.method) { - case 'DELETE': - if (id) { - return $res.json( - await deleteOrganizationTeamEmployeeRequest({ - id: id as string, - bearer_token: access_token, - tenantId, - organizationId, - employeeId: employeeId as string, - organizationTeamId: teamId - }) - ); - } - break; - - case 'PUT': - if (id) { - return $res.json( - await updateOrganizationTeamEmployeeRequest({ - id: id as string, - bearer_token: access_token, - tenantId, - body: req.body - }) - ); - } - break; - } -} diff --git a/apps/web/pages/api/_moved/organization-team-join/[id]/[action].ts b/apps/web/pages/api/_moved/organization-team-join/[id]/[action].ts deleted file mode 100644 index 0b6d58390..000000000 --- a/apps/web/pages/api/_moved/organization-team-join/[id]/[action].ts +++ /dev/null @@ -1,26 +0,0 @@ -import { IRequestToJoinActionEnum } from '@app/interfaces'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { acceptRejectRequestToJoinRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { id, action } = req.query; - - switch (req.method) { - case 'PUT': - if (id) { - return $res.json( - await acceptRejectRequestToJoinRequest({ - id: id as string, - bearer_token: access_token, - tenantId, - action: action as IRequestToJoinActionEnum - }) - ); - } - break; - } -} diff --git a/apps/web/pages/api/_moved/organization-team-join/index.ts b/apps/web/pages/api/_moved/organization-team-join/index.ts deleted file mode 100644 index c44d131c9..000000000 --- a/apps/web/pages/api/_moved/organization-team-join/index.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { IRequestToJoinCreate } from '@app/interfaces'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { getRequestToJoinRequest, requestToJoinRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - switch (req.method) { - case 'GET': - /* eslint-disable no-case-declarations */ - const { access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - - /* eslint-disable no-case-declarations */ - const requestToJoinData = await getRequestToJoinRequest({ - bearer_token: access_token, - tenantId, - organizationId - }); - return res.json(requestToJoinData.data); - case 'POST': - /* eslint-disable no-case-declarations */ - const body = req.body as IRequestToJoinCreate; - return res.json(await requestToJoinRequest(body)); - } -} diff --git a/apps/web/pages/api/_moved/organization-team-join/resend-code.ts b/apps/web/pages/api/_moved/organization-team-join/resend-code.ts deleted file mode 100644 index 6cc4b8eed..000000000 --- a/apps/web/pages/api/_moved/organization-team-join/resend-code.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { IRequestToJoinCreate } from '@app/interfaces'; -import { resendCodeRequestToJoinRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const body = req.body as IRequestToJoinCreate; - - switch (req.method) { - case 'POST': - return res.json(await resendCodeRequestToJoinRequest(body)); - } -} diff --git a/apps/web/pages/api/_moved/organization-team-join/validate.ts b/apps/web/pages/api/_moved/organization-team-join/validate.ts deleted file mode 100644 index 6ebca1ce4..000000000 --- a/apps/web/pages/api/_moved/organization-team-join/validate.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { IValidateRequestToJoin } from '@app/interfaces'; -import { validateRequestToJoinRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const body = req.body as IValidateRequestToJoin; - - switch (req.method) { - case 'POST': - return res.json(await validateRequestToJoinRequest(body)); - } -} diff --git a/apps/web/pages/api/_moved/organization-team/[id].ts b/apps/web/pages/api/_moved/organization-team/[id].ts deleted file mode 100644 index d81aa5477..000000000 --- a/apps/web/pages/api/_moved/organization-team/[id].ts +++ /dev/null @@ -1,48 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; - -import { - deleteOrganizationTeamRequest, - getOrganizationTeamRequest, - updateOrganizationTeamRequest -} from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, organizationId, access_token, tenantId, teamId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const getTeamStatus = async () => { - const { data: team } = await getOrganizationTeamRequest( - { - organizationId, - tenantId, - teamId: teamId - }, - access_token - ); - - return team; - }; - - const { id } = req.query; - switch (req.method) { - case 'GET': - return $res.json(await getTeamStatus()); - - case 'PUT': - await updateOrganizationTeamRequest(req.body, access_token); - return $res.json(await getTeamStatus()); - - case 'DELETE': - if (id) { - return $res.json( - await deleteOrganizationTeamRequest({ - id: id as string, - bearer_token: access_token, - tenantId, - organizationId - }) - ); - } - } -} diff --git a/apps/web/pages/api/_moved/organization-team/employee/[id].ts b/apps/web/pages/api/_moved/organization-team/employee/[id].ts deleted file mode 100644 index c23773bda..000000000 --- a/apps/web/pages/api/_moved/organization-team/employee/[id].ts +++ /dev/null @@ -1,41 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { - addEmployeeOrganizationTeamOrderRequest, - removeEmployeeOrganizationTeamRequest -} from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { id } = req.query; - const order = req.body.order; - - if (!id) { - return $res.status(405).json({}); - } - - switch (req.method) { - case 'DELETE': - await removeEmployeeOrganizationTeamRequest({ - bearer_token: access_token, - tenantId, - employeeId: id.toString() - }); - break; - - case 'PUT': - await addEmployeeOrganizationTeamOrderRequest({ - bearer_token: access_token, - tenantId, - employeeId: id.toString(), - order, - organizationTeamId: req.body.organizationTeamId, - organizationId: req.body.organizationId - }); - break; - } - - return; -} diff --git a/apps/web/pages/api/_moved/organization-team/index.ts b/apps/web/pages/api/_moved/organization-team/index.ts deleted file mode 100644 index f53899539..000000000 --- a/apps/web/pages/api/_moved/organization-team/index.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { IUserOrganization } from '@app/interfaces/IOrganization'; -import { IOrganizationTeamList } from '@app/interfaces/IOrganizationTeam'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { - createOrganizationTeamRequest, - getAllOrganizationTeamRequest, - getUserOrganizationsRequest -} from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - if (req.method === 'POST') { - const body = req.body as { name?: string }; - const $name = body.name?.trim() || ''; - if ($name.trim().length < 2) { - return res.status(400).json({ errors: { name: 'Invalid team name !' } }); - } - await createOrganizationTeamRequest( - { - name: $name, - tenantId, - organizationId, - managerIds: user?.employee?.id ? [user.employee.id] : [], - public: true // By default team should be public - }, - access_token - ); - } - - const { data: organizations } = await getUserOrganizationsRequest({ tenantId, userId: user.id }, access_token); - - const organizationsItems = organizations.items; - - const filteredOrganization = organizationsItems.reduce((acc, org) => { - if (!acc.find((o) => o.organizationId === org.organizationId)) { - acc.push(org); - } - return acc; - }, [] as IUserOrganization[]); - - const call_teams = filteredOrganization.map((item) => { - return getAllOrganizationTeamRequest({ tenantId, organizationId: item.organizationId }, access_token); - }); - - const teams = await Promise.all(call_teams).then((tms) => { - return tms.reduce( - (acc, { data }) => { - if (data && data.items) { - acc.items.push(...data.items); - acc.total += data.total; - } - - return acc; - }, - { items: [] as IOrganizationTeamList[], total: 0 } - ); - }); - - return $res.json(teams); -} diff --git a/apps/web/pages/api/_moved/organization-team/teams/[id].ts b/apps/web/pages/api/_moved/organization-team/teams/[id].ts deleted file mode 100644 index 964e660e7..000000000 --- a/apps/web/pages/api/_moved/organization-team/teams/[id].ts +++ /dev/null @@ -1,23 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; - -import { removeUserFromAllTeam } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { id } = req.query; - switch (req.method) { - case 'DELETE': - if (id) { - return $res.json( - await removeUserFromAllTeam({ - userId: id as string, - bearer_token: access_token, - tenantId - }) - ); - } - } -} diff --git a/apps/web/pages/api/_moved/public/team/[profileLink]/[teamId].ts b/apps/web/pages/api/_moved/public/team/[profileLink]/[teamId].ts deleted file mode 100644 index c0d76025e..000000000 --- a/apps/web/pages/api/_moved/public/team/[profileLink]/[teamId].ts +++ /dev/null @@ -1,31 +0,0 @@ -import { - getPublicOrganizationTeamMiscDataRequest, - getPublicOrganizationTeamRequest -} from '@app/services/server/requests/public-organization-team'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { profileLink, teamId, type }: { profileLink: string; teamId: string; type: string } = req.query as { - profileLink: string; - teamId: string; - type: string; - }; - - switch (req.method) { - case 'GET': - if (type === 'misc') { - return res.json( - await getPublicOrganizationTeamMiscDataRequest({ - profileLink: profileLink, - teamId - }) - ); - } - return res.json( - await getPublicOrganizationTeamRequest({ - profileLink: profileLink, - teamId - }) - ); - } -} diff --git a/apps/web/pages/api/_moved/role-permissions/[id].ts b/apps/web/pages/api/_moved/role-permissions/[id].ts deleted file mode 100644 index 6aafcad42..000000000 --- a/apps/web/pages/api/_moved/role-permissions/[id].ts +++ /dev/null @@ -1,39 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { getRolePermissionsRequest, updateRolePermissionRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const { id } = req.query; - - if (!id) { - return $res.status(405).json({}); - } - - switch (req.method) { - case 'GET': - return $res.json( - ( - await getRolePermissionsRequest({ - bearer_token: access_token, - tenantId, - roleId: id as string - }) - ).data - ); - - case 'PUT': - return $res.json( - ( - await updateRolePermissionRequest({ - bearer_token: access_token, - tenantId, - data: req.body - }) - ).data - ); - } -} diff --git a/apps/web/pages/api/_moved/roles/[id].ts b/apps/web/pages/api/_moved/roles/[id].ts deleted file mode 100644 index 249981016..000000000 --- a/apps/web/pages/api/_moved/roles/[id].ts +++ /dev/null @@ -1,35 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { deleteRoleRequest, updateRoleRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const { id } = req.query; - - if ((req.method !== 'DELETE' && req.method !== 'PUT') || !id) { - return $res.status(405).json({}); - } - - switch (req.method) { - case 'DELETE': - return $res.json( - await deleteRoleRequest({ - id: id as string, - bearer_token: access_token, - tenantId - }) - ); - - case 'PUT': - return $res.json( - await updateRoleRequest({ - bearer_token: access_token, - tenantId, - data: req.body - }) - ); - } -} diff --git a/apps/web/pages/api/_moved/roles/index.ts b/apps/web/pages/api/_moved/roles/index.ts deleted file mode 100644 index b7d2bf100..000000000 --- a/apps/web/pages/api/_moved/roles/index.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; - -import { createRoleRequest, getRolesRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - switch (req.method) { - case 'GET': - return $res.json( - ( - await getRolesRequest({ - bearer_token: access_token, - tenantId - }) - ).data - ); - case 'POST': - return $res.json( - ( - await createRoleRequest({ - bearer_token: access_token, - tenantId, - data: { - ...req.body, - tenantId - } - }) - ).data - ); - } -} diff --git a/apps/web/pages/api/_moved/tags/[id].ts b/apps/web/pages/api/_moved/tags/[id].ts deleted file mode 100644 index f471416eb..000000000 --- a/apps/web/pages/api/_moved/tags/[id].ts +++ /dev/null @@ -1,31 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { deleteTaskLabelsRequest, editTaskLabelsRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const { id } = req.query; - - switch (req.method) { - case 'DELETE': - return $res.json( - await deleteTaskLabelsRequest({ - id, - bearer_token: access_token, - tenantId - }) - ); - case 'PUT': - return $res.json( - await editTaskLabelsRequest({ - id, - datas: req.body, - bearer_token: access_token, - tenantId - }) - ); - } -} diff --git a/apps/web/pages/api/_moved/tags/index.tsx b/apps/web/pages/api/_moved/tags/index.tsx deleted file mode 100644 index c847b0257..000000000 --- a/apps/web/pages/api/_moved/tags/index.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { createLabelsRequest, getTaskLabelsListRequest } from '@app/services/server/requests/task-labels'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const { organizationTeamId } = req.query; - - const par = { - tenantId, - organizationId, - organizationTeamId: (organizationTeamId as string) || null - }; - - switch (req.method) { - case 'GET': - return $res.json(await getTaskLabelsListRequest(par, access_token)); - case 'POST': - return $res.json(await createLabelsRequest(req.body, access_token, req.body?.tenantId)); - } -} diff --git a/apps/web/pages/api/_moved/tags/level.ts b/apps/web/pages/api/_moved/tags/level.ts deleted file mode 100644 index 55b98279d..000000000 --- a/apps/web/pages/api/_moved/tags/level.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { getTaskLabelsListRequest } from '@app/services/server/requests/task-labels'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const { organizationTeamId } = req.query; - - const par = { - tenantId, - organizationId, - organizationTeamId: (organizationTeamId as string) || null - }; - - switch (req.method) { - case 'GET': - return $res.json(await getTaskLabelsListRequest(par, access_token)); - } -} diff --git a/apps/web/pages/api/_moved/task-priorities/[id].ts b/apps/web/pages/api/_moved/task-priorities/[id].ts deleted file mode 100644 index 3d6174031..000000000 --- a/apps/web/pages/api/_moved/task-priorities/[id].ts +++ /dev/null @@ -1,31 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { deleteTaskPrioritiesRequest, editTaskPrioritiesRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const { id } = req.query; - - switch (req.method) { - case 'DELETE': - return $res.json( - await deleteTaskPrioritiesRequest({ - id, - bearer_token: access_token, - tenantId - }) - ); - case 'PUT': - return $res.json( - await editTaskPrioritiesRequest({ - id, - datas: req.body, - bearer_token: access_token, - tenantId - }) - ); - } -} diff --git a/apps/web/pages/api/_moved/task-priorities/index.tsx b/apps/web/pages/api/_moved/task-priorities/index.tsx deleted file mode 100644 index 62f95f1f3..000000000 --- a/apps/web/pages/api/_moved/task-priorities/index.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { createPrioritiesRequest, getTaskPrioritiesListRequest } from '@app/services/server/requests/task-priorities'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const { organizationTeamId } = req.query; - - const par = { - tenantId, - organizationId, - organizationTeamId: (organizationTeamId as string) || null - }; - - switch (req.method) { - case 'GET': - return $res.json(await getTaskPrioritiesListRequest(par, access_token)); - case 'POST': - return $res.json(await createPrioritiesRequest(req.body, access_token, req.body?.tenantId)); - } -} diff --git a/apps/web/pages/api/_moved/task-related-issue-types/[id].ts b/apps/web/pages/api/_moved/task-related-issue-types/[id].ts deleted file mode 100644 index 44e1b2709..000000000 --- a/apps/web/pages/api/_moved/task-related-issue-types/[id].ts +++ /dev/null @@ -1,34 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { - deleteTaskRelatedIssueTypeRequest, - editTaskRelatedIssueTypeRequest -} from '@app/services/server/requests/task-related-issue-type'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const { id } = req.query; - - switch (req.method) { - case 'DELETE': - return $res.json( - await deleteTaskRelatedIssueTypeRequest({ - id, - bearer_token: access_token, - tenantId - }) - ); - case 'PUT': - return $res.json( - await editTaskRelatedIssueTypeRequest({ - id, - datas: req.body, - bearer_token: access_token, - tenantId - }) - ); - } -} diff --git a/apps/web/pages/api/_moved/task-related-issue-types/index.ts b/apps/web/pages/api/_moved/task-related-issue-types/index.ts deleted file mode 100644 index bb3306389..000000000 --- a/apps/web/pages/api/_moved/task-related-issue-types/index.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { - createRelatedIssueTypeRequest, - getTaskRelatedIssueTypeListRequest -} from '@app/services/server/requests/task-related-issue-type'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const { activeTeamId } = req.query; - - const par = { - tenantId, - organizationId, - organizationTeamId: (activeTeamId as string) || null - }; - - switch (req.method) { - case 'GET': - return $res.json(await getTaskRelatedIssueTypeListRequest(par, access_token)); - case 'POST': - return $res.json(await createRelatedIssueTypeRequest(req.body, access_token, req.body?.tenantId)); - } -} diff --git a/apps/web/pages/api/_moved/task-sizes/[id].ts b/apps/web/pages/api/_moved/task-sizes/[id].ts deleted file mode 100644 index a68fd8d42..000000000 --- a/apps/web/pages/api/_moved/task-sizes/[id].ts +++ /dev/null @@ -1,32 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { deleteTaskSizesRequest, editTaskSizesRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const { id } = req.query; - - switch (req.method) { - case 'DELETE': - return $res.json( - await deleteTaskSizesRequest({ - id, - bearer_token: access_token, - tenantId - }) - ); - - case 'PUT': - return $res.json( - await editTaskSizesRequest({ - id, - datas: req.body, - bearer_token: access_token, - tenantId - }) - ); - } -} diff --git a/apps/web/pages/api/_moved/task-sizes/index.tsx b/apps/web/pages/api/_moved/task-sizes/index.tsx deleted file mode 100644 index 393b0c084..000000000 --- a/apps/web/pages/api/_moved/task-sizes/index.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { createSizesRequest, getTaskSizesListRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const { organizationTeamId } = req.query; - - const par = { - tenantId, - organizationId, - organizationTeamId: (organizationTeamId as string) || null - }; - - switch (req.method) { - case 'GET': - return $res.json(await getTaskSizesListRequest(par, access_token)); - case 'POST': - return $res.json(await createSizesRequest(req.body, access_token, req.body?.tenantId)); - } -} diff --git a/apps/web/pages/api/_moved/task-statuses/[id].ts b/apps/web/pages/api/_moved/task-statuses/[id].ts deleted file mode 100644 index 239211707..000000000 --- a/apps/web/pages/api/_moved/task-statuses/[id].ts +++ /dev/null @@ -1,31 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { deleteTaskStatusRequest, editTaskStatusRequest } from '@app/services/server/requests/taskStatus'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const { id } = req.query; - - switch (req.method) { - case 'DELETE': - return $res.json( - await deleteTaskStatusRequest({ - id, - bearer_token: access_token, - tenantId - }) - ); - case 'PUT': - return $res.json( - await editTaskStatusRequest({ - id, - datas: req.body, - bearer_token: access_token, - tenantId - }) - ); - } -} diff --git a/apps/web/pages/api/_moved/task-statuses/index.tsx b/apps/web/pages/api/_moved/task-statuses/index.tsx deleted file mode 100644 index f44a654ff..000000000 --- a/apps/web/pages/api/_moved/task-statuses/index.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { createStatusRequest, getTaskStatusListRequest } from '@app/services/server/requests/taskStatus'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const { organizationTeamId } = req.query; - - const par = { - tenantId, - organizationId, - organizationTeamId: (organizationTeamId as string) || null - }; - - switch (req.method) { - case 'GET': - return $res.json(await getTaskStatusListRequest(par, access_token)); - case 'POST': - return $res.json(await createStatusRequest(req.body, access_token, req.body?.tenantId)); - } -} diff --git a/apps/web/pages/api/_moved/task-versions/[id].ts b/apps/web/pages/api/_moved/task-versions/[id].ts deleted file mode 100644 index 53826327e..000000000 --- a/apps/web/pages/api/_moved/task-versions/[id].ts +++ /dev/null @@ -1,31 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { deleteTaskVersionRequest, editTaskVersionRequest } from '@app/services/server/requests/task-version'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const { id } = req.query; - - switch (req.method) { - case 'DELETE': - return $res.json( - await deleteTaskVersionRequest({ - id, - bearer_token: access_token, - tenantId - }) - ); - case 'PUT': - return $res.json( - await editTaskVersionRequest({ - id, - datas: req.body, - bearer_token: access_token, - tenantId - }) - ); - } -} diff --git a/apps/web/pages/api/_moved/task-versions/index.tsx b/apps/web/pages/api/_moved/task-versions/index.tsx deleted file mode 100644 index d0e62a6db..000000000 --- a/apps/web/pages/api/_moved/task-versions/index.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { createVersionRequest, getTaskVersionListRequest } from '@app/services/server/requests/task-version'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - - if (!user) return $res(); - - const { organizationTeamId } = req.query; - - const par = { - tenantId, - organizationId, - organizationTeamId: (organizationTeamId as string) || null - }; - - switch (req.method) { - case 'GET': - return $res.json(await getTaskVersionListRequest(par, access_token)); - case 'POST': - return $res.json(await createVersionRequest(req.body, access_token, req.body?.tenantId)); - } -} diff --git a/apps/web/pages/api/_moved/tasks/[id].ts b/apps/web/pages/api/_moved/tasks/[id].ts deleted file mode 100644 index 87b475407..000000000 --- a/apps/web/pages/api/_moved/tasks/[id].ts +++ /dev/null @@ -1,47 +0,0 @@ -import { ITeamTask } from '@app/interfaces/ITask'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { getTeamTasksRequest, updateTaskRequest, getTaskByIdRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, tenantId, access_token, organizationId, projectId, teamId} = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { id: taskId } = req.query; - const body = req.body as ITeamTask; - - delete body.selectedTeam; - - switch (req.method) { - case 'GET': - return $res.status(200).json( - await getTaskByIdRequest({ - taskId: taskId as string, - tenantId, - organizationId, - bearer_token: access_token - }) - ); - - case 'PUT': - delete body.rootEpic; - await updateTaskRequest( - { - data: body, - id: taskId as string - }, - access_token - ); - break; - } - - const { data: tasks } = await getTeamTasksRequest({ - tenantId, - organizationId, - projectId, - teamId, - bearer_token: access_token - }); - - $res.status(200).json(tasks); -} diff --git a/apps/web/pages/api/_moved/tasks/employee/[employeeId].ts b/apps/web/pages/api/_moved/tasks/employee/[employeeId].ts deleted file mode 100644 index c4e86f973..000000000 --- a/apps/web/pages/api/_moved/tasks/employee/[employeeId].ts +++ /dev/null @@ -1,26 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { deleteEmployeeFromTasksRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, tenantId, access_token: bearer_token } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { employeeId, organizationTeamId } = req.query as { - employeeId: string; - organizationTeamId: string; - }; - - switch (req.method) { - case 'DELETE': - $res.status(200).json( - await deleteEmployeeFromTasksRequest({ - tenantId, - employeeId, - organizationTeamId, - bearer_token - }) - ); - break; - } -} diff --git a/apps/web/pages/api/_moved/tasks/task-linked-issue.ts b/apps/web/pages/api/_moved/tasks/task-linked-issue.ts deleted file mode 100644 index 3553395fa..000000000 --- a/apps/web/pages/api/_moved/tasks/task-linked-issue.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { ITaskLinkedIssue, LinkedTaskIssue } from '@app/interfaces/ITask'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { createTaskLinkedIsssue, updateTaskLinkedIssue } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, tenantId, access_token } = await authenticatedGuard(req, res); - if (!user) return $res(); - - if (!['POST', 'PUT'].includes(req.method as string)) { - return res.status(405).json({ status: 'failed' }); - } - - if (req.method === 'PUT') { - const body = req.body as LinkedTaskIssue; - const response = await updateTaskLinkedIssue(body, access_token, tenantId); - - $res.json(response.data); - return; - } - - const body = req.body as ITaskLinkedIssue; - const response = await createTaskLinkedIsssue(body, access_token, tenantId); - - $res.json(response.data); -} diff --git a/apps/web/pages/api/_moved/tasks/team.ts b/apps/web/pages/api/_moved/tasks/team.ts deleted file mode 100644 index afd4ab9dc..000000000 --- a/apps/web/pages/api/_moved/tasks/team.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { getActiveTeamIdCookie } from '@app/helpers/cookies'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { createTaskRequest, getTeamTasksRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, tenantId, organizationId, access_token, projectId, teamId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - if (req.method === 'POST') { - const body: Record = req.body || {}; - - const title = body.title?.trim() || ''; - if (title.trim().length < 2) { - return res.status(400).json({ errors: { name: 'Invalid task name !' } }); - } - const activeTeam = getActiveTeamIdCookie({ req, res }); - - await createTaskRequest({ - bearer_token: access_token, - data: { - description: '', - status: 'open', - members: user?.employee?.id ? [{ id: user.employee.id }] : [], - teams: [ - { - id: activeTeam - } - ], - tags: [], - organizationId, - tenantId, - projectId, - estimate: 0, - ...body, - title // this must be called after ...body - } - }); - } - - const { data: tasks } = await getTeamTasksRequest({ - tenantId, - organizationId, - projectId, - teamId, - bearer_token: access_token - }); - - $res.status(200).json(tasks); -} diff --git a/apps/web/pages/api/_moved/timer/start.ts b/apps/web/pages/api/_moved/timer/start.ts deleted file mode 100644 index 78bf0c113..000000000 --- a/apps/web/pages/api/_moved/timer/start.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { TimerSource } from '@app/interfaces/ITimer'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { getTimerStatusRequest, startTimerRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { - $res, - user, - tenantId, - access_token, - organizationId, - taskId, - teamId: organizationTeamId - } = await authenticatedGuard(req, res); - if (!user) return $res(); - - await startTimerRequest( - { - tenantId, - organizationId, - taskId, - logType: 'TRACKED', - source: TimerSource.TEAMS, - tags: [], - organizationTeamId - }, - access_token - ); - - const { data: timerStatus } = await getTimerStatusRequest({ tenantId, organizationId }, access_token); - - return $res.json(timerStatus); -} diff --git a/apps/web/pages/api/_moved/timer/status.ts b/apps/web/pages/api/_moved/timer/status.ts deleted file mode 100644 index fd993a3dc..000000000 --- a/apps/web/pages/api/_moved/timer/status.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { getTimerStatusRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, tenantId, access_token, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { data } = await getTimerStatusRequest({ tenantId, organizationId }, access_token); - - $res.json(data); -} diff --git a/apps/web/pages/api/_moved/timer/stop.ts b/apps/web/pages/api/_moved/timer/stop.ts deleted file mode 100644 index 155c8ffb6..000000000 --- a/apps/web/pages/api/_moved/timer/stop.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* eslint-disable no-mixed-spaces-and-tabs */ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { getTimerStatusRequest, stopTimerRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, tenantId, access_token, organizationId, taskId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { source } = req.body; - await stopTimerRequest( - { - tenantId, - organizationId, - logType: 'TRACKED', - source: source, - tags: [], - // Task id is optional in case timer is already started in another source - ...(taskId - ? { - taskId - } - : {}) - }, - access_token - ); - - const { data: timerStatus } = await getTimerStatusRequest({ tenantId, organizationId }, access_token); - - return $res.json(timerStatus); -} diff --git a/apps/web/pages/api/_moved/timer/sync.ts b/apps/web/pages/api/_moved/timer/sync.ts deleted file mode 100644 index 84f501bd8..000000000 --- a/apps/web/pages/api/_moved/timer/sync.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { getTimerStatusRequest, syncTimeSlotRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, tenantId, access_token, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - if (req.method !== 'POST') { - $res.status(405).send({}); - return; - } - - const { source } = req.body; - await syncTimeSlotRequest( - { - tenantId, - organizationId, - logType: 'TRACKED', - source, - employeeId: user.employee.id, - duration: 5 - }, - access_token - ); - - const { data: timerStatus } = await getTimerStatusRequest({ tenantId, organizationId }, access_token); - - return $res.json(timerStatus); -} diff --git a/apps/web/pages/api/_moved/timer/timesheet/all-statistics-tasks.ts b/apps/web/pages/api/_moved/timer/timesheet/all-statistics-tasks.ts deleted file mode 100644 index a709522bf..000000000 --- a/apps/web/pages/api/_moved/timer/timesheet/all-statistics-tasks.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { tasksTimesheetStatisticsRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, tenantId, organizationId, access_token } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const { data } = await tasksTimesheetStatisticsRequest( - { - tenantId, - organizationId, - employeeIds: [], - defaultRange: 'false' - }, - access_token - ); - - return $res.json(data); -} diff --git a/apps/web/pages/api/_moved/timer/timesheet/index.ts b/apps/web/pages/api/_moved/timer/timesheet/index.ts deleted file mode 100644 index 53fd762c9..000000000 --- a/apps/web/pages/api/_moved/timer/timesheet/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user } = await authenticatedGuard(req, res); - if (!user) return $res(); -} diff --git a/apps/web/pages/api/_moved/timer/timesheet/statistics-tasks.ts b/apps/web/pages/api/_moved/timer/timesheet/statistics-tasks.ts deleted file mode 100644 index 205644d9d..000000000 --- a/apps/web/pages/api/_moved/timer/timesheet/statistics-tasks.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { tasksTimesheetStatisticsRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, tenantId, organizationId, access_token, taskId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const activeTask = req.query.activeTask; - let employeeId = req.query.employeeId as string | undefined; - employeeId = employeeId || user.employee?.id; - - if (activeTask && !taskId) { - return $res.json({ - global: [], - today: [] - }); - } - - const { data } = await tasksTimesheetStatisticsRequest( - { - tenantId, - organizationId, - employeeIds: employeeId ? [employeeId] : [], - defaultRange: 'false', - ...(activeTask && taskId ? { 'taskIds[0]': taskId } : {}) - }, - access_token - ); - - const { data: todayData } = await tasksTimesheetStatisticsRequest( - { - tenantId, - organizationId, - employeeIds: employeeId ? [employeeId] : [], - defaultRange: 'true', - ...(activeTask && taskId ? { 'taskIds[0]': taskId } : {}), - unitOfTime: 'day' - }, - access_token - ); - - return $res.json({ - global: data, - today: todayData - }); -} diff --git a/apps/web/pages/api/_moved/timer/toggle.ts b/apps/web/pages/api/_moved/timer/toggle.ts deleted file mode 100644 index d8e51dba1..000000000 --- a/apps/web/pages/api/_moved/timer/toggle.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { getTimerStatusRequest, stopTimerRequest, toggleTimerRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, tenantId, access_token, organizationId, taskId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - if (req.method !== 'POST') { - $res.status(405).send({}); - return; - } - - const { source } = req.body; - await toggleTimerRequest( - { - source, - logType: 'TRACKED', - tenantId, - taskId, - organizationId, - tags: [] - }, - access_token - ); - - await stopTimerRequest( - { - tenantId, - organizationId, - taskId, - logType: 'TRACKED', - source, - tags: [] - }, - access_token - ); - - const { data: timerStatus } = await getTimerStatusRequest({ tenantId, organizationId }, access_token); - - return $res.json(timerStatus); -} diff --git a/apps/web/pages/api/_moved/user/[id].ts b/apps/web/pages/api/_moved/user/[id].ts deleted file mode 100644 index dcf1a684d..000000000 --- a/apps/web/pages/api/_moved/user/[id].ts +++ /dev/null @@ -1,41 +0,0 @@ -import { IUser } from '@app/interfaces/IUserData'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { getTaskCreator, updateUserAvatarRequest } from '@app/services/server/requests'; -import { deleteUserRequest } from '@app/services/server/requests/user'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - const body = req.body as IUser; - const userId = req.query?.id; - switch (req.method) { - case 'GET': - return $res.json( - await getTaskCreator({ - userId: userId as string, - bearer_token: access_token - }) - ); - case 'PUT': - return $res.json( - await updateUserAvatarRequest( - { - data: body, - id: user.id as string, - tenantId - }, - access_token - ) - ); - case 'DELETE': - return $res.json( - await deleteUserRequest({ - id: user.id, - bearer_token: access_token, - tenantId - }) - ); - } -} diff --git a/apps/web/pages/api/_moved/user/me.ts b/apps/web/pages/api/_moved/user/me.ts deleted file mode 100644 index 9bb9b961b..000000000 --- a/apps/web/pages/api/_moved/user/me.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user } = await authenticatedGuard(req, res); - if (!user) return $res(); - - $res.json(user); -} diff --git a/apps/web/pages/api/_moved/user/reset.ts b/apps/web/pages/api/_moved/user/reset.ts deleted file mode 100644 index bce1795af..000000000 --- a/apps/web/pages/api/_moved/user/reset.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; - -import { resetUserRequest } from '@app/services/server/requests/user'; -import { NextApiRequest, NextApiResponse } from 'next'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - switch (req.method) { - case 'DELETE': - return $res.json( - await resetUserRequest({ - bearer_token: access_token, - tenantId - }) - ); - } -} diff --git a/apps/web/pages/api/auth/signin-workspace.ts b/apps/web/pages/api/auth/signin-workspace.ts index 25dbdd672..66ae2ffe9 100644 --- a/apps/web/pages/api/auth/signin-workspace.ts +++ b/apps/web/pages/api/auth/signin-workspace.ts @@ -59,7 +59,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) !acceptInviteRes.response.ok || acceptInviteRes.response.status === 401 || acceptInviteRes.response.status === 400 || - (acceptInviteRes.data as any).response?.statusCode + (acceptInviteRes?.data as any).response?.statusCode ) { return res.status(400).json({ errors: {