feat: custom process modification

This commit is contained in:
Supan Adit Pratama 2024-11-02 22:33:23 +07:00
parent 0c86c9ed88
commit 55fe243e00
4 changed files with 29 additions and 18 deletions

View File

@ -1,19 +1,14 @@
import { PrismaService } from '../prisma.service';
import {
PrismaCreateProcess,
PrismaDeleteProcess,
PrismaPaginationProcess,
PrismaReadProcess,
PrismaUpdateProcess,
} from '../processes';
import { PrismaListProcess } from '../processes/list.process';
// @TODO: Find way to use typesafe in each of the process property
// Known Issue:
// - You cannot be able modified the constructor extended to each process
export interface PrismaModuleOptions {
delegate: (prisma: PrismaService) => unknown;
processCreate?: typeof PrismaCreateProcess;
processDelete?: typeof PrismaDeleteProcess;
processList?: typeof PrismaListProcess;
processPagination?: typeof PrismaPaginationProcess;
processRead?: typeof PrismaReadProcess;
processUpdate?: typeof PrismaUpdateProcess;
delegate: (prisma: PrismaService) => any;
processCreate?;
processDelete?;
processList?;
processPagination?;
processRead?;
processUpdate?;
}

View File

@ -1,6 +1,6 @@
import { PrismaModule } from '@aditama-labs/nest-autocrud/prisma';
import { Module } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import { PrismaModule } from 'libs';
import { CustomController } from './custom.controller';
import { CustomListProcess } from './domain/custom.list.process';
import { CustomReadProcess } from './domain/custom.read.process';

View File

@ -1,9 +1,25 @@
import { PrismaReadProcess } from '@aditama-labs/nest-autocrud/prisma';
import {
PRISMA_DELEGATE,
PrismaReadProcess,
PrismaService,
} from '@aditama-labs/nest-autocrud/prisma';
import { Inject, Injectable } from '@nestjs/common';
@Injectable()
export class CustomReadProcess extends PrismaReadProcess {
constructor(
@Inject(PRISMA_DELEGATE)
delegate,
@Inject()
private prisma: PrismaService,
) {
super(delegate);
}
customResult;
async before(): Promise<any> {
console.log(await this.prisma.user.findMany());
console.log('The ID requested in path parameter', this.identityData);
}
async after(): Promise<any> {

View File

@ -1,6 +1,6 @@
import { PrismaModule } from '@aditama-labs/nest-autocrud/prisma';
import { Module } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import { PrismaModule } from 'libs';
import { SimpleController } from './simple.controller';
@Module({