feat: added get workspaces by user and some refactors
This commit is contained in:
@@ -4,38 +4,15 @@ import { Repository } from "typeorm";
|
||||
import { TMWorkspace } from "../entities/workspace.entity";
|
||||
|
||||
@Injectable()
|
||||
export class WorkspaceRepository {
|
||||
constructor(
|
||||
@InjectRepository(TMWorkspace)
|
||||
private readonly repository: Repository<TMWorkspace>,
|
||||
) {}
|
||||
|
||||
findAll() {
|
||||
return this.repository.find({
|
||||
relations: ["projects", "users"],
|
||||
});
|
||||
export class WorkspaceRepository extends Repository<TMWorkspace> {
|
||||
constructor(@InjectRepository(TMWorkspace) workspaceRepository: Repository<TMWorkspace>) {
|
||||
super(workspaceRepository.target, workspaceRepository.manager, workspaceRepository.queryRunner);
|
||||
}
|
||||
|
||||
findOneById(id: string) {
|
||||
return this.repository.findOne({
|
||||
where: { id },
|
||||
relations: ["projects", "users"],
|
||||
});
|
||||
}
|
||||
|
||||
create(data: Partial<TMWorkspace>) {
|
||||
return this.repository.create(data);
|
||||
}
|
||||
|
||||
save(workspace: TMWorkspace) {
|
||||
return this.repository.save(workspace);
|
||||
}
|
||||
|
||||
update(id: string, data: Partial<TMWorkspace>) {
|
||||
return this.repository.update(id, data);
|
||||
}
|
||||
|
||||
delete(id: string) {
|
||||
return this.repository.delete(id);
|
||||
async findByUser(userId: string): Promise<TMWorkspace[]> {
|
||||
return this.createQueryBuilder("workspace")
|
||||
.innerJoin("workspace.users", "users")
|
||||
.where("user.id = :userId", { userId })
|
||||
.getMany();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user