diff --git a/.vscode/settings.json b/.vscode/settings.json index 69eb0c1..cd5e26e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -26,6 +26,7 @@ "dash/me", "frontend/auth", "dash/components", - "frontend/seo" + "frontend/seo", + "api/applications" ] } diff --git a/apps/api/src/controllers/ApplicationController.ts b/apps/api/src/controllers/ApplicationController.ts index fa48b39..a3d0d8d 100644 --- a/apps/api/src/controllers/ApplicationController.ts +++ b/apps/api/src/controllers/ApplicationController.ts @@ -1,6 +1,6 @@ import { Application, ApplicationQuestionType, ApplicationStatus } from '@repo/db'; import { Request, Response } from 'express'; -import { sendBtWebhook, WebhookType } from '../util/BtWebhooks.js'; +import { WebhookType, sendBtWebhook } from '../util/BtWebhooks.js'; import { ERROR_GENERIC, ERROR_NO_PERMISSION, ERROR_VALIDATION } from '../util/Errors.js'; import { validationResult } from 'express-validator'; @@ -30,17 +30,39 @@ class ApplicationController { const onlyReview = req.query.review; - let applications = await this.core.getPrisma().application.findMany({ - where: { - buildteam: req.query.slug ? { slug: req.params.id } : { id: req.params.id }, - status: onlyReview ? { in: [ApplicationStatus.SEND, ApplicationStatus.REVIEWING] } : undefined, - }, - include: { - user: { select: { id: true, username: true } }, - }, - }); - - res.send(applications); + if (req.query && req.query.page) { + let page = parseInt(req.query.page as string); + let take = parseInt((req.query.take || 10) as string); + let applications = await this.core.getPrisma().application.findMany({ + skip: page * take, + take: take, + where: { + buildteam: req.query.slug ? { slug: req.params.id } : { id: req.params.id }, + status: onlyReview ? { in: [ApplicationStatus.SEND, ApplicationStatus.REVIEWING] } : undefined, + }, + include: { + user: { select: { id: true, username: true } }, + }, + }); + let count = await this.core.getPrisma().application.count({ + where: { + buildteam: req.query.slug ? { slug: req.params.id } : { id: req.params.id }, + status: onlyReview ? { in: [ApplicationStatus.SEND, ApplicationStatus.REVIEWING] } : undefined, + }, + }); + res.send({ pages: Math.ceil(count / take), data: applications }); + } else { + let applications = await this.core.getPrisma().application.findMany({ + where: { + buildteam: req.query.slug ? { slug: req.params.id } : { id: req.params.id }, + status: onlyReview ? { in: [ApplicationStatus.SEND, ApplicationStatus.REVIEWING] } : undefined, + }, + include: { + user: { select: { id: true, username: true } }, + }, + }); + res.send(applications); + } } /** diff --git a/apps/api/src/web/routes/index.ts b/apps/api/src/web/routes/index.ts index dfba8ae..3153a02 100644 --- a/apps/api/src/web/routes/index.ts +++ b/apps/api/src/web/routes/index.ts @@ -450,6 +450,8 @@ class Routes { }, param('id'), query('review').isBoolean().optional(), + query('page').isNumeric().optional().default(0), + query('take').isNumeric().optional().default(10), checkUserPermission(this.web.getCore().getPrisma(), 'team.application.list', 'id'), ); router.addRoute(