* yarn * yarn update * added Mardown style formatting with sanitized inputs * Revert "yarn" This reverts commit 46eb3595cf687504c6783315749b3124936080b9. * Revert "yarn" This reverts commit 46eb3595cf687504c6783315749b3124936080b9. * Revert "yarn update" This reverts commit f4600d83a67b930c6dd72e292827578856ca5428. * Revert "yarn" This reverts commit 46eb3595cf687504c6783315749b3124936080b9. * Revert "yarn update" This reverts commit f4600d83a67b930c6dd72e292827578856ca5428. * Revert "Revert "yarn update"" This reverts commit 8ccab5ee237fb228115229f3c89cf4b848bc9449. * Revert "Revert "yarn"" This reverts commit 78a755eb39cb518eb0526272a3c11882c48004de. * yarn.lock removed * Parses using prisma middleware * Reverting changes * Fixes hydration warning * Fixes Dom warnings * Update yarn.lock Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: zomars <zomars@me.com>
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import { PrismaClient } from "@prisma/client";
|
|
|
|
function middleware(prisma: PrismaClient) {
|
|
/***********************************/
|
|
/* SOFT DELETE MIDDLEWARE */
|
|
/***********************************/
|
|
prisma.$use(async (params, next) => {
|
|
// Check incoming query type
|
|
|
|
if (params.model === "BookingReference") {
|
|
if (params.action === "delete") {
|
|
// Delete queries
|
|
// Change action to an update
|
|
params.action = "update";
|
|
params.args["data"] = { deleted: true };
|
|
}
|
|
if (params.action === "deleteMany") {
|
|
console.log("deletingMany");
|
|
// Delete many queries
|
|
params.action = "updateMany";
|
|
if (params.args.data !== undefined) {
|
|
params.args.data["deleted"] = true;
|
|
} else {
|
|
params.args["data"] = { deleted: true };
|
|
}
|
|
}
|
|
if (params.action === "findUnique") {
|
|
// Change to findFirst - you cannot filter
|
|
// by anything except ID / unique with findUnique
|
|
params.action = "findFirst";
|
|
// Add 'deleted' filter
|
|
// ID filter maintained
|
|
params.args.where["deleted"] = null;
|
|
}
|
|
if (params.action === "findMany" || params.action === "findFirst") {
|
|
// Find many queries
|
|
if (params.args.where !== undefined) {
|
|
if (params.args.where.deleted === undefined) {
|
|
// Exclude deleted records if they have not been explicitly requested
|
|
params.args.where["deleted"] = null;
|
|
}
|
|
} else {
|
|
params.args["where"] = { deleted: null };
|
|
}
|
|
}
|
|
}
|
|
return next(params);
|
|
});
|
|
}
|
|
|
|
export default middleware;
|