xxx
This commit is contained in:
42
api/src/modules/system/system.service.ts
Normal file
42
api/src/modules/system/system.service.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { CreateSystemDto } from './dto/create-system.dto';
|
||||
import { UpdateSystemDto } from './dto/update-system.dto';
|
||||
import { KeySystemRepository } from 'src/model/repositories';
|
||||
import { User } from 'src/model/entitites';
|
||||
|
||||
@Injectable()
|
||||
export class SystemService {
|
||||
constructor(private systemRepo: KeySystemRepository) {}
|
||||
|
||||
async create(user: User, createSystemDto: CreateSystemDto) {
|
||||
const sys = this.systemRepo.create(createSystemDto);
|
||||
sys.managers = [user];
|
||||
try {
|
||||
const res = await this.systemRepo.save(sys);
|
||||
return res;
|
||||
} catch (e) {
|
||||
throw new HttpException(e.code, HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
}
|
||||
|
||||
findAll(user: User) {
|
||||
return this.systemRepo.find({
|
||||
where: { managers: { id: user.id } },
|
||||
order: { name: { direction: 'ASC' } },
|
||||
});
|
||||
}
|
||||
|
||||
findOne(id: string) {
|
||||
return `This action returns a #${id} system`;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
update(id: string, updateSystemDto: UpdateSystemDto) {
|
||||
return `This action updates a #${id} system`;
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
const system = await this.systemRepo.findOne({ where: { id } });
|
||||
return this.systemRepo.softRemove(system);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user