feat: remove all promise for now to let user have flexibility

This commit is contained in:
Supan Adit Pratama 2024-11-02 01:22:14 +07:00
parent bb23bd0db9
commit 3ca746548e
17 changed files with 28 additions and 27 deletions

View File

@ -9,7 +9,7 @@ import {
import { PrismaListProcess } from '../processes/list.process'; import { PrismaListProcess } from '../processes/list.process';
export interface PrismaModuleOptions { export interface PrismaModuleOptions {
delegate: (prisma: PrismaService) => any; delegate: (prisma: PrismaService) => unknown;
processCreate?: typeof PrismaCreateProcess; processCreate?: typeof PrismaCreateProcess;
processDelete?: typeof PrismaDeleteProcess; processDelete?: typeof PrismaDeleteProcess;
processList?: typeof PrismaListProcess; processList?: typeof PrismaListProcess;

View File

@ -34,7 +34,7 @@ import { PrismaListProcess } from './processes/list.process';
], ],
}) })
export class PrismaModule extends ConfigurableModuleClass { export class PrismaModule extends ConfigurableModuleClass {
private static autoPresetProvider(providers, option, key, preset): any { private static autoPresetProvider(providers, option, key, preset) {
if (option) { if (option) {
providers = [ providers = [
...providers, ...providers,

View File

@ -7,7 +7,7 @@ export class PrismaCreateProcess
{ {
public payload; public payload;
async process(): Promise<any> { async process() {
this.result = await this.getDelegate().create({ this.result = await this.getDelegate().create({
data: this.payload, data: this.payload,
}); });

View File

@ -5,9 +5,9 @@ export class PrismaDeleteProcess
extends PrismaProcess extends PrismaProcess
implements DeleteProcess implements DeleteProcess
{ {
public identity: any; public identity;
async process(): Promise<any> { async process() {
this.result = await this.getDelegate().delete({ this.result = await this.getDelegate().delete({
where: { id: this.identity }, where: { id: this.identity },
}); });

View File

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

View File

@ -8,7 +8,7 @@ export class PrismaPaginationProcess
{ {
params: IPaginationParam; params: IPaginationParam;
async process(): Promise<any> { async process() {
const { page, limit } = this.params; const { page, limit } = this.params;
const skip = (page - 1) * limit; const skip = (page - 1) * limit;

View File

@ -4,7 +4,7 @@ import { PrismaProcess } from './prisma.process';
export class PrismaReadProcess extends PrismaProcess implements ReadProcess { export class PrismaReadProcess extends PrismaProcess implements ReadProcess {
public identity; public identity;
async process(): Promise<any> { async process() {
this.result = await this.getDelegate().findUnique({ this.result = await this.getDelegate().findUnique({
where: { id: this.identity }, where: { id: this.identity },
}); });

View File

@ -5,10 +5,10 @@ export class PrismaUpdateProcess
extends PrismaProcess extends PrismaProcess
implements UpdateProcess implements UpdateProcess
{ {
public identity: any; public identity;
public payload: any; public payload;
async process(): Promise<any> { async process() {
this.result = await this.getDelegate().update({ this.result = await this.getDelegate().update({
data: this.payload, data: this.payload,
where: { id: this.identity }, where: { id: this.identity },

View File

@ -8,7 +8,7 @@ export class CreateExcutor extends DefaultExecutor {
process.payload = data; process.payload = data;
} }
static async bootstrap(process: CreateProcess, data): Promise<any> { static async bootstrap(process: CreateProcess, data) {
const executor = new CreateExcutor(process, data); const executor = new CreateExcutor(process, data);
await executor.execute(); await executor.execute();
return executor.getOutput(); return executor.getOutput();

View File

@ -12,7 +12,7 @@ export class DefaultExecutor {
await this.process.after(); await this.process.after();
} }
getOutput(): any { getOutput() {
return this.process.output(); return this.process.output();
} }
} }

View File

@ -9,7 +9,7 @@ export class DeleteExecutor extends DefaultExecutor {
process.identity = id; process.identity = id;
} }
static async bootstrap(process: DeleteProcess, id): Promise<any> { static async bootstrap(process: DeleteProcess, id) {
const executor = new DeleteExecutor(process, id); const executor = new DeleteExecutor(process, id);
await executor.execute(); await executor.execute();
return executor.getOutput(); return executor.getOutput();

View File

@ -6,7 +6,7 @@ export class ListExecutor extends DefaultExecutor {
super(process); super(process);
} }
static async bootstrap(process: ListProcess): Promise<any> { static async bootstrap(process: ListProcess) {
const executor = new ListExecutor(process); const executor = new ListExecutor(process);
await executor.execute(); await executor.execute();
return executor.getOutput(); return executor.getOutput();

View File

@ -12,7 +12,7 @@ export class PaginationExecutor extends DefaultExecutor {
static async bootstrap( static async bootstrap(
process: PaginationProcess, process: PaginationProcess,
params: PaginationParamDTO, params: PaginationParamDTO,
): Promise<any> { ) {
const executor = new PaginationExecutor(process, params); const executor = new PaginationExecutor(process, params);
await executor.execute(); await executor.execute();
return executor.getOutput(); return executor.getOutput();

View File

@ -8,7 +8,7 @@ export class ReadExecutor extends DefaultExecutor {
process.identity = id; process.identity = id;
} }
static async bootstrap(process: ReadProcess, id): Promise<any> { static async bootstrap(process: ReadProcess, id) {
const executor = new ReadExecutor(process, id); const executor = new ReadExecutor(process, id);
await executor.execute(); await executor.execute();
return executor.getOutput(); return executor.getOutput();

View File

@ -10,7 +10,7 @@ export class UpdateExecutor extends DefaultExecutor {
process.payload = data; 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); const executor = new UpdateExecutor(process, id, data);
await executor.execute(); await executor.execute();
return executor.getOutput(); return executor.getOutput();

View File

@ -3,12 +3,13 @@ import { ISkeletonProcess } from '../interfaces/skeleton-process.interface';
export class DefaultProcess implements ISkeletonProcess { export class DefaultProcess implements ISkeletonProcess {
protected result; protected result;
async initialization(): 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 before(): Promise<any> {} async initialization() {}
async begin(): Promise<any> {} async before() {}
async process(): Promise<any> {} async begin() {}
async end(): Promise<any> {} async process() {}
async after(): Promise<any> {} async end() {}
async after() {}
output() { output() {
return this.result; return this.result;

View File

@ -45,7 +45,7 @@ export class SkeletonCRUDController implements ISkeletonCRUDController {
) {} ) {}
@Post() @Post()
async create(@Body() body): Promise<any> { async create(@Body() body) {
return await CreateExcutor.bootstrap(this.createProcess, body); return await CreateExcutor.bootstrap(this.createProcess, body);
} }
@ -77,7 +77,7 @@ export class SkeletonCRUDController implements ISkeletonCRUDController {
} }
// NOTES: // 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 ? // - 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 // - 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 // - 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 { class WrapperCRUDController extends SkeletonCRUDController {
@Post() @Post()
async create(@Body() body): Promise<any> { async create(@Body() body) {
return await super.create(body); return await super.create(body);
} }