diff --git a/README.md b/README.md index a12cc42..089595f 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,10 @@ [Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. +## Todo + +- [] Create custom generic for Prisma ORM Support [#5273](https://github.com/prisma/prisma/issues/5273) + ## Project setup ```bash diff --git a/libs/prisma/src/prisma-crud.controller.ts b/libs/prisma/src/prisma-crud.controller.ts index e69de29..6703728 100644 --- a/libs/prisma/src/prisma-crud.controller.ts +++ b/libs/prisma/src/prisma-crud.controller.ts @@ -0,0 +1,3 @@ +import { SkeletonCRUDController } from '@autocrud/skeleton'; + +export class PrismaCRUDController extends SkeletonCRUDController {} diff --git a/libs/prisma/src/processes/batch/delete.process.ts b/libs/prisma/src/processes/batch/delete.process.ts new file mode 100644 index 0000000..6f914bb --- /dev/null +++ b/libs/prisma/src/processes/batch/delete.process.ts @@ -0,0 +1,11 @@ +import { BatchDeleteProcess } from '@autocrud/skeleton/processes/batch/delete.process'; + +export abstract class PrismaBatchDeleteProcess implements BatchDeleteProcess { + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); +} diff --git a/libs/prisma/src/processes/batch/update.process.ts b/libs/prisma/src/processes/batch/update.process.ts new file mode 100644 index 0000000..34784bf --- /dev/null +++ b/libs/prisma/src/processes/batch/update.process.ts @@ -0,0 +1,11 @@ +import { BatchUpdateProcess } from '@autocrud/skeleton/processes/batch/update.process'; + +export abstract class PrismaBatchUpdateProcess implements BatchUpdateProcess { + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); +} diff --git a/libs/prisma/src/processes/create.process.ts b/libs/prisma/src/processes/create.process.ts new file mode 100644 index 0000000..c101ffd --- /dev/null +++ b/libs/prisma/src/processes/create.process.ts @@ -0,0 +1,18 @@ +import { CreateProcess } from '@autocrud/skeleton/processes/create.process'; +import { Prisma, PrismaClient } from '@prisma/client'; + +export abstract class PrismaCreateProcess implements CreateProcess { + constructor(private readonly prisma: PrismaClient) {} + + abstract initialization(): T; + abstract before(): T; + abstract begin(): T; + process(): T { + this.prisma['asd'].create({ + data, + }); + } + abstract end(): T; + abstract after(): T; + abstract result(): R; +} diff --git a/libs/prisma/src/processes/delete.process.ts b/libs/prisma/src/processes/delete.process.ts new file mode 100644 index 0000000..fef6feb --- /dev/null +++ b/libs/prisma/src/processes/delete.process.ts @@ -0,0 +1,12 @@ +import { DeleteProcess } from '@autocrud/skeleton/processes/delete.process'; +import { Prisma } from '@prisma/client'; + +export abstract class PrismaDeleteProcess implements DeleteProcess { + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); +} diff --git a/libs/prisma/src/processes/list.process.ts b/libs/prisma/src/processes/list.process.ts new file mode 100644 index 0000000..0fbfe3b --- /dev/null +++ b/libs/prisma/src/processes/list.process.ts @@ -0,0 +1,11 @@ +import { ListProcess } from '@autocrud/skeleton/processes/list.process'; + +export abstract class PrismaListProcess implements ListProcess { + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); +} diff --git a/libs/prisma/src/processes/pagination.process.ts b/libs/prisma/src/processes/pagination.process.ts new file mode 100644 index 0000000..d661ca5 --- /dev/null +++ b/libs/prisma/src/processes/pagination.process.ts @@ -0,0 +1,11 @@ +import { PaginationProcess } from '@autocrud/skeleton/processes/pagination.process'; + +export abstract class PrismaPaginationProcess implements PaginationProcess { + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); +} diff --git a/libs/prisma/src/processes/partial/batch/update.process.ts b/libs/prisma/src/processes/partial/batch/update.process.ts new file mode 100644 index 0000000..cc63c45 --- /dev/null +++ b/libs/prisma/src/processes/partial/batch/update.process.ts @@ -0,0 +1,13 @@ +import { PartialBatchUpdateProcess } from '@autocrud/skeleton/processes/partial/batch/update.process'; + +export abstract class PrismaPartialBatchUpdateProcess + implements PartialBatchUpdateProcess +{ + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); +} diff --git a/libs/prisma/src/processes/partial/update.process.ts b/libs/prisma/src/processes/partial/update.process.ts new file mode 100644 index 0000000..b743084 --- /dev/null +++ b/libs/prisma/src/processes/partial/update.process.ts @@ -0,0 +1,13 @@ +import { PartialUpdateProcess } from '@autocrud/skeleton/processes/partial/update.process'; + +export abstract class PrismaPartialUpdateProcess + implements PartialUpdateProcess +{ + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); +} diff --git a/libs/prisma/src/processes/read.process.ts b/libs/prisma/src/processes/read.process.ts new file mode 100644 index 0000000..22e74c7 --- /dev/null +++ b/libs/prisma/src/processes/read.process.ts @@ -0,0 +1,11 @@ +import { ReadProcess } from '@autocrud/skeleton/processes/read.process'; + +export abstract class PrismaReadProcess implements ReadProcess { + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); +} diff --git a/libs/prisma/src/processes/update.process.ts b/libs/prisma/src/processes/update.process.ts new file mode 100644 index 0000000..431e670 --- /dev/null +++ b/libs/prisma/src/processes/update.process.ts @@ -0,0 +1,11 @@ +import { UpdateProcess } from '@autocrud/skeleton/processes/update.process'; + +export abstract class PrismaUpdateProcess implements UpdateProcess { + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); +} diff --git a/libs/skeleton/src/interfaces/controller/skeleton-crud.controller.interface.ts b/libs/skeleton/src/interfaces/controller/skeleton-crud.controller.interface.ts index 9d3a6b4..03da976 100644 --- a/libs/skeleton/src/interfaces/controller/skeleton-crud.controller.interface.ts +++ b/libs/skeleton/src/interfaces/controller/skeleton-crud.controller.interface.ts @@ -1,14 +1,13 @@ -import { IPaginationEntity } from '@autocrud/skeleton/entities/pagination.entity'; -export interface ISkeletonCRUDController { - create(): Promise; - readSelected(id: E): Promise; - readPagination(): Promise>; - readEntire(): Promise; - updatePartial(): Promise; - updatePartialBatch(): Promise; - updateEntire(): Promise; - updateEntireBatch(): Promise; - deleteSelected(): Promise; - deleteBatch(): Promise; +export interface ISkeletonCRUDController { + create(); + readSelected(id); + readPagination(); + readEntire(); + updatePartial(); + updatePartialBatch(); + updateEntire(); + updateEntireBatch(); + deleteSelected(); + deleteBatch(); } diff --git a/libs/skeleton/src/interfaces/skeleton-process.interface.ts b/libs/skeleton/src/interfaces/skeleton-process.interface.ts index 181f4bd..314ced7 100644 --- a/libs/skeleton/src/interfaces/skeleton-process.interface.ts +++ b/libs/skeleton/src/interfaces/skeleton-process.interface.ts @@ -1,10 +1,10 @@ -export interface ISkeletonProcess { - initialization(): T; - before(): T; - begin(): T; - process(): T; - end(): T; - after(): T; +export interface ISkeletonProcess { + initialization(); + before(); + begin(); + process(); + end(); + after(); - result(): R; + result(); } diff --git a/libs/skeleton/src/processes/batch/delete.process.ts b/libs/skeleton/src/processes/batch/delete.process.ts index 568ec81..1f69e53 100644 --- a/libs/skeleton/src/processes/batch/delete.process.ts +++ b/libs/skeleton/src/processes/batch/delete.process.ts @@ -1,13 +1,11 @@ import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface'; -export abstract class BatchDeleteProcess - implements ISkeletonProcess -{ - abstract initialization(): T; - abstract before(): T; - abstract begin(): T; - abstract process(): T; - abstract end(): T; - abstract after(): T; - abstract result(): R; +export abstract class BatchDeleteProcess implements ISkeletonProcess { + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); } diff --git a/libs/skeleton/src/processes/batch/update.process.ts b/libs/skeleton/src/processes/batch/update.process.ts index 6e1f0f6..8c18e20 100644 --- a/libs/skeleton/src/processes/batch/update.process.ts +++ b/libs/skeleton/src/processes/batch/update.process.ts @@ -1,13 +1,11 @@ import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface'; -export abstract class BatchUpdateProcess - implements ISkeletonProcess -{ - abstract initialization(): T; - abstract before(): T; - abstract begin(): T; - abstract process(): T; - abstract end(): T; - abstract after(): T; - abstract result(): R; +export abstract class BatchUpdateProcess implements ISkeletonProcess { + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); } diff --git a/libs/skeleton/src/processes/create.process.ts b/libs/skeleton/src/processes/create.process.ts index 325a17c..0725033 100644 --- a/libs/skeleton/src/processes/create.process.ts +++ b/libs/skeleton/src/processes/create.process.ts @@ -1,11 +1,11 @@ import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; -export abstract class CreateProcess implements ISkeletonProcess { - abstract initialization(): T; - abstract before(): T; - abstract begin(): T; - abstract process(): T; - abstract end(): T; - abstract after(): T; - abstract result(): R; +export abstract class CreateProcess implements ISkeletonProcess { + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); } diff --git a/libs/skeleton/src/processes/delete.process.ts b/libs/skeleton/src/processes/delete.process.ts index cd4cd23..e29c66c 100644 --- a/libs/skeleton/src/processes/delete.process.ts +++ b/libs/skeleton/src/processes/delete.process.ts @@ -1,11 +1,11 @@ import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; -export abstract class DeleteProcess implements ISkeletonProcess { - abstract initialization(): T; - abstract before(): T; - abstract begin(): T; - abstract process(): T; - abstract end(): T; - abstract after(): T; - abstract result(): R; +export abstract class DeleteProcess implements ISkeletonProcess { + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); } diff --git a/libs/skeleton/src/processes/list.process.ts b/libs/skeleton/src/processes/list.process.ts index fbdbe9b..3290bc2 100644 --- a/libs/skeleton/src/processes/list.process.ts +++ b/libs/skeleton/src/processes/list.process.ts @@ -1,11 +1,11 @@ import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; -export abstract class ListProcess implements ISkeletonProcess { - abstract initialization(): T; - abstract before(): T; - abstract begin(): T; - abstract process(): T; - abstract end(): T; - abstract after(): T; - abstract result(): R; +export abstract class ListProcess implements ISkeletonProcess { + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); } diff --git a/libs/skeleton/src/processes/pagination.process.ts b/libs/skeleton/src/processes/pagination.process.ts index 4d19ebb..77e14ad 100644 --- a/libs/skeleton/src/processes/pagination.process.ts +++ b/libs/skeleton/src/processes/pagination.process.ts @@ -1,11 +1,11 @@ import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; -export abstract class PaginationProcess implements ISkeletonProcess { - abstract initialization(): T; - abstract before(): T; - abstract begin(): T; - abstract process(): T; - abstract end(): T; - abstract after(): T; - abstract result(): R; +export abstract class PaginationProcess implements ISkeletonProcess { + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); } diff --git a/libs/skeleton/src/processes/partial/batch/update.process.ts b/libs/skeleton/src/processes/partial/batch/update.process.ts index 0de9f99..907989d 100644 --- a/libs/skeleton/src/processes/partial/batch/update.process.ts +++ b/libs/skeleton/src/processes/partial/batch/update.process.ts @@ -1,13 +1,11 @@ import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface'; -export abstract class PartialBatchUpdateProcess - implements ISkeletonProcess -{ - abstract initialization(): T; - abstract before(): T; - abstract begin(): T; - abstract process(): T; - abstract end(): T; - abstract after(): T; - abstract result(): R; +export abstract class PartialBatchUpdateProcess implements ISkeletonProcess { + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); } diff --git a/libs/skeleton/src/processes/partial/update.process.ts b/libs/skeleton/src/processes/partial/update.process.ts new file mode 100644 index 0000000..fa0fd6d --- /dev/null +++ b/libs/skeleton/src/processes/partial/update.process.ts @@ -0,0 +1,11 @@ +import { ISkeletonProcess } from '@autocrud/skeleton/interfaces/skeleton-process.interface'; + +export abstract class PartialUpdateProcess implements ISkeletonProcess { + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); +} diff --git a/libs/skeleton/src/processes/read.process.ts b/libs/skeleton/src/processes/read.process.ts index 9420d71..7929e6f 100644 --- a/libs/skeleton/src/processes/read.process.ts +++ b/libs/skeleton/src/processes/read.process.ts @@ -1,11 +1,11 @@ import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; -export abstract class ReadProcess implements ISkeletonProcess { - abstract initialization(): T; - abstract before(): T; - abstract begin(): T; - abstract process(): T; - abstract end(): T; - abstract after(): T; - abstract result(): R; +export abstract class ReadProcess implements ISkeletonProcess { + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); } diff --git a/libs/skeleton/src/processes/update.process.ts b/libs/skeleton/src/processes/update.process.ts index 552c6c4..8054483 100644 --- a/libs/skeleton/src/processes/update.process.ts +++ b/libs/skeleton/src/processes/update.process.ts @@ -1,11 +1,11 @@ import { ISkeletonProcess } from '../interfaces/skeleton-process.interface'; -export abstract class UpdateProcess implements ISkeletonProcess { - abstract initialization(): T; - abstract before(): T; - abstract begin(): T; - abstract process(): T; - abstract end(): T; - abstract after(): T; - abstract result(): R; +export abstract class UpdateProcess implements ISkeletonProcess { + abstract initialization(); + abstract before(); + abstract begin(); + abstract process(); + abstract end(); + abstract after(); + abstract result(); } diff --git a/libs/skeleton/src/skeleton-crud.controller.ts b/libs/skeleton/src/skeleton-crud.controller.ts index d1185aa..8d403f2 100644 --- a/libs/skeleton/src/skeleton-crud.controller.ts +++ b/libs/skeleton/src/skeleton-crud.controller.ts @@ -1,91 +1,67 @@ import { Delete, Get, Param, Patch, Post, Put } from '@nestjs/common'; -import { IPaginationEntity } from './entities/pagination.entity'; import { ISkeletonCRUDController } from './interfaces/controller/skeleton-crud.controller.interface'; -import { BatchDeleteProcess } from './processes/batch/delete.process'; -import { BatchUpdateProcess } from './processes/batch/update.process'; -import { CreateProcess } from './processes/create.process'; -import { DeleteProcess } from './processes/delete.process'; -import { ListProcess } from './processes/list.process'; -import { PaginationProcess } from './processes/pagination.process'; -import { PartialBatchUpdateProcess } from './processes/partial/batch/update.process'; -import { ReadProcess } from './processes/read.process'; -import { UpdateProcess } from './processes/update.process'; -export class SkeletonCRUDController< - T, - E, - CP extends CreateProcess, - RSP extends ReadProcess, - RPP extends PaginationProcess>, - REP extends ListProcess, - UPP extends UpdateProcess, - UBP extends PartialBatchUpdateProcess, - UEP extends UpdateProcess, - UEBP extends BatchUpdateProcess, - DP extends DeleteProcess, - DBP extends BatchDeleteProcess, -> implements ISkeletonCRUDController -{ +export class SkeletonCRUDController implements ISkeletonCRUDController { constructor( - private readonly createProcess: CP, - private readonly readProcess: RSP, - private readonly readPaginationProcess: RPP, - private readonly readEntireProcess: REP, - private readonly updatePartialProcess: UPP, - private readonly updateBatchProcess: UBP, - private readonly updateEntireProcess: UEP, - private readonly updateEntireBatchProcess: UEBP, - private readonly deleteProcess: DP, - private readonly deleteBatchProcess: DBP, + private readonly createProcess, + private readonly readProcess, + private readonly readPaginationProcess, + private readonly readEntireProcess, + private readonly updatePartialProcess, + private readonly updateBatchProcess, + private readonly updateEntireProcess, + private readonly updateEntireBatchProcess, + private readonly deleteProcess, + private readonly deleteBatchProcess, ) {} @Post() - async create(): Promise { + async create() { return this.createProcess.result(); } @Get(':id') - async readSelected(@Param('id') id: E): Promise { + async readSelected(@Param('id') id) { return this.readProcess.result(); } @Get() - async readPagination(): Promise> { + async readPagination() { return this.readPaginationProcess.result(); } @Get('list') - async readEntire(): Promise { + async readEntire() { return this.readEntireProcess.result(); } @Patch() - async updatePartial(): Promise { + async updatePartial() { return this.updatePartialProcess.result(); } @Patch('batch') - async updatePartialBatch(): Promise { + async updatePartialBatch() { return this.updateBatchProcess.result(); } @Put() - async updateEntire(): Promise { + async updateEntire() { return this.updateEntireProcess.result(); } @Put('batch') - async updateEntireBatch(): Promise { + async updateEntireBatch() { return this.updateEntireBatchProcess.result(); } @Delete() - async deleteSelected(): Promise { + async deleteSelected() { return this.deleteProcess.result(); } @Delete('batch') - async deleteBatch(): Promise { + async deleteBatch() { return this.deleteBatchProcess.result(); } } diff --git a/src/app.controller.ts b/src/app.controller.ts index bce179c..1b2aaa9 100644 --- a/src/app.controller.ts +++ b/src/app.controller.ts @@ -1,12 +1,9 @@ -import { SkeletonCRUDController } from '@autocrud/skeleton'; +import { PrismaCRUDController } from '@autocrud/prisma/prisma-crud.controller'; import { Controller } from '@nestjs/common'; -import { AppService } from './app.service'; @Controller('hello') -export class AppController extends SkeletonCRUDController { - constructor(private readonly appService: AppService) { - super(); - } +export class AppController extends PrismaCRUDController { + constructor() {} // Read(): void { // console.log(this.appService.getHello()); diff --git a/src/app.module.ts b/src/app.module.ts index 8662803..19e4b4a 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,9 +1,10 @@ +import { PrismaModule } from '@autocrud/prisma'; import { Module } from '@nestjs/common'; import { AppController } from './app.controller'; import { AppService } from './app.service'; @Module({ - imports: [], + imports: [PrismaModule], controllers: [AppController], providers: [AppService], })