mirror of
https://github.com/aditama-labs/nest-autocrud.git
synced 2024-11-21 19:06:21 +00:00
feat: change id to identity instead for general purpose unique identifier
This commit is contained in:
parent
c7ae346c07
commit
81daab1f4d
@ -5,11 +5,11 @@ export class PrismaCreateProcess
|
|||||||
extends PrismaProcess
|
extends PrismaProcess
|
||||||
implements CreateProcess
|
implements CreateProcess
|
||||||
{
|
{
|
||||||
public data;
|
public payload;
|
||||||
|
|
||||||
async process(): Promise<any> {
|
async process(): Promise<any> {
|
||||||
this.result = await this.getDelegate().create({
|
this.result = await this.getDelegate().create({
|
||||||
data: this.data,
|
data: this.payload,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,11 @@ export class PrismaDeleteProcess
|
|||||||
extends PrismaProcess
|
extends PrismaProcess
|
||||||
implements DeleteProcess
|
implements DeleteProcess
|
||||||
{
|
{
|
||||||
public id: any;
|
public identity: any;
|
||||||
|
|
||||||
async process(): Promise<any> {
|
async process(): Promise<any> {
|
||||||
this.result = await this.getDelegate().delete({
|
this.result = await this.getDelegate().delete({
|
||||||
where: { id: this.id },
|
where: { id: this.identity },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,11 @@ import { ReadProcess } from '@aditama-labs/nest-autocrud/skeleton';
|
|||||||
import { PrismaProcess } from './prisma.process';
|
import { PrismaProcess } from './prisma.process';
|
||||||
|
|
||||||
export class PrismaReadProcess extends PrismaProcess implements ReadProcess {
|
export class PrismaReadProcess extends PrismaProcess implements ReadProcess {
|
||||||
public id;
|
public identity;
|
||||||
|
|
||||||
async process(): Promise<any> {
|
async process(): Promise<any> {
|
||||||
this.result = await this.getDelegate().findUnique({
|
this.result = await this.getDelegate().findUnique({
|
||||||
where: { id: this.id },
|
where: { id: this.identity },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,13 @@ export class PrismaUpdateProcess
|
|||||||
extends PrismaProcess
|
extends PrismaProcess
|
||||||
implements UpdateProcess
|
implements UpdateProcess
|
||||||
{
|
{
|
||||||
public id: any;
|
public identity: any;
|
||||||
public data: any;
|
public payload: any;
|
||||||
|
|
||||||
async process(): Promise<any> {
|
async process(): Promise<any> {
|
||||||
this.result = await this.getDelegate().update({
|
this.result = await this.getDelegate().update({
|
||||||
data: this.data,
|
data: this.payload,
|
||||||
where: { id: this.id },
|
where: { id: this.identity },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ export class CreateExcutor extends DefaultExecutor {
|
|||||||
constructor(process: CreateProcess, data) {
|
constructor(process: CreateProcess, data) {
|
||||||
super(process);
|
super(process);
|
||||||
// Set data to process
|
// Set data to process
|
||||||
process.data = data;
|
process.payload = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async bootstrap(process: CreateProcess, data): Promise<any> {
|
static async bootstrap(process: CreateProcess, data): Promise<any> {
|
||||||
|
@ -6,7 +6,7 @@ export class DeleteExecutor extends DefaultExecutor {
|
|||||||
constructor(process: DeleteProcess, id) {
|
constructor(process: DeleteProcess, id) {
|
||||||
super(process);
|
super(process);
|
||||||
// Set the id of the data
|
// Set the id of the data
|
||||||
process.id = id;
|
process.identity = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async bootstrap(process: DeleteProcess, id): Promise<any> {
|
static async bootstrap(process: DeleteProcess, id): Promise<any> {
|
||||||
|
@ -5,7 +5,7 @@ export class ReadExecutor extends DefaultExecutor {
|
|||||||
constructor(process: ReadProcess, id) {
|
constructor(process: ReadProcess, id) {
|
||||||
super(process);
|
super(process);
|
||||||
// Set the id of the data
|
// Set the id of the data
|
||||||
process.id = id;
|
process.identity = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async bootstrap(process: ReadProcess, id): Promise<any> {
|
static async bootstrap(process: ReadProcess, id): Promise<any> {
|
||||||
|
@ -6,8 +6,8 @@ export class UpdateExecutor extends DefaultExecutor {
|
|||||||
constructor(process: UpdateProcess, id, data) {
|
constructor(process: UpdateProcess, id, data) {
|
||||||
super(process);
|
super(process);
|
||||||
// Set the id and data to process
|
// Set the id and data to process
|
||||||
process.id = id;
|
process.identity = id;
|
||||||
process.data = data;
|
process.payload = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async bootstrap(process: UpdateProcess, id, data): Promise<any> {
|
static async bootstrap(process: UpdateProcess, id, data): Promise<any> {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { DefaultProcess } from './default.process';
|
import { DefaultProcess } from './default.process';
|
||||||
|
|
||||||
export class CreateProcess extends DefaultProcess {
|
export class CreateProcess extends DefaultProcess {
|
||||||
public data;
|
public payload;
|
||||||
}
|
}
|
||||||
|
@ -2,5 +2,5 @@ import { DefaultProcess } from './default.process';
|
|||||||
|
|
||||||
// @TODO: DeleteProcess and ReadProcess are the same, should be refactored next
|
// @TODO: DeleteProcess and ReadProcess are the same, should be refactored next
|
||||||
export class DeleteProcess extends DefaultProcess {
|
export class DeleteProcess extends DefaultProcess {
|
||||||
public id;
|
public identity;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { DefaultProcess } from './default.process';
|
import { DefaultProcess } from './default.process';
|
||||||
|
|
||||||
export class ReadProcess extends DefaultProcess {
|
export class ReadProcess extends DefaultProcess {
|
||||||
public id;
|
public identity;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import { DefaultProcess } from './default.process';
|
|||||||
|
|
||||||
export class UpdateProcess extends DefaultProcess {
|
export class UpdateProcess extends DefaultProcess {
|
||||||
// @TODO: The property of id can be take from ReadProcess which is extended
|
// @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
|
// @TODO: The property of data can be take from CreateProcess which is extended
|
||||||
public data;
|
public payload;
|
||||||
}
|
}
|
||||||
|
@ -50,8 +50,8 @@ class SkeletonCRUDController implements ISkeletonCRUDController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
async delete(@Param('id') providedKey) {
|
async delete(@Param('id') identity) {
|
||||||
return await DeleteExecutor.bootstrap(this.deleteProcess, providedKey);
|
return await DeleteExecutor.bootstrap(this.deleteProcess, identity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('list')
|
@Get('list')
|
||||||
@ -66,17 +66,13 @@ class SkeletonCRUDController implements ISkeletonCRUDController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
async read(@Param('id') providedKey) {
|
async read(@Param('id') identity) {
|
||||||
return await ReadExecutor.bootstrap(this.readProcess, providedKey);
|
return await ReadExecutor.bootstrap(this.readProcess, identity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
async update(@Param('id') providedKey, @Body() body) {
|
async update(@Param('id') identity, @Body() body) {
|
||||||
return await UpdateExecutor.bootstrap(
|
return await UpdateExecutor.bootstrap(this.updateProcess, identity, body);
|
||||||
this.updateProcess,
|
|
||||||
providedKey,
|
|
||||||
body,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ export class CustomReadProcess extends PrismaReadProcess {
|
|||||||
customResult;
|
customResult;
|
||||||
|
|
||||||
async before(): Promise<any> {
|
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> {
|
async after(): Promise<any> {
|
||||||
this.customResult = {
|
this.customResult = {
|
||||||
|
Loading…
Reference in New Issue
Block a user