feat: simple working list process

This commit is contained in:
Supan Adit Pratama 2024-10-27 00:43:17 +07:00
parent 3755f49181
commit 231fd12dea
6 changed files with 19 additions and 16 deletions

View File

@ -1 +1 @@
export declare const PRISMA_DELEGATE = 'PRISMA_DELEGATE'; export const PRISMA_DELEGATE = 'PRISMA_DELEGATE';

View File

@ -1,14 +1,8 @@
import { READ_ENTIRE_PROCESS } from '@autocrud/skeleton';
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { PrismaService } from './prisma.service'; import { PrismaService } from './prisma.service';
import { PrismaListProcess } from './processes/list.process';
@Module({ @Module({
providers: [ providers: [PrismaService],
PrismaService,
{ provide: READ_ENTIRE_PROCESS, useClass: PrismaListProcess },
,
],
exports: [PrismaService], exports: [PrismaService],
}) })
export class PrismaModule {} export class PrismaModule {}

View File

@ -2,7 +2,7 @@ import { ListProcess } from '@autocrud/skeleton/processes/list.process';
import { PrismaProcess } from './prisma.process'; import { PrismaProcess } from './prisma.process';
export class PrismaListProcess extends PrismaProcess implements ListProcess { export class PrismaListProcess extends PrismaProcess implements ListProcess {
private data; private data: any;
async process(): Promise<any> { async process(): Promise<any> {
this.data = await this.getDelegate().findMany(); this.data = await this.getDelegate().findMany();

View File

@ -1,16 +1,17 @@
import { DefaultProcess } from '@autocrud/skeleton/processes/default.process'; import { DefaultProcess } from '@autocrud/skeleton/processes/default.process';
import { Inject } from '@nestjs/common'; import { Inject, Injectable } from '@nestjs/common';
import { PRISMA_DELEGATE } from '../constants'; import { PRISMA_DELEGATE } from '../constants';
@Injectable()
export class PrismaProcess extends DefaultProcess { export class PrismaProcess extends DefaultProcess {
constructor( constructor(
@Inject(PRISMA_DELEGATE) @Inject(PRISMA_DELEGATE)
private delegate: any, private delegate,
) { ) {
super(); super();
} }
get getDelegate() { getDelegate() {
return this.delegate; return this.delegate;
} }
} }

View File

@ -1 +1 @@
export declare const READ_ENTIRE_PROCESS = 'READ_ENTIRE_PROCESS'; export const READ_ENTIRE_PROCESS = 'READ_ENTIRE_PROCESS';

View File

@ -1,10 +1,13 @@
import { PrismaModule, PrismaService } from '@autocrud/prisma'; import { PrismaModule, PrismaService } from '@autocrud/prisma';
import { PRISMA_DELEGATE } from '@autocrud/prisma/constants'; import { PRISMA_DELEGATE } from '@autocrud/prisma/constants';
import { ListProcess } from '@autocrud/skeleton/processes/list.process';
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { AppController } from './app.controller'; import { AppController } from './app.controller';
import { AppService } from './app.service'; import { AppService } from './app.service';
import { READ_ENTIRE_PROCESS } from '@autocrud/skeleton';
import { PrismaListProcess } from '@autocrud/prisma/processes/list.process';
const delegateFactory = { const customFactory = {
provide: PRISMA_DELEGATE, provide: PRISMA_DELEGATE,
useFactory: (prisma: PrismaService) => { useFactory: (prisma: PrismaService) => {
return prisma.user; return prisma.user;
@ -13,8 +16,13 @@ const delegateFactory = {
}; };
@Module({ @Module({
imports: [PrismaModule], imports: [],
controllers: [AppController], controllers: [AppController],
providers: [AppService, delegateFactory], providers: [
AppService,
PrismaService,
customFactory,
{ provide: READ_ENTIRE_PROCESS, useClass: PrismaListProcess },
],
}) })
export class AppModule {} export class AppModule {}