Good morning, I'm looking for a way to automatical...
# prisma-client
y
Good morning, I'm looking for a way to automatically add the
updated_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??
Copy code
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);
});