feat(proejct): project curd.
This commit is contained in:
35
src/projects/projects.service.ts
Normal file
35
src/projects/projects.service.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { BaseDbService } from 'src/commons/services/base-db.service';
|
||||
import { Repository } from 'typeorm';
|
||||
import { CreateProjectInput } from './dtos/create-project.input';
|
||||
import { Project } from './project.entity';
|
||||
|
||||
@Injectable()
|
||||
export class ProjectsService extends BaseDbService<Project> {
|
||||
readonly uniqueFields: Array<keyof Project> = ['name'];
|
||||
constructor(
|
||||
@InjectRepository(Project)
|
||||
readonly repository: Repository<Project>,
|
||||
) {
|
||||
super(repository);
|
||||
}
|
||||
|
||||
async list() {
|
||||
return this.repository.find();
|
||||
}
|
||||
|
||||
async create(dto: CreateProjectInput) {
|
||||
await this.isDuplicateEntity(dto);
|
||||
return await this.repository.save(this.repository.create(dto));
|
||||
}
|
||||
|
||||
async update(id: string, dto: CreateProjectInput) {
|
||||
await this.isDuplicateEntityForUpdate(id, dto);
|
||||
await this.repository.update({ id }, dto);
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
return (await this.repository.softDelete({ id })).affected;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user