38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { BaseDbService } from '../commons/services/base-db.service';
|
|
import { Repository } from 'typeorm';
|
|
import { CreateProjectInput } from './dtos/create-project.input';
|
|
import { Project } from './project.entity';
|
|
import { UpdateProjectInput } from './dtos/update-project.input';
|
|
|
|
@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(dto: UpdateProjectInput) {
|
|
await this.isDuplicateEntityForUpdate(dto.id, dto);
|
|
const old = await this.findOne(dto.id);
|
|
return await this.repository.save(this.repository.merge(old, dto));
|
|
}
|
|
|
|
async remove(id: string) {
|
|
return (await this.repository.softDelete({ id })).affected;
|
|
}
|
|
}
|