remoed base service + base controller (cause of conflitcts)
This commit is contained in:
parent
d05b46e117
commit
0fa43f7d9c
@ -1,33 +0,0 @@
|
|||||||
import { Body, Delete, Get, Param, Patch, Post } from "@nestjs/common";
|
|
||||||
import { BaseService } from "./base.service";
|
|
||||||
import type { DeepPartial, ObjectLiteral } from "typeorm";
|
|
||||||
import type { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity.js";
|
|
||||||
|
|
||||||
export class BaseController<T extends ObjectLiteral> {
|
|
||||||
constructor(protected readonly service: BaseService<T>) { }
|
|
||||||
|
|
||||||
@Get()
|
|
||||||
getAll(relations: string[] = []) {
|
|
||||||
return this.service.findAll(relations);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(':id')
|
|
||||||
getOne(@Param('id') id: string) {
|
|
||||||
return this.service.findOne(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post()
|
|
||||||
create(@Body() data: DeepPartial<T>) {
|
|
||||||
return this.service.create(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Patch(':id')
|
|
||||||
update(@Param('id') id: string, @Body() data: QueryDeepPartialEntity<T>) {
|
|
||||||
return this.service.update(id, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Delete(':id')
|
|
||||||
delete(@Param('id') id: string) {
|
|
||||||
return this.service.delete(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
import { DeepPartial, ObjectLiteral, Repository } from "typeorm";
|
|
||||||
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity.js";
|
|
||||||
|
|
||||||
export class BaseService<T extends ObjectLiteral> {
|
|
||||||
constructor(protected readonly repo: Repository<T>) { }
|
|
||||||
|
|
||||||
findAll(relations: string[] = []) {
|
|
||||||
return this.repo.find({ relations });
|
|
||||||
}
|
|
||||||
|
|
||||||
findOne(id: string, relations: string[] = []) {
|
|
||||||
return this.repo.findOne({ where: { id } as any, relations });
|
|
||||||
}
|
|
||||||
|
|
||||||
create(data: DeepPartial<T>) {
|
|
||||||
const entity = this.repo.create(data);
|
|
||||||
return this.repo.save(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
async update(id: string, data: QueryDeepPartialEntity<T>) {
|
|
||||||
await this.repo.update(id, data);
|
|
||||||
return this.findOne(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete(id: string) {
|
|
||||||
return this.repo.delete(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user