mirror of
https://github.com/aditama-labs/nest-autocrud.git
synced 2024-11-21 19:06:21 +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';
|
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;
|
||||||
|
@ -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,
|
||||||
|
@ -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,
|
||||||
});
|
});
|
||||||
|
@ -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 },
|
||||||
});
|
});
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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 },
|
||||||
});
|
});
|
||||||
|
@ -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 },
|
||||||
|
@ -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();
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
@ -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();
|
||||||
|
@ -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();
|
||||||
|
@ -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();
|
||||||
|
@ -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();
|
||||||
|
@ -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;
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user