patched review suggestions and discovered bugs

This commit is contained in:
Laurin
2022-06-07 03:47:37 +02:00
parent 94b2030c8f
commit 7655eebcd9
10 changed files with 259 additions and 221 deletions
+18 -12
View File
@@ -10,6 +10,7 @@ import { PrismaClientKnownRequestError } from "@prisma/client/runtime";
import { generateInvalidBodyError, DataType } from "./common";
import { unlink } from "fs/promises";
import ForwardableError from "../Middleware/error/ForwardableError";
import { table } from "console";
require("express-async-errors");
@@ -204,21 +205,26 @@ export const linkMedia = async (req: Request<{ pid: string }, {}, { mediaPid: st
);
}
const updatedRec = await getPrismaUpdateFKT(tableToUpdate[2])({
where: { pid },
data: {
visual: { connect: { pid: mediaPid } },
},
});
try {
const updatedRec = await getPrismaUpdateFKT(tableToUpdate[2])({
where: { pid },
data: {
visual: { connect: { pid: mediaPid } },
},
});
if (!updatedRec) {
throw new NotFoundError(tableToUpdate[2], pid);
return res.status(200).json({
type: "success",
payload: { message: "Linking with the visual was successful" },
});
} catch (e) {
if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") {
throw new NotFoundError(tableToUpdate[2], pid);
}
throw e;
}
return res.status(200).json({
type: "success",
payload: {},
});
};
export const unlinkMedia = async (req: Request<{ pid: string; mediaPid: string }>, res: Response) => {