Yaakov
02/07/2022, 1:20 PMupdated_by
ID before each update. The currect user can be obtained from req.user.id
. The correct approach seems to be using Prisma middleware, however prisma.$use
does not seem to provide access to the req
object!
Any ideas??
prisma.$use(async (params, next) => {
if (params.action === 'update') {
const models = prisma._dmmf.datamodel.models;
let model = models.find(m => m.name === params.model);
let updatedAtField = model.fields.find(f => f.name === 'updated_by');
if (updatedAtField) {
params.args.data['updated_by'] = NEED ACCESS TO req.user.id;
}
}
return next(params);
});