feat: change id to identity instead for general purpose unique identifier

This commit is contained in:
Supan Adit Pratama 2024-11-02 00:51:57 +07:00
parent c7ae346c07
commit 81daab1f4d
14 changed files with 27 additions and 31 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -5,7 +5,7 @@ export class CreateExcutor extends DefaultExecutor {
constructor(process: CreateProcess, data) {
super(process);
// Set data to process
process.data = data;
process.payload = data;
}
static async bootstrap(process: CreateProcess, data): Promise<any> {

View File

@ -6,7 +6,7 @@ export class DeleteExecutor extends DefaultExecutor {
constructor(process: DeleteProcess, id) {
super(process);
// Set the id of the data
process.id = id;
process.identity = id;
}
static async bootstrap(process: DeleteProcess, id): Promise<any> {

View File

@ -5,7 +5,7 @@ export class ReadExecutor extends DefaultExecutor {
constructor(process: ReadProcess, id) {
super(process);
// Set the id of the data
process.id = id;
process.identity = id;
}
static async bootstrap(process: ReadProcess, id): Promise<any> {

View File

@ -6,8 +6,8 @@ export class UpdateExecutor extends DefaultExecutor {
constructor(process: UpdateProcess, id, data) {
super(process);
// Set the id and data to process
process.id = id;
process.data = data;
process.identity = id;
process.payload = data;
}
static async bootstrap(process: UpdateProcess, id, data): Promise<any> {

View File

@ -1,5 +1,5 @@
import { DefaultProcess } from './default.process';
export class CreateProcess extends DefaultProcess {
public data;
public payload;
}

View File

@ -2,5 +2,5 @@ import { DefaultProcess } from './default.process';
// @TODO: DeleteProcess and ReadProcess are the same, should be refactored next
export class DeleteProcess extends DefaultProcess {
public id;
public identity;
}

View File

@ -1,5 +1,5 @@
import { DefaultProcess } from './default.process';
export class ReadProcess extends DefaultProcess {
public id;
public identity;
}

View File

@ -2,7 +2,7 @@ import { DefaultProcess } from './default.process';
export class UpdateProcess extends DefaultProcess {
// @TODO: The property of id can be take from ReadProcess which is extended
public id;
public identity;
// @TODO: The property of data can be take from CreateProcess which is extended
public data;
public payload;
}

View File

@ -50,8 +50,8 @@ class SkeletonCRUDController implements ISkeletonCRUDController {
}
@Delete(':id')
async delete(@Param('id') providedKey) {
return await DeleteExecutor.bootstrap(this.deleteProcess, providedKey);
async delete(@Param('id') identity) {
return await DeleteExecutor.bootstrap(this.deleteProcess, identity);
}
@Get('list')
@ -66,17 +66,13 @@ class SkeletonCRUDController implements ISkeletonCRUDController {
}
@Get(':id')
async read(@Param('id') providedKey) {
return await ReadExecutor.bootstrap(this.readProcess, providedKey);
async read(@Param('id') identity) {
return await ReadExecutor.bootstrap(this.readProcess, identity);
}
@Patch(':id')
async update(@Param('id') providedKey, @Body() body) {
return await UpdateExecutor.bootstrap(
this.updateProcess,
providedKey,
body,
);
async update(@Param('id') identity, @Body() body) {
return await UpdateExecutor.bootstrap(this.updateProcess, identity, body);
}
}

View File

@ -4,7 +4,7 @@ export class CustomReadProcess extends PrismaReadProcess {
customResult;
async before(): Promise<any> {
console.log('The ID requested in path parameter', this.id);
console.log('The ID requested in path parameter', this.identity);
}
async after(): Promise<any> {
this.customResult = {