Spaces:
Paused
Paused
Download apps/prevision-api/src/prisma/soft-delete.extension.ts from modventures/prevision: direct link, hf CLI and curl.
- Browser
- Download file 836 Bytes
-
https://huggingface.co/spaces/modventures/prevision/resolve/main/apps/prevision-api/src/prisma/soft-delete.extension.ts
- Command line
-
hf download hf://spaces/modventures/prevision/apps/prevision-api/src/prisma/soft-delete.extension.ts
-
curl -L -o soft-delete.extension.ts https://huggingface.co/spaces/modventures/prevision/resolve/main/apps/prevision-api/src/prisma/soft-delete.extension.ts
836 Bytes
| import { Prisma } from '../generated/prisma/client.js'; | |
| const SCOPED_OPERATIONS = new Set([ | |
| 'findUnique', | |
| 'findUniqueOrThrow', | |
| 'findFirst', | |
| 'findFirstOrThrow', | |
| 'findMany', | |
| 'count', | |
| 'update', | |
| 'updateMany', | |
| ]); | |
| const SOFT_DELETE_MODELS = new Set(['User', 'Tile']); | |
| /** Users and tiles are never removed: queries skip soft-deleted rows unless they filter `deletedAt` themselves. */ | |
| export const softDelete = Prisma.defineExtension({ | |
| name: 'soft-delete', | |
| query: { | |
| $allModels: { | |
| $allOperations({ model, operation, args, query }) { | |
| if (SOFT_DELETE_MODELS.has(model) && SCOPED_OPERATIONS.has(operation)) { | |
| const scoped = args as { where?: Record<string, unknown> }; | |
| scoped.where = { deletedAt: null, ...scoped.where }; | |
| } | |
| return query(args); | |
| }, | |
| }, | |
| }, | |
| }); | |