-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #333 from conceptadev/featue/cfg-crud-builder
feat: configurable crud builder
- Loading branch information
Showing
37 changed files
with
1,314 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/nestjs-crud/src/__fixtures__/app-ccb-custom.module.fixture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { default as ormConfig } from './ormconfig.fixture'; | ||
import { CrudModule } from '../crud.module'; | ||
import { PhotoCcbCustomModuleFixture } from './photo-ccb-custom/photo-ccb-custom.module.fixture'; | ||
|
||
@Module({ | ||
imports: [ | ||
TypeOrmModule.forRoot(ormConfig), | ||
CrudModule.forRoot({}), | ||
PhotoCcbCustomModuleFixture, | ||
], | ||
}) | ||
export class AppCcbCustomModuleFixture {} |
14 changes: 14 additions & 0 deletions
14
packages/nestjs-crud/src/__fixtures__/app-ccb-ext.module.fixture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmExtModule } from '@concepta/nestjs-typeorm-ext'; | ||
import { default as ormConfig } from './ormconfig.fixture'; | ||
import { CrudModule } from '../crud.module'; | ||
import { PhotoCcbExtModuleFixture } from './photo-ccb-ext/photo-ccb-ext.module.fixture'; | ||
|
||
@Module({ | ||
imports: [ | ||
TypeOrmExtModule.forRoot(ormConfig), | ||
CrudModule.forRoot({}), | ||
PhotoCcbExtModuleFixture, | ||
], | ||
}) | ||
export class AppCcbExtModuleFixture {} |
14 changes: 14 additions & 0 deletions
14
packages/nestjs-crud/src/__fixtures__/app-ccb-sub.module.fixture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { default as ormConfig } from './ormconfig.fixture'; | ||
import { CrudModule } from '../crud.module'; | ||
import { PhotoCcbSubModuleFixture } from './photo-ccb-sub/photo-ccb-sub.module.fixture'; | ||
|
||
@Module({ | ||
imports: [ | ||
TypeOrmModule.forRoot(ormConfig), | ||
CrudModule.forRoot({}), | ||
PhotoCcbSubModuleFixture, | ||
], | ||
}) | ||
export class AppCcbSubModuleFixture {} |
14 changes: 14 additions & 0 deletions
14
packages/nestjs-crud/src/__fixtures__/app-ccb.module.fixture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { default as ormConfig } from './ormconfig.fixture'; | ||
import { CrudModule } from '../crud.module'; | ||
import { PhotoCcbModuleFixture } from './photo-ccb/photo-ccb.module.fixture'; | ||
|
||
@Module({ | ||
imports: [ | ||
TypeOrmModule.forRoot(ormConfig), | ||
CrudModule.forRoot({}), | ||
PhotoCcbModuleFixture, | ||
], | ||
}) | ||
export class AppCcbModuleFixture {} |
136 changes: 136 additions & 0 deletions
136
...ages/nestjs-crud/src/__fixtures__/photo-ccb-custom/photo-ccb-custom.controller.fixture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import { PhotoEntityInterfaceFixture } from '../photo/interfaces/photo-entity.interface.fixture'; | ||
import { PhotoCreatableInterfaceFixture } from '../photo/interfaces/photo-creatable.interface.fixture'; | ||
import { PhotoUpdatableInterfaceFixture } from '../photo/interfaces/photo-updatable.interface.fixture'; | ||
import { PhotoFixture } from '../photo/photo.entity.fixture'; | ||
import { PhotoDtoFixture } from '../photo/dto/photo.dto.fixture'; | ||
import { PhotoPaginatedDtoFixture } from '../photo/dto/photo-paginated.dto.fixture'; | ||
import { PhotoCreateDtoFixture } from '../photo/dto/photo-create.dto.fixture'; | ||
import { PhotoCreateManyDtoFixture } from '../photo/dto/photo-create-many.dto.fixture'; | ||
import { PhotoUpdateDtoFixture } from '../photo/dto/photo-update.dto.fixture'; | ||
import { ConfigurableCrudBuilder } from '../../util/configurable-crud.builder'; | ||
import { CrudSoftDelete } from '../../decorators/routes/crud-soft-delete.decorator'; | ||
import { AbstractCrudController } from '../../controllers/abstract-crud.controller'; | ||
import { CrudRequest } from '../../decorators/params/crud-request.decorator'; | ||
import { CrudRequestInterface } from '../../interfaces/crud-request.interface'; | ||
import { TypeOrmCrudService } from '../../services/typeorm-crud.service'; | ||
import { CrudBody } from '../../decorators/params/crud-body.decorator'; | ||
|
||
export const PHOTO_CRUD_SERVICE_TOKEN = Symbol('__PHOTO_CRUD_SERVICE_TOKEN__'); | ||
|
||
const crudBuilder = new ConfigurableCrudBuilder< | ||
PhotoEntityInterfaceFixture, | ||
PhotoCreatableInterfaceFixture, | ||
PhotoUpdatableInterfaceFixture | ||
>(); | ||
|
||
const { | ||
ConfigurableServiceClass, | ||
CrudController, | ||
CrudGetMany, | ||
CrudGetOne, | ||
CrudCreateMany, | ||
CrudCreateOne, | ||
CrudUpdateOne, | ||
CrudReplaceOne, | ||
CrudDeleteOne, | ||
CrudRecoverOne, | ||
} = crudBuilder.build({ | ||
service: { | ||
entity: PhotoFixture, | ||
injectionToken: PHOTO_CRUD_SERVICE_TOKEN, | ||
}, | ||
controller: { | ||
path: 'photo', | ||
model: { | ||
type: PhotoDtoFixture, | ||
paginatedType: PhotoPaginatedDtoFixture, | ||
}, | ||
}, | ||
getMany: {}, | ||
getOne: {}, | ||
createMany: { | ||
dto: PhotoCreateManyDtoFixture, | ||
}, | ||
createOne: { | ||
dto: PhotoCreateDtoFixture, | ||
}, | ||
updateOne: { | ||
dto: PhotoUpdateDtoFixture, | ||
}, | ||
replaceOne: { | ||
dto: PhotoUpdateDtoFixture, | ||
}, | ||
deleteOne: { | ||
extraDecorators: [CrudSoftDelete(true)], | ||
}, | ||
recoverOne: { path: 'recover/:id' }, | ||
}); | ||
|
||
export class PhotoCcbCustomCrudServiceFixture extends ConfigurableServiceClass {} | ||
|
||
@CrudController | ||
export class PhotoCcbCustomControllerFixture extends AbstractCrudController< | ||
PhotoEntityInterfaceFixture, | ||
PhotoCreatableInterfaceFixture, | ||
PhotoUpdatableInterfaceFixture | ||
> { | ||
constructor( | ||
@Inject(PHOTO_CRUD_SERVICE_TOKEN) | ||
protected crudService: TypeOrmCrudService<PhotoEntityInterfaceFixture>, | ||
) { | ||
super(crudService); | ||
} | ||
|
||
@CrudGetMany | ||
async getMany(@CrudRequest() crudRequest: CrudRequestInterface) { | ||
return this.crudService.getMany(crudRequest); | ||
} | ||
|
||
@CrudGetOne | ||
async getOne(@CrudRequest() crudRequest: CrudRequestInterface) { | ||
return this.crudService.getOne(crudRequest); | ||
} | ||
|
||
@CrudCreateMany | ||
async createMany( | ||
@CrudRequest() crudRequest: CrudRequestInterface, | ||
@CrudBody() dto: PhotoCreateManyDtoFixture, | ||
) { | ||
return this.crudService.createMany(crudRequest, dto); | ||
} | ||
|
||
@CrudCreateOne | ||
async createOne( | ||
@CrudRequest() crudRequest: CrudRequestInterface, | ||
@CrudBody() dto: PhotoCreateDtoFixture, | ||
) { | ||
return this.crudService.createOne(crudRequest, dto); | ||
} | ||
|
||
@CrudUpdateOne | ||
async updateOne( | ||
@CrudRequest() crudRequest: CrudRequestInterface, | ||
@CrudBody() dto: PhotoUpdateDtoFixture, | ||
) { | ||
return this.crudService.createOne(crudRequest, dto); | ||
} | ||
|
||
@CrudReplaceOne | ||
async replaceOne( | ||
@CrudRequest() crudRequest: CrudRequestInterface, | ||
@CrudBody() dto: PhotoUpdateDtoFixture, | ||
) { | ||
return this.crudService.replaceOne(crudRequest, dto); | ||
} | ||
|
||
@CrudDeleteOne | ||
async deleteOne(@CrudRequest() crudRequest: CrudRequestInterface) { | ||
return this.crudService.deleteOne(crudRequest); | ||
} | ||
|
||
@CrudRecoverOne | ||
async recoverOne(@CrudRequest() crudRequest: CrudRequestInterface) { | ||
return this.crudService.recoverOne(crudRequest); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/nestjs-crud/src/__fixtures__/photo-ccb-custom/photo-ccb-custom.module.fixture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
|
||
import { PhotoFixture } from '../photo/photo.entity.fixture'; | ||
|
||
import { | ||
PhotoCcbCustomControllerFixture, | ||
PhotoCcbCustomCrudServiceFixture, | ||
PHOTO_CRUD_SERVICE_TOKEN, | ||
} from './photo-ccb-custom.controller.fixture'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([PhotoFixture])], | ||
providers: [ | ||
{ | ||
provide: PHOTO_CRUD_SERVICE_TOKEN, | ||
useClass: PhotoCcbCustomCrudServiceFixture, | ||
}, | ||
], | ||
controllers: [PhotoCcbCustomControllerFixture], | ||
}) | ||
export class PhotoCcbCustomModuleFixture {} |
54 changes: 54 additions & 0 deletions
54
packages/nestjs-crud/src/__fixtures__/photo-ccb-ext/photo-ccb-ext.controller.fixture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { PhotoEntityInterfaceFixture } from '../photo/interfaces/photo-entity.interface.fixture'; | ||
import { PhotoCreatableInterfaceFixture } from '../photo/interfaces/photo-creatable.interface.fixture'; | ||
import { PhotoUpdatableInterfaceFixture } from '../photo/interfaces/photo-updatable.interface.fixture'; | ||
import { PhotoDtoFixture } from '../photo/dto/photo.dto.fixture'; | ||
import { PhotoPaginatedDtoFixture } from '../photo/dto/photo-paginated.dto.fixture'; | ||
import { PhotoCreateDtoFixture } from '../photo/dto/photo-create.dto.fixture'; | ||
import { PhotoCreateManyDtoFixture } from '../photo/dto/photo-create-many.dto.fixture'; | ||
import { PhotoUpdateDtoFixture } from '../photo/dto/photo-update.dto.fixture'; | ||
import { ConfigurableCrudBuilder } from '../../util/configurable-crud.builder'; | ||
import { CrudSoftDelete } from '../../decorators/routes/crud-soft-delete.decorator'; | ||
|
||
export const PHOTO_CRUD_SERVICE_TOKEN = Symbol('__PHOTO_CRUD_SERVICE_TOKEN__'); | ||
|
||
const crudBuilder = new ConfigurableCrudBuilder< | ||
PhotoEntityInterfaceFixture, | ||
PhotoCreatableInterfaceFixture, | ||
PhotoUpdatableInterfaceFixture | ||
>(); | ||
|
||
const { ConfigurableControllerClass, ConfigurableServiceClass } = | ||
crudBuilder.build({ | ||
service: { | ||
entityKey: 'photo', | ||
injectionToken: PHOTO_CRUD_SERVICE_TOKEN, | ||
}, | ||
controller: { | ||
path: 'photo', | ||
model: { | ||
type: PhotoDtoFixture, | ||
paginatedType: PhotoPaginatedDtoFixture, | ||
}, | ||
}, | ||
getMany: {}, | ||
getOne: {}, | ||
createMany: { | ||
dto: PhotoCreateManyDtoFixture, | ||
}, | ||
createOne: { | ||
dto: PhotoCreateDtoFixture, | ||
}, | ||
updateOne: { | ||
dto: PhotoUpdateDtoFixture, | ||
}, | ||
replaceOne: { | ||
dto: PhotoUpdateDtoFixture, | ||
}, | ||
deleteOne: { | ||
extraDecorators: [CrudSoftDelete(true)], | ||
}, | ||
recoverOne: { path: 'recover/:id' }, | ||
}); | ||
|
||
export class PhotoCcbExtCrudServiceFixture extends ConfigurableServiceClass {} | ||
export class PhotoCcbExtControllerFixture extends ConfigurableControllerClass {} |
28 changes: 28 additions & 0 deletions
28
packages/nestjs-crud/src/__fixtures__/photo-ccb-ext/photo-ccb-ext.module.fixture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { TypeOrmExtModule } from '@concepta/nestjs-typeorm-ext'; | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { PhotoFixture } from '../photo/photo.entity.fixture'; | ||
|
||
import { | ||
PhotoCcbExtControllerFixture, | ||
PhotoCcbExtCrudServiceFixture, | ||
PHOTO_CRUD_SERVICE_TOKEN, | ||
} from './photo-ccb-ext.controller.fixture'; | ||
|
||
@Module({ | ||
imports: [ | ||
TypeOrmExtModule.forFeature({ | ||
photo: { | ||
entity: PhotoFixture, | ||
}, | ||
}), | ||
], | ||
providers: [ | ||
{ | ||
provide: PHOTO_CRUD_SERVICE_TOKEN, | ||
useClass: PhotoCcbExtCrudServiceFixture, | ||
}, | ||
], | ||
controllers: [PhotoCcbExtControllerFixture], | ||
}) | ||
export class PhotoCcbExtModuleFixture {} |
Oops, something went wrong.