Skip to content

Commit

Permalink
merge(dev): 🔀 Push recent development changes to main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Nudelsuppe42 committed Jun 1, 2024
2 parents 3023955 + 397fcdd commit 4ebd4c3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
56 changes: 55 additions & 1 deletion src/controllers/ClaimController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,43 @@ class ClaimController {
return;
}

public async getClaimImages(req: Request, res: Response) {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return ERROR_VALIDATION(req, res, errors.array());
}
const uploads = await this.core.getPrisma().upload.findMany({
orderBy: {
createdAt: "desc",
},
take: parseInt((req.query.take as string) || "10"),
skip: parseInt((req.query.skip as string) || "0"),
where: {
claimId: { not: null },
},
include: {
Showcase: {
select: {
id: true,
approved: true,
buildTeam: { select: { name: true, slug: true } },
city: true,
title: true,
},
},
Claim: { select: { id: true, name: true } },
},
});

const count = await this.core.getPrisma().upload.count({
where: {
claimId: { not: null },
},
});

res.send({ data: uploads, total: count });
}

public async getStatistics(req: Request, res: Response) {
const claimAggr = await this.core.getPrisma().claim.aggregate({
_avg: {
Expand Down Expand Up @@ -517,13 +554,30 @@ class ClaimController {
const claim = await this.core.getPrisma().claim.findFirst({
where: {
id: req.params.id,
ownerId: req.user.id, // TODO
},
select: {
images: { where: { id: req.params.image } },
id: true,
buildTeamId: true,
ownerId: true,
externalId: true,
buildTeam: { select: { webhook: true } },
},
});

if (claim?.ownerId != req.user.id) {
if (
!userHasPermissions(
this.core.getPrisma(),
req.user.ssoId,
["team.claim.list"],
claim.buildTeamId
)
) {
return ERROR_NO_PERMISSION(req, res);
}
}

if (claim?.images[0]) {
await this.core.getAWS().deleteFile("uploads", claim.images[0].id);
res.send(claim);
Expand Down
2 changes: 1 addition & 1 deletion src/util/Prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Core from "../Core.js";

export async function middlewareUploadSrc(params, next) {
const result = await next(params);
if (params.model == "Upload") {
if (params.model == "Upload" && params.action != "count") {
result.src = `https://cdn.buildtheearth.net/uploads/${result.name}`;
}
return result;
Expand Down
8 changes: 8 additions & 0 deletions src/web/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,14 @@ class Routes {
await controllers.claim.getClaimsGeoJson(request, response);
}
);
router.addRoute(
RequestMethods.GET,
"/claims/images",
async (request, response) => {
await controllers.claim.getClaimImages(request, response);
},
checkUserPermission(this.web.getCore().getPrisma(), "team.claim.list")
);
router.addRoute(
RequestMethods.GET,
"/map/statistics",
Expand Down

0 comments on commit 4ebd4c3

Please sign in to comment.