More cleanup
This commit is contained in:
+9
-11
@@ -2,7 +2,6 @@ import {
|
||||
ActivityPerformanceSchema,
|
||||
ActivityVerificationsSchema,
|
||||
PlayerSchema,
|
||||
Activity,
|
||||
} from "@blade-and-brawn/domain"
|
||||
import { cors } from "@elysiajs/cors";
|
||||
import { Elysia, NotFoundError, redirect, status, t } from "elysia";
|
||||
@@ -33,7 +32,6 @@ import { VerificationsService, VerificationStatusSchema } from "./services/verif
|
||||
const EVENT_QUEUE_MANAGE_DELAY_MS = 1000 // 1 sec
|
||||
const JWT_EXP = "1d";
|
||||
const JWT_EXP_SECONDS = 60 * 60 * 24; // keep in sync with JWT_EXP; used for cookie maxAge
|
||||
const PG_UNIQUE_VIOLATION = "23505";
|
||||
|
||||
// SERVICES
|
||||
// -----------------------
|
||||
@@ -59,12 +57,6 @@ const r2 = {
|
||||
})
|
||||
};
|
||||
|
||||
const presignVerificationUploads = (assessmentId: string) =>
|
||||
Object.values(Activity).map(() => r2.verificationMedia.presign(`${assessmentId}/${crypto.randomUUID()}`, {
|
||||
method: "PUT",
|
||||
expiresIn: 30 * 60,
|
||||
}));
|
||||
|
||||
// QUEUES
|
||||
// -----------------------
|
||||
const queues = [
|
||||
@@ -122,7 +114,7 @@ export const app = new Elysia()
|
||||
.onError(({ code, error }) => {
|
||||
// Database errors
|
||||
if (error instanceof DatabaseError) {
|
||||
if (error.code === PG_UNIQUE_VIOLATION)
|
||||
if (error.code === "23505")
|
||||
return status(409, { error: "Conflicts with an existing record" });
|
||||
log.error({ err: error }, "Database error");
|
||||
return status(500, { error: "Internal Server Error" });
|
||||
@@ -557,7 +549,10 @@ export const app = new Elysia()
|
||||
const created = await s.Verifications.create(assessmentId);
|
||||
if (!created) throw new ConflictError("This assessment already has a verification");
|
||||
|
||||
return { ...created, uploadUrls: presignVerificationUploads(assessmentId) };
|
||||
return {
|
||||
...created,
|
||||
uploadUrls: VerificationsService.presignMediaUploads(r2.verificationMedia, assessmentId)
|
||||
};
|
||||
}, {
|
||||
body: t.Object({
|
||||
assessmentId: BigIntIdSchema
|
||||
@@ -570,7 +565,10 @@ export const app = new Elysia()
|
||||
const reopened = await s.Verifications.reopen(id);
|
||||
if (!reopened) throw new ConflictError(`Cannot reopen a ${verification.status} verification`);
|
||||
|
||||
return { ...reopened, uploadUrls: presignVerificationUploads(verification.assessment_id) };
|
||||
return {
|
||||
...reopened,
|
||||
uploadUrls: VerificationsService.presignMediaUploads(r2.verificationMedia, verification.assessment_id)
|
||||
};
|
||||
}, {
|
||||
params: t.Object({ id: BigIntIdSchema })
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user