41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { Injectable, NotFoundException } from "@nestjs/common";
|
|
import { CreateWorkspaceDto } from "../dto/workspace/create-workspace.dto";
|
|
import { WorkspaceRepository } from "../repositories/workspace.repository";
|
|
import { UpdateWorkspaceDto } from "../dto/workspace/update-workspace.dto";
|
|
|
|
@Injectable()
|
|
export class WorkspaceService {
|
|
constructor(
|
|
private readonly workspaceRepository: WorkspaceRepository,
|
|
) {}
|
|
|
|
findAll() {
|
|
return this.workspaceRepository.findAll();
|
|
}
|
|
|
|
async findOne(id: string) {
|
|
const workspace = await this.workspaceRepository.findOneById(id);
|
|
|
|
if (!workspace) {
|
|
throw new NotFoundException(`Workspace #${id} not found`);
|
|
}
|
|
|
|
return workspace;
|
|
}
|
|
|
|
async create(dto: CreateWorkspaceDto) {
|
|
const workspace = this.workspaceRepository.create(dto);
|
|
return this.workspaceRepository.save(workspace);
|
|
}
|
|
|
|
async update(id: string, dto: UpdateWorkspaceDto) {
|
|
await this.findOne(id);
|
|
await this.workspaceRepository.update(id, dto);
|
|
return this.findOne(id);
|
|
}
|
|
|
|
async remove(id: string) {
|
|
await this.findOne(id);
|
|
await this.workspaceRepository.delete(id);
|
|
}
|
|
} |