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/auth/_signin-workspace/route.ts b/apps/web/app/api/auth/_signin-workspace/route.ts new file mode 100644 index 000000000..5a4eafb5f --- /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/pages/api/auth/login.ts b/apps/web/app/api/auth/login/route.ts similarity index 88% rename from apps/web/pages/api/auth/login.ts rename to apps/web/app/api/auth/login/route.ts index e2c22b7a2..79e954e79 100644 --- a/apps/web/pages/api/auth/login.ts +++ b/apps/web/app/api/auth/login/route.ts @@ -9,16 +9,17 @@ import { verifyAuthCodeRequest, verifyInviteCodeRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; +import { NextResponse } from 'next/server'; -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const body = req.body as ILoginDataAPI; +export async function POST(req: Request) { + const res = new NextResponse(); + const body = (await req.json()) as unknown 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 }); + return NextResponse.json({ errors }); } /** @@ -40,7 +41,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) (authReq.data as any).status === 400 || (authReq.data as any).status === 401 ) { - return res.status(200).json({ + return NextResponse.json({ errors: { email: 'Authentication code or email address invalid' } @@ -50,7 +51,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) loginResponse = authReq.data; } catch (error) { // return notFound(res); - return res.status(200).json({ + return NextResponse.json({ errors: { email: 'Authentication code or email address invalid' } @@ -83,7 +84,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) acceptInviteRes.response.status === 400 || (acceptInviteRes.data as any).response?.statusCode ) { - return res.status(400).json({ + return NextResponse.json({ errors: { email: 'Authentication code or email address invalid' } @@ -94,7 +95,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) } if (!loginResponse) { - return res.status(400).json({ + return NextResponse.json({ errors: { email: 'Authentication code or email address invalid' } @@ -113,7 +114,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const organization = organizations?.items[0]; if (!organization) { - return res.status(400).json({ + return NextResponse.json({ errors: { email: 'Your account is not yet ready to be used on the Ever Teams Platform' } @@ -128,7 +129,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const team = teams.items[0]; if (!team) { - setNoTeamPopupShowCookie(true); + setNoTeamPopupShowCookie(true); } setAuthCookies( @@ -148,5 +149,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) res ); - res.status(200).json({ team, loginResponse }); + return NextResponse.json({ team, loginResponse }); } diff --git a/apps/web/pages/api/auth/meet/jwt.ts b/apps/web/app/api/auth/meet/jwt/route.ts similarity index 84% rename from apps/web/pages/api/auth/meet/jwt.ts rename to apps/web/app/api/auth/meet/jwt/route.ts index 06dddc445..40e5c6473 100644 --- a/apps/web/pages/api/auth/meet/jwt.ts +++ b/apps/web/app/api/auth/meet/jwt/route.ts @@ -3,10 +3,10 @@ import { MEET_DOMAIN, MEET_JWT_APP_ID, MEET_JWT_APP_SECRET } from '@app/constant // // getMeetJwtSessionCookie, // setMeetJwtSessionCookie, // } from '@app/helpers'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import jwt from 'jsonwebtoken'; -import { NextApiRequest, NextApiResponse } from 'next'; +import { NextResponse } from 'next/server'; const algo: jwt.SignOptions = { algorithm: 'HS256' }; type Params = { @@ -40,12 +40,13 @@ function generateToken(params: Params): string { return jwt.sign(payload, params.appkey, algo); } -export default async function handler(req: NextApiRequest, res: NextApiResponse) { +export async function GET(req: Request) { + const res = new NextResponse(); const { $res, user } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return $res('Unauthorized'); if (!MEET_JWT_APP_SECRET || !MEET_JWT_APP_ID || !MEET_DOMAIN) { - return $res.status(400).json('Invalid configuration !'); + return $res('Invalid configuration !'); } // Check if existing token from cookie is valid @@ -73,5 +74,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) // We don't use this cookie for now // setMeetJwtSessionCookie(new_token, { req, res }); - res.status(200).json({ token: new_token }); + return NextResponse.json({ token: new_token }); } diff --git a/apps/web/pages/api/auth/refresh.ts b/apps/web/app/api/auth/refresh/route.ts similarity index 63% rename from apps/web/pages/api/auth/refresh.ts rename to apps/web/app/api/auth/refresh/route.ts index d0dc4137e..13c4b1a81 100644 --- a/apps/web/pages/api/auth/refresh.ts +++ b/apps/web/app/api/auth/refresh/route.ts @@ -1,18 +1,16 @@ 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'; +import { NextResponse } from 'next/server'; -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - if (req.method !== 'POST') { - return res.status(405).send({}); - } +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) { - return res.status(401).json( + return NextResponse.json( hasErrors({ refresh_token: 'The refresh token must be provided on the request body' }) @@ -21,7 +19,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const { data } = await refreshTokenRequest(refresh_token); if (!data) { - return res.status(401); + return NextResponse.error(); } const { data: user } = await currentAuthenticatedUserRequest({ @@ -30,5 +28,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) setAccessTokenCookie(data.token, { res, req }); - res.status(200).json({ user, token: data.token }); + return NextResponse.json({ user, token: data.token }); } diff --git a/apps/web/pages/api/auth/register.ts b/apps/web/app/api/auth/register/route.ts similarity index 78% rename from apps/web/pages/api/auth/register.ts rename to apps/web/app/api/auth/register/route.ts index 55b40f051..ad0efada8 100644 --- a/apps/web/pages/api/auth/register.ts +++ b/apps/web/app/api/auth/register/route.ts @@ -11,44 +11,40 @@ import { 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'; +import { NextResponse } from 'next/server'; -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - if (req.method !== 'POST') { - return res.status(405).json({}); - } +export async function POST(req: Request) { + const url = new URL(req.url); + const res = new NextResponse(); - const appEmailConfirmationUrl = `${req.headers.origin}${VERIFY_EMAIL_CALLBACK_PATH}`; + const appEmailConfirmationUrl = `${url.origin}${VERIFY_EMAIL_CALLBACK_PATH}`; - const body = req.body as IRegisterDataAPI; + const body = (await req.json()) as unknown as IRegisterDataAPI; 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 }); + return NextResponse.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 NextResponse.json({ errors: { recaptcha: 'Invalid reCAPTCHA. Please try again' } }); + } } /** * Verify if the SMTP has been configured @@ -56,7 +52,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) // const hasSMTPConfig = validSMTPConfig(); // if (0 && hasSMTPConfig) { - // return res.status(400).json({ + // return NextResponse.json({ // status: 400, // message: 'Unable to find SMTP configuration', // }); @@ -145,5 +141,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) res ); - res.status(200).json({ loginRes, team, employee }); + return NextResponse.json({ loginRes, team, employee }); } diff --git a/apps/web/pages/api/auth/send-code.ts b/apps/web/app/api/auth/send-code/route.ts similarity index 52% rename from apps/web/pages/api/auth/send-code.ts rename to apps/web/app/api/auth/send-code/route.ts index 58c005446..861608981 100644 --- a/apps/web/pages/api/auth/send-code.ts +++ b/apps/web/app/api/auth/send-code/route.ts @@ -1,32 +1,29 @@ 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'; +import { NextResponse } from 'next/server'; -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}`; +export async function POST(req: Request) { + const url = new URL(req.url); + const callbackUrl = `${url.origin}${INVITE_CALLBACK_PATH}`; - const body = req.body as { email: string }; + const body = (await req.json()) as unknown as { email: string }; const { errors, valid: formValid } = authFormValidate(['email'], body as any); if (!formValid) { - return res.status(400).json({ errors }); + return NextResponse.json({ errors }); } const codeSendRes = await sendAuthCodeRequest(body.email, callbackUrl).catch(() => void 0); if (!codeSendRes) { - return res.status(400).json({ + return NextResponse.json({ errors: { email: "We couldn't find any account associated to this email" } }); } - res.status(200).json(codeSendRes.data); + return NextResponse.json(codeSendRes.data); } diff --git a/apps/web/pages/api/auth/signin-email-confirm.ts b/apps/web/app/api/auth/signin-email-confirm/route.ts similarity index 83% rename from apps/web/pages/api/auth/signin-email-confirm.ts rename to apps/web/app/api/auth/signin-email-confirm/route.ts index 49cd61cb9..c7ed9cba7 100644 --- a/apps/web/pages/api/auth/signin-email-confirm.ts +++ b/apps/web/app/api/auth/signin-email-confirm/route.ts @@ -8,20 +8,18 @@ import { signInEmailConfirmRequest, verifyInviteCodeRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; +import { NextResponse } from 'next/server'; -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - if (req.method !== 'POST') { - return res.status(405).json({ status: 'fail' }); - } +export async function POST(req: Request) { + const res = new NextResponse(); - const body = req.body 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); if (!formValid) { - return res.status(400).json({ errors }); + return NextResponse.json({ errors }); } // Accept Invite Flow Start @@ -55,9 +53,9 @@ 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({ + return NextResponse.json({ errors: { email: 'Authentication code or email address invalid' } @@ -66,7 +64,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) loginResponse = acceptInviteRes.data; if (!loginResponse) { - return res.status(400).json({ + return NextResponse.json({ errors: { email: 'Authentication code or email address invalid' } @@ -87,7 +85,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const organization = organizations?.items[0]; if (!organization) { - return res.status(400).json({ + return NextResponse.json({ errors: { email: 'Your account is not yet ready to be used on the Ever Teams Platform' } @@ -118,7 +116,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) req, res ); - return res.status(200).json({ team, loginResponse }); + return NextResponse.json({ team, loginResponse }); } // Accept Invite Flow End @@ -127,5 +125,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) email: body.email }); - res.json(data); + 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..b7f7c0968 --- /dev/null +++ b/apps/web/app/api/auth/signin-email/route.ts @@ -0,0 +1,33 @@ +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 = (await req.json()) as unknown as { email: string }; + + const { errors, valid: formValid } = authFormValidate(['email'], body as any); + + if (!formValid) { + return NextResponse.json({ errors }, { status: 400 }); + } + + 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" + } + }, + { status: 400 } + ); + } + + return NextResponse.json(codeSendRes.data); +} diff --git a/apps/web/pages/api/auth/verify/code.ts b/apps/web/app/api/auth/verify/code/route.ts similarity index 58% rename from apps/web/pages/api/auth/verify/code.ts rename to apps/web/app/api/auth/verify/code/route.ts index 410e15cd4..ffbecc257 100644 --- a/apps/web/pages/api/auth/verify/code.ts +++ b/apps/web/app/api/auth/verify/code/route.ts @@ -1,23 +1,20 @@ import { authFormValidate } from '@app/helpers/validations'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; 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' }); - } +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(); + if (!user) return $res('unauthorized'); - const body = req.body as { code: string }; + const body = (await req.json()) as unknown as { code: string }; const { errors, valid: formValid } = authFormValidate(['code'], body as any); if (!formValid) { - return res.status(400).json({ errors }); + return NextResponse.json({ errors }); } const { data } = await verifyUserEmailByCodeRequest({ @@ -27,5 +24,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) email: user.email }); - $res.json(data); + return $res(data); } diff --git a/apps/web/pages/api/auth/verify/resend-link.ts b/apps/web/app/api/auth/verify/resend-link/route.ts similarity index 53% rename from apps/web/pages/api/auth/verify/resend-link.ts rename to apps/web/app/api/auth/verify/resend-link/route.ts index 69a85d3e8..125acf18d 100644 --- a/apps/web/pages/api/auth/verify/resend-link.ts +++ b/apps/web/app/api/auth/verify/resend-link/route.ts @@ -1,18 +1,17 @@ import { VERIFY_EMAIL_CALLBACK_PATH } from '@app/constants'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { resentVerifyUserLinkRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; +import { NextResponse } from 'next/server'; -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - if (req.method !== 'POST') { - return res.status(405).json({ status: 'fail' }); - } +export async function POST(req: Request) { + const res = new NextResponse(); + const url = new URL(req.url); - const appEmailConfirmationUrl = `${req.headers.origin}${VERIFY_EMAIL_CALLBACK_PATH}`; + const appEmailConfirmationUrl = `${url.origin}${VERIFY_EMAIL_CALLBACK_PATH}`; const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return $res('Unauthorized'); const { data } = await resentVerifyUserLinkRequest({ bearer_token: access_token, @@ -21,5 +20,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) appEmailConfirmationUrl }); - $res.json(data); + return $res(data); } diff --git a/apps/web/pages/api/auth/verify/token.ts b/apps/web/app/api/auth/verify/token/route.ts similarity index 50% rename from apps/web/pages/api/auth/verify/token.ts rename to apps/web/app/api/auth/verify/token/route.ts index d8327ee81..6d3df80af 100644 --- a/apps/web/pages/api/auth/verify/token.ts +++ b/apps/web/app/api/auth/verify/token/route.ts @@ -1,18 +1,14 @@ import { authFormValidate } from '@app/helpers/validations'; import { verifyUserEmailByTokenRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; +import { NextResponse } from 'next/server'; -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 }; +export async function POST(req: Request) { + const body = (await req.json()) as unknown as { email: string; token: string }; const { errors, valid: formValid } = authFormValidate(['email', 'token'], body as any); if (!formValid) { - return res.status(400).json({ errors }); + return NextResponse.json({ errors }); } const { data } = await verifyUserEmailByTokenRequest({ @@ -20,5 +16,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) email: body.email }); - res.status(200).json(data); + return NextResponse.json(data); } 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/pages/api/employee/working.ts b/apps/web/app/api/employee/working/route.ts similarity index 58% rename from apps/web/pages/api/employee/working.ts rename to apps/web/app/api/employee/working/route.ts index c0b44321a..be5643a38 100644 --- a/apps/web/pages/api/employee/working.ts +++ b/apps/web/app/api/employee/working/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 { getOrganizationEmployees } 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, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); const { data } = await getOrganizationEmployees(access_token, tenantId, organizationId); - $res.json(data); + $res(data); } diff --git a/apps/web/pages/api/integration-tenant/[id].ts b/apps/web/app/api/integration-tenant/[id]/route.ts similarity index 53% rename from apps/web/pages/api/integration-tenant/[id].ts rename to apps/web/app/api/integration-tenant/[id]/route.ts index 01ea6e4a3..5ad00af5f 100644 --- a/apps/web/pages/api/integration-tenant/[id].ts +++ b/apps/web/app/api/integration-tenant/[id]/route.ts @@ -1,20 +1,17 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { deleteIntegrationTenantRequest } 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 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 $res(); + if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); - const { id } = req.query; - - if (req.method !== 'DELETE') { - return $res.status(405).json({}); - } + const { id } = params; if (id) { const response = await deleteIntegrationTenantRequest(id as string, tenantId, organizationId, access_token); - return $res.status(200).json(response); + return $res(response); } } diff --git a/apps/web/pages/api/integration-tenant/remember/state/index.ts b/apps/web/app/api/integration-tenant/remember/state/route.ts similarity index 51% rename from apps/web/pages/api/integration-tenant/remember/state/index.ts rename to apps/web/app/api/integration-tenant/remember/state/route.ts index ac8014d53..a0c6b021c 100644 --- a/apps/web/pages/api/integration-tenant/remember/state/index.ts +++ b/apps/web/app/api/integration-tenant/remember/state/route.ts @@ -1,16 +1,14 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { getIntegrationTenantRequest } 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, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); - const { name } = req.query; - - if (req.method !== 'GET') { - return $res.status(405).json({}); - } + const { searchParams } = new URL(req.url); + const { name } = searchParams as unknown as { name: string }; const response = await getIntegrationTenantRequest( { @@ -21,5 +19,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) access_token ); - return $res.status(200).json(response); + return $res(response); } diff --git a/apps/web/pages/api/integration/github/install.ts b/apps/web/app/api/integration/github/install/route.ts similarity index 52% rename from apps/web/pages/api/integration/github/install.ts rename to apps/web/app/api/integration/github/install/route.ts index 8c251468b..c6270ae1e 100644 --- a/apps/web/pages/api/integration/github/install.ts +++ b/apps/web/app/api/integration/github/install/route.ts @@ -1,16 +1,13 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { installGitHubIntegration } 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, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return NextResponse.json({}, { status: 401 }); - const { installation_id, setup_action } = req.body; - - if (req.method !== 'POST') { - return $res.status(405).json({}); - } + const { installation_id, setup_action } = await req.json(); const response = await installGitHubIntegration( { @@ -22,5 +19,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) access_token ); - return $res.status(200).json(response); + return $res(response); } diff --git a/apps/web/pages/api/integration/github/metadata.ts b/apps/web/app/api/integration/github/metadata/route.ts similarity index 54% rename from apps/web/pages/api/integration/github/metadata.ts rename to apps/web/app/api/integration/github/metadata/route.ts index c3c0fb866..c136907a1 100644 --- a/apps/web/pages/api/integration/github/metadata.ts +++ b/apps/web/app/api/integration/github/metadata/route.ts @@ -1,16 +1,15 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { getGithubIntegrationMetadataRequest } 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, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return NextResponse.json({}, { status: 401 }); - if (req.method !== 'GET') { - return $res.status(405).json({}); - } + const { searchParams } = new URL(req.url); - const { integrationId } = req.query; + const { integrationId } = searchParams as unknown as { integrationId: string }; const response = await getGithubIntegrationMetadataRequest( { @@ -21,5 +20,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) access_token ); - return $res.status(200).json(response); + return $res(response); } diff --git a/apps/web/pages/api/integration/github/oauth.ts b/apps/web/app/api/integration/github/oauth/route.ts similarity index 52% rename from apps/web/pages/api/integration/github/oauth.ts rename to apps/web/app/api/integration/github/oauth/route.ts index 3062d276b..c6e543aa1 100644 --- a/apps/web/pages/api/integration/github/oauth.ts +++ b/apps/web/app/api/integration/github/oauth/route.ts @@ -1,16 +1,13 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { oAuthEndpointAuthorization } 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, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return NextResponse.json({}, { status: 401 }); - const { installation_id, setup_action, code } = req.body; - - if (req.method !== 'POST') { - return $res.status(405).json({}); - } + const { installation_id, setup_action, code } = await req.json(); const response = await oAuthEndpointAuthorization( { @@ -23,5 +20,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) access_token ); - return $res.status(200).json(response); + return $res(response); } diff --git a/apps/web/pages/api/integration/github/repositories.ts b/apps/web/app/api/integration/github/repositories/route.ts similarity index 54% rename from apps/web/pages/api/integration/github/repositories.ts rename to apps/web/app/api/integration/github/repositories/route.ts index e0e455c41..6e9628caa 100644 --- a/apps/web/pages/api/integration/github/repositories.ts +++ b/apps/web/app/api/integration/github/repositories/route.ts @@ -1,16 +1,15 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { getGithubIntegrationRepositoriesRequest } 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, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return NextResponse.json({}, { status: 401 }); - if (req.method !== 'GET') { - return $res.status(405).json({}); - } + const { searchParams } = new URL(req.url); - const { integrationId } = req.query; + const { integrationId } = searchParams as unknown as { integrationId: string }; const response = await getGithubIntegrationRepositoriesRequest( { @@ -21,5 +20,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) access_token ); - return $res.status(200).json(response); + return $res(response); } diff --git a/apps/web/pages/api/integration/github/repository/sync.ts b/apps/web/app/api/integration/github/repository/sync/route.ts similarity index 53% rename from apps/web/pages/api/integration/github/repository/sync.ts rename to apps/web/app/api/integration/github/repository/sync/route.ts index 8b860bcfa..25735cd72 100644 --- a/apps/web/pages/api/integration/github/repository/sync.ts +++ b/apps/web/app/api/integration/github/repository/sync/route.ts @@ -1,23 +1,22 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { projectRepositorySyncRequest } 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, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return NextResponse.json({}, { status: 401 }); - if (req.method !== 'POST') { - return $res.status(405).json({}); - } + const body = await req.json(); const response = await projectRepositorySyncRequest( { - ...req.body, + ...body, tenantId, organizationId }, access_token ); - return $res.status(200).json(response); + return $res(response); } diff --git a/apps/web/pages/api/integration/types/index.ts b/apps/web/app/api/integration/types/route.ts similarity index 51% rename from apps/web/pages/api/integration/types/index.ts rename to apps/web/app/api/integration/types/route.ts index 07577464e..dc7e8b44f 100644 --- a/apps/web/pages/api/integration/types/index.ts +++ b/apps/web/app/api/integration/types/route.ts @@ -1,14 +1,11 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { getIntegrationTypesRequest } 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, access_token, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); - - if (req.method !== 'GET') { - return $res.status(405).json({}); - } + if (!user) return NextResponse.json({}, { status: 401 }); const response = await getIntegrationTypesRequest( { @@ -17,5 +14,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) access_token ); - return $res.status(200).json(response); + 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/pages/api/invite/emails.ts b/apps/web/app/api/invite/emails/route.ts similarity index 75% rename from apps/web/pages/api/invite/emails.ts rename to apps/web/app/api/invite/emails/route.ts index 1722a54e1..0afd5221b 100644 --- a/apps/web/pages/api/invite/emails.ts +++ b/apps/web/app/api/invite/emails/route.ts @@ -1,26 +1,29 @@ 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 { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { getEmployeeRoleRequest, getTeamInvitationsRequest, inviteByEmailsRequest } 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, organizationId, access_token, teamId, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return NextResponse.json({ errors: 'Unauthorized' }, { status: 401 }); - const callbackUrl = `${req.headers.origin}${INVITE_CALLBACK_PATH}`; + const { origin } = new URL(req.url); - const body = req.body as IInviteRequest; + const callbackUrl = `${origin}${INVITE_CALLBACK_PATH}`; + + const body = (await req.json()) as IInviteRequest; const { errors, isValid: formValid } = validateForm(['email', 'name'], body); if (!formValid) { - return res.status(400).json({ errors }); + return NextResponse.json({ errors }, { status: 400 }); } const { data: employeeRole } = await getEmployeeRoleRequest({ @@ -62,5 +65,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) access_token ); - $res.status(200).json(data); + $res(data); } diff --git a/apps/web/pages/api/invite/resend.ts b/apps/web/app/api/invite/resend/route.ts similarity index 62% rename from apps/web/pages/api/invite/resend.ts rename to apps/web/app/api/invite/resend/route.ts index a934c2d79..38887c4d8 100644 --- a/apps/web/pages/api/invite/resend.ts +++ b/apps/web/app/api/invite/resend/route.ts @@ -1,21 +1,24 @@ 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 { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { resendInvitationEmailRequest } 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, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return NextResponse.json({}, { status: 401 }); - const callbackUrl = `${req.headers.origin}${INVITE_CALLBACK_PATH}`; + const url = new URL(req.url); - const body = req.body as { inviteId: string }; + 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 res.status(400).json({ errors }); + return NextResponse.json({ errors }, { status: 400 }); } const { data } = await resendInvitationEmailRequest( @@ -29,5 +32,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) access_token ); - $res.json(data); + $res(data); } diff --git a/apps/web/pages/api/invite/index.ts b/apps/web/app/api/invite/route.ts similarity index 63% rename from apps/web/pages/api/invite/index.ts rename to apps/web/app/api/invite/route.ts index 70085e3b4..7ffec62c9 100644 --- a/apps/web/pages/api/invite/index.ts +++ b/apps/web/app/api/invite/route.ts @@ -1,10 +1,11 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { getTeamInvitationsRequest } 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, access_token, tenantId, organizationId, teamId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return NextResponse.json({ error: 'Unauthorized' }); const { data } = await getTeamInvitationsRequest( { @@ -16,5 +17,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) access_token ); - $res.status(200).json(data); + $res(data); } diff --git a/apps/web/pages/api/invite/validate-by-code.ts b/apps/web/app/api/invite/validate-by-code/route.ts similarity index 58% rename from apps/web/pages/api/invite/validate-by-code.ts rename to apps/web/app/api/invite/validate-by-code/route.ts index a1440c109..5338481c2 100644 --- a/apps/web/pages/api/invite/validate-by-code.ts +++ b/apps/web/app/api/invite/validate-by-code/route.ts @@ -2,18 +2,18 @@ import { validateForm } from '@app/helpers/validations'; import { IInviteVerifyCode } from '@app/interfaces/IInvite'; import { verifyInviteCodeRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; +import { NextResponse } from 'next/server'; -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const body = req.body as IInviteVerifyCode; +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 res.status(400).json({ errors }); + return NextResponse.json({ errors }, { status: 400 }); } const { data } = await verifyInviteCodeRequest(body); - res.status(200).json(data); + NextResponse.json(data, { status: 200 }); } 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/pages/api/languages/index.ts b/apps/web/app/api/languages/route.ts similarity index 50% rename from apps/web/pages/api/languages/index.ts rename to apps/web/app/api/languages/route.ts index 7cfc8b503..bf2e8e31b 100644 --- a/apps/web/pages/api/languages/index.ts +++ b/apps/web/app/api/languages/route.ts @@ -1,19 +1,17 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { getLanguageListRequest } 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, access_token, tenantId } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); const par = { is_system: user.role.isSystem as boolean, tenantId }; - switch (req.method) { - case 'GET': - return $res.json(await getLanguageListRequest(par, access_token)); - } + return $res(await getLanguageListRequest(par, access_token)); } 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/pages/api/organization-projects/setting/[id].ts b/apps/web/app/api/organization-projects/setting/[id]/route.ts similarity index 53% rename from apps/web/pages/api/organization-projects/setting/[id].ts rename to apps/web/app/api/organization-projects/setting/[id]/route.ts index e4a151b68..93c6816d2 100644 --- a/apps/web/pages/api/organization-projects/setting/[id].ts +++ b/apps/web/app/api/organization-projects/setting/[id]/route.ts @@ -1,20 +1,22 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { editOrganizationProjectsSettingsRequest } 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 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(); + if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); - const { id } = req.query; + const { id } = params; + const body = await req.json(); switch (req.method) { case 'PUT': - return $res.json( + return $res( await editOrganizationProjectsSettingsRequest({ bearer_token: access_token, id, - datas: req.body, + datas: body, tenantId }) ); 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..fddf8fbd6 --- /dev/null +++ b/apps/web/app/api/organization-team-employee/[id]/active-task/route.ts @@ -0,0 +1,24 @@ +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; + + if (id) { + return $res( + await updateOrganizationTeamEmployeeActiveTaskRequest({ + id: id as string, + bearer_token: access_token, + tenantId, + body + }) + ); + } +} 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 new file mode 100644 index 000000000..d649458b3 --- /dev/null +++ b/apps/web/app/api/organization-team-join/[id]/[action]/route.ts @@ -0,0 +1,23 @@ +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, { 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 { id, action } = params; + + 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/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/pages/api/organization-team/index.ts b/apps/web/app/api/organization-team/route.ts similarity index 54% rename from apps/web/pages/api/organization-team/index.ts rename to apps/web/app/api/organization-team/route.ts index f53899539..047fb5e90 100644 --- a/apps/web/pages/api/organization-team/index.ts +++ b/apps/web/app/api/organization-team/route.ts @@ -1,23 +1,24 @@ import { IUserOrganization } from '@app/interfaces/IOrganization'; import { IOrganizationTeamList } from '@app/interfaces/IOrganizationTeam'; -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { createOrganizationTeamRequest, getAllOrganizationTeamRequest, getUserOrganizationsRequest } 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, access_token, tenantId, organizationId } = await authenticatedGuard(req, res); - if (!user) return $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 res.status(400).json({ errors: { name: 'Invalid team name !' } }); + return NextResponse.json({ errors: { name: 'Invalid team name !' } }, { status: 400 }); } await createOrganizationTeamRequest( { @@ -60,5 +61,43 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) ); }); - return $res.json(teams); + 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/app/api/public/team/[profileLink]/[teamId]/route.ts b/apps/web/app/api/public/team/[profileLink]/[teamId]/route.ts new file mode 100644 index 000000000..ae8430811 --- /dev/null +++ b/apps/web/app/api/public/team/[profileLink]/[teamId]/route.ts @@ -0,0 +1,27 @@ +import { + getPublicOrganizationTeamMiscDataRequest, + getPublicOrganizationTeamRequest +} from '@app/services/server/requests/public-organization-team'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request, { params }: { params: { profileLink: string; teamId: string } }) { + const { searchParams } = new URL(req.url); + + const { profileLink, teamId, } = params; + const { type } = searchParams as unknown as {type: string;}; + + if (type === 'misc') { + return NextResponse.json( + await getPublicOrganizationTeamMiscDataRequest({ + profileLink: profileLink, + teamId + }) + ); + } + return NextResponse.json( + await getPublicOrganizationTeamRequest({ + profileLink: profileLink, + teamId + }) + ); +} 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..4dea0195c --- /dev/null +++ b/apps/web/app/api/role-permissions/[id]/route.ts @@ -0,0 +1,41 @@ +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, { params }: { params: { id: string } }) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('unauthorized'); + + const { id } = params; + + return $res( + ( + await getRolePermissionsRequest({ + bearer_token: access_token, + tenantId, + roleId: id as string + }) + ).data + ); +} + +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..1654f262f --- /dev/null +++ b/apps/web/app/api/roles/[id]/route.ts @@ -0,0 +1,38 @@ +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, { params }: { params: { id: string } }) { + const res = new NextResponse(); + + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('unauthorized'); + + const { id } = params + + return $res( + await 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/app/api/tags/[id]/route.ts b/apps/web/app/api/tags/[id]/route.ts new file mode 100644 index 000000000..cc2703a2d --- /dev/null +++ b/apps/web/app/api/tags/[id]/route.ts @@ -0,0 +1,40 @@ +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, { params }: { params: { id: string } }) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return NextResponse.json({ error: 'unauthorized' }, { status: 401 }); + + const { id } = params; + + return $res( + await deleteTaskLabelsRequest({ + id, + bearer_token: access_token, + tenantId + }) + ); +} + +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 } = params; + + 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..c86ebf135 --- /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: 'Unauthorized' }, { 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: 'Unauthorized' }, { status: 401 }); + + return $res(await createLabelsRequest(body, access_token, body?.tenantId)); +} 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..36396543f --- /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, { params }: { params: { id: string } }) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + + const { id } = params; + + const datas = (await req.json()) as unknown as ITaskPrioritiesCreate; + return $res( + await editTaskPrioritiesRequest({ + id, + datas, + bearer_token: access_token, + tenantId + }) + ); +} + +export async function DELETE(req: Request, { params }: { params: { id: string } }) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + + const { id } = params; + + return $res( + await deleteTaskPrioritiesRequest({ + id, + bearer_token: access_token, + tenantId + }) + ); +} 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..28147c244 --- /dev/null +++ b/apps/web/app/api/task-priorities/route.ts @@ -0,0 +1,34 @@ +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 { 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 = (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 new file mode 100644 index 000000000..86e9f972f --- /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, { params }: { params: { id: string } }) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + + const { id } = params; + + const datas = (await req.json()) as unknown as ITaskRelatedIssueTypeCreate; + return $res( + await editTaskRelatedIssueTypeRequest({ + id, + datas, + bearer_token: access_token, + tenantId + }) + ); +} + +export async function DELETE(req: Request, { params }: { params: { id: string } }) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + + const { id } = params; + + return $res( + await deleteTaskRelatedIssueTypeRequest({ + id, + bearer_token: access_token, + tenantId + }) + ); +} 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..d2b791d4d --- /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 = (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 new file mode 100644 index 000000000..d54aba1a0 --- /dev/null +++ b/apps/web/app/api/task-sizes/[id]/route.ts @@ -0,0 +1,40 @@ +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, { params }: { params: { id: string } }) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { id } = params + + const datas = (await req.json()) as unknown as ITaskSizesCreate; + return $res( + await editTaskSizesRequest({ + id, + datas, + 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 $res('Unauthorized'); + + const { id } = params + + 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..30d9381e8 --- /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 = (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 new file mode 100644 index 000000000..64e656609 --- /dev/null +++ b/apps/web/app/api/task-statuses/[id]/route.ts @@ -0,0 +1,40 @@ +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, { params }: { params: { id: string } }) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { id } = params; + + const datas = (await req.json()) as unknown as ITaskStatusCreate; + return $res( + await editTaskStatusRequest({ + id, + datas, + 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 $res('Unauthorized'); + + const { id } = params; + + 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..8910dd1e6 --- /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 = (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 new file mode 100644 index 000000000..fb78de3c8 --- /dev/null +++ b/apps/web/app/api/task-versions/[id]/route.ts @@ -0,0 +1,40 @@ +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, { params }: { params: { id: string } }) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + + if (!user) return $res('Unauthorized'); + + const { id } = params; + + const datas = (await req.json()) as unknown as ITaskVersionCreate; + return $res( + await editTaskVersionRequest({ + id, + datas, + 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 $res('Unauthorized'); + + const { id } = params; + + 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..a680437be --- /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 = (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 new file mode 100644 index 000000000..6c62f0a9b --- /dev/null +++ b/apps/web/app/api/tasks/[id]/route.ts @@ -0,0 +1,55 @@ +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, { 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 { id: taskId } = params; + + return $res( + await getTaskByIdRequest({ + taskId: taskId as string, + tenantId, + organizationId, + bearer_token: access_token + }) + ); +} + +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, + res + ); + if (!user) return $res('Unauthorized'); + + const { id: taskId } = params; + const body = (await req.json()) 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 + }); + + 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 new file mode 100644 index 000000000..4f2b8eb82 --- /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, { 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} = params + const { organizationTeamId } = searchParams as unknown as { + organizationTeamId: string; + }; + + return $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..64b3c5aa7 --- /dev/null +++ b/apps/web/app/api/tasks/task-linked-issue/route.ts @@ -0,0 +1,26 @@ +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 = (await req.json()) as unknown as ITaskLinkedIssue; + const response = await createTaskLinkedIsssue(body, access_token, tenantId); + + return $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 = (await req.json()) as unknown as LinkedTaskIssue; + const response = await updateTaskLinkedIssue(body, access_token, tenantId); + + return $res(response.data); +} 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..a7fdaf055 --- /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 = (await req.json()) || {}; + + 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 + }); + + return $res(tasks); +} diff --git a/apps/web/pages/api/timer/start.ts b/apps/web/app/api/timer/start/route.ts similarity index 72% rename from apps/web/pages/api/timer/start.ts rename to apps/web/app/api/timer/start/route.ts index 78bf0c113..175421893 100644 --- a/apps/web/pages/api/timer/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 async function POST(req: Request) { + const res = new NextResponse(); const { $res, user, @@ -13,7 +14,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) taskId, teamId: organizationTeamId } = await authenticatedGuard(req, res); - if (!user) return $res(); + console.log({ user, tenantId, taskId}) + if (!user) return $res('Unauthorized'); await startTimerRequest( { @@ -30,5 +32,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/pages/api/timer/status.ts b/apps/web/app/api/timer/status/route.ts similarity index 61% rename from apps/web/pages/api/timer/status.ts rename to apps/web/app/api/timer/status/route.ts index fd993a3dc..e4a19c36b 100644 --- a/apps/web/pages/api/timer/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); + return $res(data); } diff --git a/apps/web/pages/api/timer/stop.ts b/apps/web/app/api/timer/stop/route.ts similarity index 69% rename from apps/web/pages/api/timer/stop.ts rename to apps/web/app/api/timer/stop/route.ts index 155c8ffb6..d8aae0900 100644 --- a/apps/web/pages/api/timer/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 = (await req.json()) 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/pages/api/timer/sync.ts b/apps/web/app/api/timer/sync/route.ts similarity index 62% rename from apps/web/pages/api/timer/sync.ts rename to apps/web/app/api/timer/sync/route.ts index 84f501bd8..6d36ec3ac 100644 --- a/apps/web/pages/api/timer/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 = (await req.json()) 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); } diff --git a/apps/web/pages/api/timer/timesheet/all-statistics-tasks.ts b/apps/web/app/api/timer/timesheet/all-statistics-tasks/route.ts similarity index 65% rename from apps/web/pages/api/timer/timesheet/all-statistics-tasks.ts rename to apps/web/app/api/timer/timesheet/all-statistics-tasks/route.ts index a709522bf..824fa83dc 100644 --- a/apps/web/pages/api/timer/timesheet/all-statistics-tasks.ts +++ b/apps/web/app/api/timer/timesheet/all-statistics-tasks/route.ts @@ -1,10 +1,11 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { tasksTimesheetStatisticsRequest } 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, organizationId, access_token } = await authenticatedGuard(req, res); - if (!user) return $res(); + if (!user) return $res('Unauthorized'); const { data } = await tasksTimesheetStatisticsRequest( { @@ -16,5 +17,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) access_token ); - return $res.json(data); + 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..4ab1a8c61 --- /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 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/pages/api/timer/timesheet/statistics-tasks.ts b/apps/web/app/api/timer/timesheet/statistics-tasks/route.ts similarity index 69% rename from apps/web/pages/api/timer/timesheet/statistics-tasks.ts rename to apps/web/app/api/timer/timesheet/statistics-tasks/route.ts index 205644d9d..0883d18bd 100644 --- a/apps/web/pages/api/timer/timesheet/statistics-tasks.ts +++ b/apps/web/app/api/timer/timesheet/statistics-tasks/route.ts @@ -1,17 +1,21 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { tasksTimesheetStatisticsRequest } from '@app/services/server/requests'; -import { NextApiRequest, NextApiResponse } from 'next'; +import { NextResponse } from 'next/server'; + +export async function GET(req: Request) { + const res = new NextResponse(); + const { searchParams } = new URL(req.url); -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(); + if (!user) return $res('unauthorized'); - const activeTask = req.query.activeTask; - let employeeId = req.query.employeeId as string | undefined; + 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.json({ + return $res({ global: [], today: [] }); @@ -40,7 +44,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) access_token ); - return $res.json({ + return $res({ global: data, today: todayData }); diff --git a/apps/web/pages/api/timer/toggle.ts b/apps/web/app/api/timer/toogle/route.ts similarity index 67% rename from apps/web/pages/api/timer/toggle.ts rename to apps/web/app/api/timer/toogle/route.ts index d8e51dba1..63a380aac 100644 --- a/apps/web/pages/api/timer/toggle.ts +++ b/apps/web/app/api/timer/toogle/route.ts @@ -1,17 +1,15 @@ -import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard'; +import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; import { getTimerStatusRequest, stopTimerRequest, toggleTimerRequest } 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(''); - if (req.method !== 'POST') { - $res.status(405).send({}); - return; - } + const body = (await req.json()) as unknown as { source: any }; + const { source } = body; - const { source } = req.body; await toggleTimerRequest( { source, @@ -38,5 +36,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/user/[id]/route.ts b/apps/web/app/api/user/[id]/route.ts new file mode 100644 index 000000000..e0aab649a --- /dev/null +++ b/apps/web/app/api/user/[id]/route.ts @@ -0,0 +1,55 @@ +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, { params }: { params: { id: string } }) { + const res = new NextResponse(); + + const { $res, user, access_token } = await authenticatedGuard(req, res); + if (!user) return $res('Unauthorized'); + + const { id: userId } = params; + return $res( + 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('Unauthorized'); + + const body = (await req.json()) as unknown as IUser; + + return $res( + 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('Unauthorized'); + + return $res( + await deleteUserRequest({ + id: user.id, + bearer_token: access_token, + tenantId + }) + ); +} 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..22148570a --- /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 async function GET(req: Request) { + const res = new NextResponse(); + const { $res, user } = await authenticatedGuard(req, res); + if (!user) return $res('Unauthorized'); + + return $res(user); +} diff --git a/apps/web/app/api/user/reset/route.ts b/apps/web/app/api/user/reset/route.ts new file mode 100644 index 000000000..fc6c55b49 --- /dev/null +++ b/apps/web/app/api/user/reset/route.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 async function DELETE(req: Request) { + const res = new NextResponse(); + const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res); + if (!user) return $res('Unauthorized'); + + return $res( + 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..cbd88cb28 --- /dev/null +++ b/apps/web/app/services/server/guards/authenticated-guard-app.ts @@ -0,0 +1,42 @@ +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 { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + $res: (data: any) => NextResponse.json({ statusCode: 401, message: data }), + user: null + }; + } + + return { + $res: (data: any) => NextResponse.json(data), + user: r_res.data, + access_token: access_token as string, + tenantId, + organizationId, + teamId, + taskId, + projectId + }; +} 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/pages/api/auth/signin-email.ts b/apps/web/pages/api/auth/signin-email.ts deleted file mode 100644 index 1ad9c2ee9..000000000 --- a/apps/web/pages/api/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/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: { diff --git a/apps/web/pages/api/email-reset/request-change-email.ts b/apps/web/pages/api/email-reset/request-change-email.ts deleted file mode 100644 index cf6c4b585..000000000 --- a/apps/web/pages/api/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/email-reset/verify-change-email.ts b/apps/web/pages/api/email-reset/verify-change-email.ts deleted file mode 100644 index aa7ab23e6..000000000 --- a/apps/web/pages/api/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/invite/[id].ts b/apps/web/pages/api/invite/[id].ts deleted file mode 100644 index 4d45eaabb..000000000 --- a/apps/web/pages/api/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/issue-types/[id].ts b/apps/web/pages/api/issue-types/[id].ts deleted file mode 100644 index d4068a393..000000000 --- a/apps/web/pages/api/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/issue-types/index.tsx b/apps/web/pages/api/issue-types/index.tsx deleted file mode 100644 index cca758a0f..000000000 --- a/apps/web/pages/api/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/organization-projects/[id].ts b/apps/web/pages/api/organization-projects/[id].ts deleted file mode 100644 index 20003fcd2..000000000 --- a/apps/web/pages/api/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/organization-team-employee/[id]/active-task.ts b/apps/web/pages/api/organization-team-employee/[id]/active-task.ts deleted file mode 100644 index 37f50e021..000000000 --- a/apps/web/pages/api/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/organization-team-employee/[id]/index.tsx b/apps/web/pages/api/organization-team-employee/[id]/index.tsx deleted file mode 100644 index 3893a0ade..000000000 --- a/apps/web/pages/api/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/organization-team-join/[id]/[action].ts b/apps/web/pages/api/organization-team-join/[id]/[action].ts deleted file mode 100644 index 0b6d58390..000000000 --- a/apps/web/pages/api/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/organization-team-join/index.ts b/apps/web/pages/api/organization-team-join/index.ts deleted file mode 100644 index c44d131c9..000000000 --- a/apps/web/pages/api/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/organization-team-join/resend-code.ts b/apps/web/pages/api/organization-team-join/resend-code.ts deleted file mode 100644 index 6cc4b8eed..000000000 --- a/apps/web/pages/api/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/organization-team-join/validate.ts b/apps/web/pages/api/organization-team-join/validate.ts deleted file mode 100644 index 6ebca1ce4..000000000 --- a/apps/web/pages/api/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/organization-team/[id].ts b/apps/web/pages/api/organization-team/[id].ts deleted file mode 100644 index d81aa5477..000000000 --- a/apps/web/pages/api/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/organization-team/employee/[id].ts b/apps/web/pages/api/organization-team/employee/[id].ts deleted file mode 100644 index c23773bda..000000000 --- a/apps/web/pages/api/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/organization-team/teams/[id].ts b/apps/web/pages/api/organization-team/teams/[id].ts deleted file mode 100644 index 964e660e7..000000000 --- a/apps/web/pages/api/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/public/team/[profileLink]/[teamId].ts b/apps/web/pages/api/public/team/[profileLink]/[teamId].ts deleted file mode 100644 index c0d76025e..000000000 --- a/apps/web/pages/api/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/role-permissions/[id].ts b/apps/web/pages/api/role-permissions/[id].ts deleted file mode 100644 index 6aafcad42..000000000 --- a/apps/web/pages/api/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/roles/[id].ts b/apps/web/pages/api/roles/[id].ts deleted file mode 100644 index 249981016..000000000 --- a/apps/web/pages/api/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/roles/index.ts b/apps/web/pages/api/roles/index.ts deleted file mode 100644 index b7d2bf100..000000000 --- a/apps/web/pages/api/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/tags/[id].ts b/apps/web/pages/api/tags/[id].ts deleted file mode 100644 index f471416eb..000000000 --- a/apps/web/pages/api/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/tags/index.tsx b/apps/web/pages/api/tags/index.tsx deleted file mode 100644 index c847b0257..000000000 --- a/apps/web/pages/api/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/tags/level.ts b/apps/web/pages/api/tags/level.ts deleted file mode 100644 index 55b98279d..000000000 --- a/apps/web/pages/api/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/task-priorities/[id].ts b/apps/web/pages/api/task-priorities/[id].ts deleted file mode 100644 index 3d6174031..000000000 --- a/apps/web/pages/api/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/task-priorities/index.tsx b/apps/web/pages/api/task-priorities/index.tsx deleted file mode 100644 index 62f95f1f3..000000000 --- a/apps/web/pages/api/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/task-related-issue-types/[id].ts b/apps/web/pages/api/task-related-issue-types/[id].ts deleted file mode 100644 index 44e1b2709..000000000 --- a/apps/web/pages/api/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/task-related-issue-types/index.ts b/apps/web/pages/api/task-related-issue-types/index.ts deleted file mode 100644 index bb3306389..000000000 --- a/apps/web/pages/api/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/task-sizes/[id].ts b/apps/web/pages/api/task-sizes/[id].ts deleted file mode 100644 index a68fd8d42..000000000 --- a/apps/web/pages/api/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/task-sizes/index.tsx b/apps/web/pages/api/task-sizes/index.tsx deleted file mode 100644 index 393b0c084..000000000 --- a/apps/web/pages/api/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/task-statuses/[id].ts b/apps/web/pages/api/task-statuses/[id].ts deleted file mode 100644 index 239211707..000000000 --- a/apps/web/pages/api/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/task-statuses/index.tsx b/apps/web/pages/api/task-statuses/index.tsx deleted file mode 100644 index f44a654ff..000000000 --- a/apps/web/pages/api/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/task-versions/[id].ts b/apps/web/pages/api/task-versions/[id].ts deleted file mode 100644 index 53826327e..000000000 --- a/apps/web/pages/api/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/task-versions/index.tsx b/apps/web/pages/api/task-versions/index.tsx deleted file mode 100644 index d0e62a6db..000000000 --- a/apps/web/pages/api/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/tasks/[id].ts b/apps/web/pages/api/tasks/[id].ts deleted file mode 100644 index 87b475407..000000000 --- a/apps/web/pages/api/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/tasks/employee/[employeeId].ts b/apps/web/pages/api/tasks/employee/[employeeId].ts deleted file mode 100644 index c4e86f973..000000000 --- a/apps/web/pages/api/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/tasks/task-linked-issue.ts b/apps/web/pages/api/tasks/task-linked-issue.ts deleted file mode 100644 index 3553395fa..000000000 --- a/apps/web/pages/api/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/tasks/team.ts b/apps/web/pages/api/tasks/team.ts deleted file mode 100644 index afd4ab9dc..000000000 --- a/apps/web/pages/api/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/timer/timesheet/index.ts b/apps/web/pages/api/timer/timesheet/index.ts deleted file mode 100644 index 53fd762c9..000000000 --- a/apps/web/pages/api/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/user/[id].ts b/apps/web/pages/api/user/[id].ts deleted file mode 100644 index dcf1a684d..000000000 --- a/apps/web/pages/api/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/user/me.ts b/apps/web/pages/api/user/me.ts deleted file mode 100644 index 9bb9b961b..000000000 --- a/apps/web/pages/api/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/user/reset.ts b/apps/web/pages/api/user/reset.ts deleted file mode 100644 index bce1795af..000000000 --- a/apps/web/pages/api/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 - }) - ); - } -}