refactor: isolated the repository and logic in services
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { In, Repository } from 'typeorm';
|
||||
import { WorkspaceRepository } from '../repositories/workspace.repository';
|
||||
import { TMWorkspace } from '../entities/workspace.entity';
|
||||
import { CreateWorkspaceDto } from '../dto/workspace/create-workspace.dto';
|
||||
import { UpdateWorkspaceDto } from '../dto/workspace/update-workspace.dto';
|
||||
@@ -9,23 +10,17 @@ import { User } from '../../users/entities/user.entity';
|
||||
@Injectable()
|
||||
export class WorkspaceService {
|
||||
constructor(
|
||||
@InjectRepository(TMWorkspace)
|
||||
private readonly workspaceRepository: Repository<TMWorkspace>,
|
||||
private readonly workspaceRepository: WorkspaceRepository,
|
||||
@InjectRepository(User)
|
||||
private readonly userRepository: Repository<User>,
|
||||
) {}
|
||||
|
||||
findAll(): Promise<TMWorkspace[]> {
|
||||
return this.workspaceRepository.find({
|
||||
relations: ['workspaceType', 'projects', 'users'],
|
||||
});
|
||||
return this.workspaceRepository.findAll();
|
||||
}
|
||||
|
||||
async findOneOrFail(id: string): Promise<TMWorkspace> {
|
||||
const workspace = await this.workspaceRepository.findOne({
|
||||
where: { id },
|
||||
relations: ['workspaceType', 'projects', 'users'],
|
||||
});
|
||||
const workspace = await this.workspaceRepository.findOneById(id);
|
||||
if (!workspace) throw new NotFoundException(`Workspace #${id} not found`);
|
||||
return workspace;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user