Handle auto filter base on status of model (prisma and nestjs)

In my project, I have some roles, they are Student, Lecture, and Admin. I also have some model with status. Status = enum(Public, Private, Archive) Role= enum(Student, Private,Public) I have University and Course model with their own status, I want the user with role Student only have access for University/Course with Public status. Lecture also only have access to Course with Public and Private Status. If I only have 1 controller/route for all roles, how I can implement this requirement with good performance? I was able to create a middleware for every routes to determine the process base on role but in middleware I need to make a query select, and that is my concern because it make me select the item more than one, (1 for middleware, >=1 in service)
2 Replies
Nurul
Nurul4d ago
Based on your use case it looks like you want to implement Row Level Security? Do you want to achive something like discussed in this feature request? https://github.com/prisma/prisma/issues/12735
GitHub
Support for row-level security (RLS) · Issue #12735 · prisma/prisma
Problem Currently, if we want to guarantee that user's requests have enough permissions to run a query, we have to keep coding where:{...} clauses everywhere in our code. Depending on the size ...
Nurul
Nurul4d ago
Can you share your current implementation to help me better understand what you are trying to achieve?

Did you find this page helpful?