mirror of
https://github.com/aditama-labs/nest-autocrud.git
synced 2024-11-24 12:56:22 +00:00
feat: remove all promise for now to let user have flexibility
This commit is contained in:
parent
bb23bd0db9
commit
3ca746548e
@ -9,7 +9,7 @@ import {
|
||||
import { PrismaListProcess } from '../processes/list.process';
|
||||
|
||||
export interface PrismaModuleOptions {
|
||||
delegate: (prisma: PrismaService) => any;
|
||||
delegate: (prisma: PrismaService) => unknown;
|
||||
processCreate?: typeof PrismaCreateProcess;
|
||||
processDelete?: typeof PrismaDeleteProcess;
|
||||
processList?: typeof PrismaListProcess;
|
||||
|
@ -34,7 +34,7 @@ import { PrismaListProcess } from './processes/list.process';
|
||||
],
|
||||
})
|
||||
export class PrismaModule extends ConfigurableModuleClass {
|
||||
private static autoPresetProvider(providers, option, key, preset): any {
|
||||
private static autoPresetProvider(providers, option, key, preset) {
|
||||
if (option) {
|
||||
providers = [
|
||||
...providers,
|
||||
|
@ -7,7 +7,7 @@ export class PrismaCreateProcess
|
||||
{
|
||||
public payload;
|
||||
|
||||
async process(): Promise<any> {
|
||||
async process() {
|
||||
this.result = await this.getDelegate().create({
|
||||
data: this.payload,
|
||||
});
|
||||
|
@ -5,9 +5,9 @@ export class PrismaDeleteProcess
|
||||
extends PrismaProcess
|
||||
implements DeleteProcess
|
||||
{
|
||||
public identity: any;
|
||||
public identity;
|
||||
|
||||
async process(): Promise<any> {
|
||||
async process() {
|
||||
this.result = await this.getDelegate().delete({
|
||||
where: { id: this.identity },
|
||||
});
|
||||
|
@ -2,7 +2,7 @@ import { ListProcess } from '@aditama-labs/nest-autocrud/skeleton';
|
||||
import { PrismaProcess } from './prisma.process';
|
||||
|
||||
export class PrismaListProcess extends PrismaProcess implements ListProcess {
|
||||
async process(): Promise<any> {
|
||||
async process() {
|
||||
this.result = await this.getDelegate().findMany();
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ export class PrismaPaginationProcess
|
||||
{
|
||||
params: IPaginationParam;
|
||||
|
||||
async process(): Promise<any> {
|
||||
async process() {
|
||||
const { page, limit } = this.params;
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
|
@ -4,7 +4,7 @@ import { PrismaProcess } from './prisma.process';
|
||||
export class PrismaReadProcess extends PrismaProcess implements ReadProcess {
|
||||
public identity;
|
||||
|
||||
async process(): Promise<any> {
|
||||
async process() {
|
||||
this.result = await this.getDelegate().findUnique({
|
||||
where: { id: this.identity },
|
||||
});
|
||||
|
@ -5,10 +5,10 @@ export class PrismaUpdateProcess
|
||||
extends PrismaProcess
|
||||
implements UpdateProcess
|
||||
{
|
||||
public identity: any;
|
||||
public payload: any;
|
||||
public identity;
|
||||
public payload;
|
||||
|
||||
async process(): Promise<any> {
|
||||
async process() {
|
||||
this.result = await this.getDelegate().update({
|
||||
data: this.payload,
|
||||
where: { id: this.identity },
|
||||
|
@ -8,7 +8,7 @@ export class CreateExcutor extends DefaultExecutor {
|
||||
process.payload = data;
|
||||
}
|
||||
|
||||
static async bootstrap(process: CreateProcess, data): Promise<any> {
|
||||
static async bootstrap(process: CreateProcess, data) {
|
||||
const executor = new CreateExcutor(process, data);
|
||||
await executor.execute();
|
||||
return executor.getOutput();
|
||||
|
@ -12,7 +12,7 @@ export class DefaultExecutor {
|
||||
await this.process.after();
|
||||
}
|
||||
|
||||
getOutput(): any {
|
||||
getOutput() {
|
||||
return this.process.output();
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ export class DeleteExecutor extends DefaultExecutor {
|
||||
process.identity = id;
|
||||
}
|
||||
|
||||
static async bootstrap(process: DeleteProcess, id): Promise<any> {
|
||||
static async bootstrap(process: DeleteProcess, id) {
|
||||
const executor = new DeleteExecutor(process, id);
|
||||
await executor.execute();
|
||||
return executor.getOutput();
|
||||
|
@ -6,7 +6,7 @@ export class ListExecutor extends DefaultExecutor {
|
||||
super(process);
|
||||
}
|
||||
|
||||
static async bootstrap(process: ListProcess): Promise<any> {
|
||||
static async bootstrap(process: ListProcess) {
|
||||
const executor = new ListExecutor(process);
|
||||
await executor.execute();
|
||||
return executor.getOutput();
|
||||
|
@ -12,7 +12,7 @@ export class PaginationExecutor extends DefaultExecutor {
|
||||
static async bootstrap(
|
||||
process: PaginationProcess,
|
||||
params: PaginationParamDTO,
|
||||
): Promise<any> {
|
||||
) {
|
||||
const executor = new PaginationExecutor(process, params);
|
||||
await executor.execute();
|
||||
return executor.getOutput();
|
||||
|
@ -8,7 +8,7 @@ export class ReadExecutor extends DefaultExecutor {
|
||||
process.identity = id;
|
||||
}
|
||||
|
||||
static async bootstrap(process: ReadProcess, id): Promise<any> {
|
||||
static async bootstrap(process: ReadProcess, id) {
|
||||
const executor = new ReadExecutor(process, id);
|
||||
await executor.execute();
|
||||
return executor.getOutput();
|
||||
|
@ -10,7 +10,7 @@ export class UpdateExecutor extends DefaultExecutor {
|
||||
process.payload = data;
|
||||
}
|
||||
|
||||
static async bootstrap(process: UpdateProcess, id, data): Promise<any> {
|
||||
static async bootstrap(process: UpdateProcess, id, data) {
|
||||
const executor = new UpdateExecutor(process, id, data);
|
||||
await executor.execute();
|
||||
return executor.getOutput();
|
||||
|
@ -3,12 +3,13 @@ import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
|
||||
export class DefaultProcess implements ISkeletonProcess {
|
||||
protected result;
|
||||
|
||||
async initialization(): Promise<any> {}
|
||||
async before(): Promise<any> {}
|
||||
async begin(): Promise<any> {}
|
||||
async process(): Promise<any> {}
|
||||
async end(): Promise<any> {}
|
||||
async after(): Promise<any> {}
|
||||
// @TODO: Soon it will conver to abstract, for now I just set as regular class for simplicity and making developer optionally override it instead of force it
|
||||
async initialization() {}
|
||||
async before() {}
|
||||
async begin() {}
|
||||
async process() {}
|
||||
async end() {}
|
||||
async after() {}
|
||||
|
||||
output() {
|
||||
return this.result;
|
||||
|
@ -45,7 +45,7 @@ export class SkeletonCRUDController implements ISkeletonCRUDController {
|
||||
) {}
|
||||
|
||||
@Post()
|
||||
async create(@Body() body): Promise<any> {
|
||||
async create(@Body() body) {
|
||||
return await CreateExcutor.bootstrap(this.createProcess, body);
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ export class SkeletonCRUDController implements ISkeletonCRUDController {
|
||||
}
|
||||
|
||||
// NOTES:
|
||||
// - This method only works when return as `any`
|
||||
// - This method only works when return as `any` or not define the type at all
|
||||
// - I know this is not recommended but.... is there any way to pass custom unique identifier ?
|
||||
// - Everyone still can use SkeletonCRUDController with no issue if don't want or don't like this approach, but... unique identifier must ID for sure and the type should either UUID, String or Number
|
||||
// - Correct me if I wrong. I already read the main repository of NestJS and they use Reflect for passing some metadata ( I know how to do it ) but... it still not possible for dynamic unique identifier
|
||||
@ -89,7 +89,7 @@ export const CustomCRUDController = (options?: ControllerOption) => {
|
||||
|
||||
class WrapperCRUDController extends SkeletonCRUDController {
|
||||
@Post()
|
||||
async create(@Body() body): Promise<any> {
|
||||
async create(@Body() body) {
|
||||
return await super.create(body);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user