#Implement prisma middleware

6 messages · Page 1 of 1 (latest)

wanton elk
#

Hello i'm trying to implement a soft delete feature to my models and i'm wondering where i could add the middleware responsible for this feature.
Should i use a nestjs middleware or a prisma middleware like what is shown from the prisma documentation ?
If so how could i implement prisma middleware in nestjs ?

proven nacelle
#

maybe this answer in stackover flow can help you

#

we used softDelete middleware in our primaService like this I hope this help you

#
import { Injectable } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import { softDeleteMiddleware } from '../utils/prisma.middleware';

@Injectable()
export class PrismaService extends PrismaClient {
  constructor() {
    super({
      datasources: {
        db: {
          url: process.env.DATABASE_URL,
        },
      },
    });
    this.$use(softDeleteMiddleware());
  }
}
wanton elk
#

cool thanks :