Skip to content
This repository was archived by the owner on Feb 22, 2025. It is now read-only.

Commit 33023bc

Browse files
committed
feat(users): ✨ Get all reviews a user can review
1 parent ca463a1 commit 33023bc

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/controllers/UserController.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { ApplicationStatus, PrismaClient } from "@prisma/client";
12
import { Request, Response } from "express";
23

3-
import { PrismaClient } from "@prisma/client";
44
import { validationResult } from "express-validator";
55
import Core from "../Core.js";
66
import { userHasPermissions } from "../web/routes/utils/CheckUserPermissionMiddleware.js";
@@ -157,6 +157,45 @@ class UserController {
157157
}
158158
}
159159

160+
public async getUserReviews(req: Request, res: Response) {
161+
const errors = validationResult(req);
162+
if (!errors.isEmpty()) {
163+
return res.status(400).json({ errors: errors.array() });
164+
}
165+
166+
if (!req.kauth.grant) {
167+
return res.status(401).json("You are not permited to do this!");
168+
}
169+
const user = await this.core.getPrisma().user.findFirst({
170+
where: {
171+
id: req.params.id,
172+
},
173+
});
174+
175+
if (user.ssoId != req.kauth.grant.access_token.content.sub) {
176+
return res.status(401).json("You are not permited to do this!");
177+
}
178+
179+
const reviewPermissions = await this.core
180+
.getPrisma()
181+
.userPermission.findMany({
182+
where: { userId: user.id, permissionId: "team.application.review" },
183+
select: { buildTeamId: true, id: true },
184+
});
185+
186+
const applications = await this.core.getPrisma().application.findMany({
187+
where: {
188+
status: { in: [ApplicationStatus.SEND, ApplicationStatus.REVIEWING] },
189+
buildteamId: { in: reviewPermissions.map((p) => p.buildTeamId) },
190+
},
191+
include: {
192+
buildteam: { select: { slug: true, name: true, icon: true } },
193+
},
194+
});
195+
196+
res.send(applications);
197+
}
198+
160199
public async updateUser(req: Request, res: Response) {
161200
const errors = validationResult(req);
162201
if (!errors.isEmpty()) {

src/web/routes/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,15 @@ class Routes {
494494
param("id").isUUID()
495495
// Permission check later
496496
);
497+
router.addRoute(
498+
RequestMethods.GET,
499+
"/users/:id/review",
500+
async (request, response) => {
501+
await userController.getUserReviews(request, response);
502+
},
503+
param("id").isUUID()
504+
// Permission check later
505+
);
497506
router.addRoute(
498507
RequestMethods.POST,
499508
"/users/:id",

0 commit comments

Comments
 (0)