Just wondering if there is something in Prisma equivalent to the Mongoose isModified method to be used in Prisma middleware
prisma.$use(async (params, next) => {
if (params.model == 'User' && params.action == 'create') {
// check if password modified
params.args.data.password = await bcrypt.hash(params.args.data.password, 10);
}
return next(params);
});
Thanks
You can use findMany method
if (params.model == 'User' && params.action == 'create') {
// check if password modified
const result = await prisma.user.findMany({
where: {
email: email
}
})
const receivedPassword = await bcrypt.hash(params.args.data.password)
if (result[0].password === receivedPassword) {
params.args.data.password = await bcrypt.hash(params.args.data.password, 10);
}
}