Compare commits
6 Commits
c5b2cb93f0
...
9f61152d94
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f61152d94 | |||
| a14bd490be | |||
| 47a5a2abb4 | |||
| 5763cb7d6c | |||
| 35d0d9f7cd | |||
| d4bd593f5b |
@@ -0,0 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class Migrations1783244654421 implements MigrationInterface {
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class Taskmanager31783244669371 implements MigrationInterface {
|
||||
name = 'Taskmanager31783244669371'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "tm_workspaces" ADD CONSTRAINT "UQ_6496168de3e6c5f006d494ebac5" UNIQUE ("name")`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "tm_workspaces" DROP CONSTRAINT "UQ_6496168de3e6c5f006d494ebac5"`);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,9 +5,9 @@ import { connectionSource } from "./connection";
|
||||
// import { seedCityAndProvince } from "./seeders/iran-city.seeder";
|
||||
// import { seedNotifSettings } from "./seeders/notif-setting.seeder";
|
||||
// import { seedPaymentGateways } from "./seeders/payment-gateway.seeder";
|
||||
// import { seedPermissionsAndRoles } from "./seeders/role.seeder";
|
||||
import { seedBlogCommentReplies } from "./seeders/blog-comment-reply.seeder";
|
||||
import { seedBlogComments } from "./seeders/blog-comment.seeder";
|
||||
import { seedPermissionsAndRoles } from "./seeders/role.seeder";
|
||||
// import { seedBlogCommentReplies } from "./seeders/blog-comment-reply.seeder";
|
||||
// import { seedBlogComments } from "./seeders/blog-comment.seeder";
|
||||
|
||||
const logger = new Logger("Seeder");
|
||||
|
||||
@@ -15,14 +15,14 @@ export const runSeeder = async () => {
|
||||
await connectionSource.initialize();
|
||||
logger.log("start seeding database");
|
||||
//
|
||||
// await seedPermissionsAndRoles(connectionSource, logger);
|
||||
await seedPermissionsAndRoles(connectionSource, logger);
|
||||
// await seedAdmin(connectionSource, logger);
|
||||
// await seedNotifSettings(connectionSource, logger);
|
||||
// await seedPaymentGateways(connectionSource, logger);
|
||||
// await seedCityAndProvince(connectionSource, logger);
|
||||
|
||||
await seedBlogComments(connectionSource, logger);
|
||||
await seedBlogCommentReplies(connectionSource, logger);
|
||||
// await seedBlogComments(connectionSource, logger);
|
||||
// await seedBlogCommentReplies(connectionSource, logger);
|
||||
|
||||
logger.log("seeding completed");
|
||||
process.exit(0);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Logger } from "@nestjs/common";
|
||||
import { DataSource } from "typeorm";
|
||||
|
||||
import { Permission } from "../../src/modules/users/entities/permission.entity";
|
||||
import { Role } from "../../src/modules/users/entities/role.entity";
|
||||
// import { Permission } from "../../src/modules/users/entities/permission.entity";
|
||||
// import { Role } from "../../src/modules/users/entities/role.entity";
|
||||
import { PermissionEnum } from "../../src/modules/users/enums/permission.enum";
|
||||
import { RoleEnum } from "../../src/modules/users/enums/role.enum";
|
||||
|
||||
@@ -23,8 +23,8 @@ const rolesWithPermissions: { name: RoleEnum; permissions: PermissionEnum[] }[]
|
||||
|
||||
export const seedPermissionsAndRoles = async (dataSource: DataSource, logger: Logger) => {
|
||||
try {
|
||||
const permissionRepo = dataSource.getRepository(Permission);
|
||||
const roleRepo = dataSource.getRepository(Role);
|
||||
const permissionRepo = dataSource.getRepository('Permission');
|
||||
const roleRepo = dataSource.getRepository('Role');
|
||||
|
||||
// Seed Permissions
|
||||
logger.log("Seeding Permissions...");
|
||||
|
||||
@@ -917,5 +917,14 @@ export const enum AccessLogMessage {
|
||||
}
|
||||
|
||||
export const enum WorkSpaceMessage {
|
||||
WORKSPACE_EXISTS = "فضای کار با این اسم وجود دارد!"
|
||||
WORKSPACE_EXISTS = "فضای کار با این اسم وجود دارد!",
|
||||
WORKSPACE_NOT_FOUND = "فضای کار مورد نظر شما وجود ندارد!",
|
||||
USERS_DONT_BELONG_TO_THIS_WORKSPACE = "کاربران تعیین شده برای این فضای کاری نیستند!",
|
||||
WORKSPACE_SAME_NAME_EXISTS = "فضای کاری با این اسم از قبل وجود دارد!"
|
||||
}
|
||||
|
||||
export const enum ProjectMessage {
|
||||
PROJECT_EXISTS = "پروژه مورد نظر شما از قبل وجود دارد!",
|
||||
PROJECT_NOT_FOUND = "پروژه مورد نظر شما وجود ندارد!",
|
||||
PROJECT_CONTAINS_TASK_PHASES = "پروژه شامل فاز تسک است. لطفا ابتدا فاز تسک های این پروژه را حذف کنید."
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
import { IPageFormat } from "../interfaces/IPagination";
|
||||
|
||||
export function buildPageFormat(
|
||||
page: number,
|
||||
limit: number,
|
||||
totalItems: number,
|
||||
baseUrl: string,
|
||||
): IPageFormat {
|
||||
const totalPages = Math.ceil(totalItems / limit);
|
||||
|
||||
const prevPage =
|
||||
page > 1
|
||||
? `${baseUrl}?page=${page - 1}&limit=${limit}`
|
||||
: false;
|
||||
|
||||
const nextPage =
|
||||
page < totalPages
|
||||
? `${baseUrl}?page=${page + 1}&limit=${limit}`
|
||||
: false;
|
||||
|
||||
return {
|
||||
page,
|
||||
limit,
|
||||
totalItems,
|
||||
totalPages,
|
||||
prevPage,
|
||||
nextPage,
|
||||
};
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
import { IPageFormat } from "./IPagination";
|
||||
|
||||
export interface PaginatedResult<T> {
|
||||
data: T[];
|
||||
meta: IPageFormat;
|
||||
}
|
||||
@@ -1,42 +1,40 @@
|
||||
import { Controller, Get, Post, Patch, Delete, Param, Body, Query, Headers } from "@nestjs/common";
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery } from "@nestjs/swagger";
|
||||
import { Controller, Get, Post, Patch, Delete, Param, Body, Query } from "@nestjs/common";
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam } from "@nestjs/swagger";
|
||||
import { ProjectService } from "../providers/project.service";
|
||||
import { CreateProjectDto } from "../dto/project/create-project.dto";
|
||||
import { UpdateProjectDto } from "../dto/project/update-project.dto";
|
||||
import { PaginationDto } from "../../../common/DTO/pagination.dto";
|
||||
import { TMProject } from "../entities/project.entity";
|
||||
import { AdminRoute } from "../../../common/decorators/admin.decorator";
|
||||
import { PermissionsDec } from "../../../common/decorators/permission.decorator";
|
||||
import { PermissionEnum } from "../../users/enums/permission.enum";
|
||||
|
||||
@AdminRoute()
|
||||
@ApiTags("Task Manager - Projects")
|
||||
@Controller("task-manager/projects")
|
||||
export class ProjectController {
|
||||
constructor(private readonly projectService: ProjectService) {}
|
||||
|
||||
@Get()
|
||||
@PermissionsDec(PermissionEnum.PROJECT)
|
||||
@ApiOperation({ summary: "Get all projects, optionally filtered by workspace" })
|
||||
@ApiQuery({ name: "workspaceId", required: false, description: "Filter projects by workspace ID" })
|
||||
@ApiResponse({ status: 200, description: "Paginated list of projects" })
|
||||
findAll(
|
||||
@Query() pagination: PaginationDto,
|
||||
@Query("workspaceId") workspaceId: string,
|
||||
@Headers("host") host: string,
|
||||
@Headers("x-forwarded-proto") proto?: string,
|
||||
) {
|
||||
const protocol = proto ?? "http";
|
||||
const baseUrl = `${protocol}://${host}/task-manager/projects`;
|
||||
if (workspaceId) return this.projectService.findByWorkspace(workspaceId, pagination, baseUrl);
|
||||
return this.projectService.findAll(pagination, baseUrl);
|
||||
findAll(@Query() pagination: PaginationDto): Promise<{ projects: TMProject[]; count: number; paginate: true }> {
|
||||
return this.projectService.findAll(pagination);
|
||||
}
|
||||
|
||||
@Get(":id")
|
||||
@PermissionsDec(PermissionEnum.PROJECT)
|
||||
@ApiOperation({ summary: "Get a project by ID" })
|
||||
@ApiParam({ name: "id", description: "Project ID" })
|
||||
@ApiResponse({ status: 200, description: "Project found", type: TMProject })
|
||||
@ApiResponse({ status: 404, description: "Project not found" })
|
||||
findOne(@Param("id") id: string): Promise<TMProject> {
|
||||
return this.projectService.findOne(id);
|
||||
return this.projectService.findOneOrFail(id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@PermissionsDec(PermissionEnum.PROJECT)
|
||||
@ApiOperation({ summary: "Create a new project" })
|
||||
@ApiResponse({ status: 201, description: "Project created", type: TMProject })
|
||||
@ApiResponse({ status: 400, description: "One or more users are not members of the workspace" })
|
||||
@@ -46,6 +44,7 @@ export class ProjectController {
|
||||
}
|
||||
|
||||
@Patch(":id")
|
||||
@PermissionsDec(PermissionEnum.PROJECT)
|
||||
@ApiOperation({ summary: "Update a project" })
|
||||
@ApiParam({ name: "id", description: "Project ID" })
|
||||
@ApiResponse({ status: 200, description: "Project updated", type: TMProject })
|
||||
@@ -56,6 +55,7 @@ export class ProjectController {
|
||||
}
|
||||
|
||||
@Delete(":id")
|
||||
@PermissionsDec(PermissionEnum.PROJECT)
|
||||
@ApiOperation({ summary: "Delete a project" })
|
||||
@ApiParam({ name: "id", description: "Project ID" })
|
||||
@ApiResponse({ status: 200, description: "Project deleted", type: TMProject })
|
||||
@@ -63,4 +63,17 @@ export class ProjectController {
|
||||
remove(@Param("id") id: string): Promise<TMProject> {
|
||||
return this.projectService.remove(id);
|
||||
}
|
||||
|
||||
@Get("/workspace/:wsId")
|
||||
@PermissionsDec(PermissionEnum.PROJECT)
|
||||
@ApiOperation({ summary: "Get projects of a specific workspace" })
|
||||
@ApiParam({ name: "wsId", description: "Workspace ID" })
|
||||
@ApiResponse({ status: 200, description: "received projects successfully!" })
|
||||
@ApiResponse({ status: 404, description: "WorkSpace not found" })
|
||||
findByWorkspace(
|
||||
@Param("wsId") wsId: string,
|
||||
@Query() pagination: PaginationDto,
|
||||
): Promise<{ projects: TMProject[]; count: number; paginate: true }> {
|
||||
return this.projectService.findByWorkspace(wsId, pagination);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,66 +1,83 @@
|
||||
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { In, Repository } from 'typeorm';
|
||||
import { ProjectRepository } from '../repositories/project.repository';
|
||||
import { WorkspaceRepository } from '../repositories/workspace.repository';
|
||||
import { TMProject } from '../entities/project.entity';
|
||||
import { CreateProjectDto } from '../dto/project/create-project.dto';
|
||||
import { UpdateProjectDto } from '../dto/project/update-project.dto';
|
||||
import { PaginationDto } from '../../../common/DTO/pagination.dto';
|
||||
import { PaginatedResult } from '../../../common/interfaces/paginated-result.interface';
|
||||
import { buildPageFormat } from '../../../common/helpers/pagination.helper';
|
||||
import { User } from '../../users/entities/user.entity';
|
||||
import { BadRequestException, Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { In, Repository } from "typeorm";
|
||||
import { ProjectRepository } from "../repositories/project.repository";
|
||||
import { TMProject } from "../entities/project.entity";
|
||||
import { CreateProjectDto } from "../dto/project/create-project.dto";
|
||||
import { UpdateProjectDto } from "../dto/project/update-project.dto";
|
||||
import { PaginationDto } from "../../../common/DTO/pagination.dto";
|
||||
import { User } from "../../users/entities/user.entity";
|
||||
import { ProjectMessage, WorkSpaceMessage } from "../../../common/enums/message.enum";
|
||||
import { WorkspaceService } from "./workspace.service";
|
||||
|
||||
@Injectable()
|
||||
export class ProjectService {
|
||||
constructor(
|
||||
private readonly projectRepository: ProjectRepository,
|
||||
private readonly workspaceRepository: WorkspaceRepository,
|
||||
private readonly workspaceService: WorkspaceService,
|
||||
@InjectRepository(User)
|
||||
private readonly userRepository: Repository<User>,
|
||||
) {}
|
||||
|
||||
async findAll(pagination: PaginationDto, baseUrl: string): Promise<PaginatedResult<TMProject>> {
|
||||
async findAll(pagination: PaginationDto): Promise<{ projects: TMProject[]; count: number; paginate: true }> {
|
||||
const page = pagination.page ?? 1;
|
||||
const limit = pagination.limit ?? 10;
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
const [data, totalItems] = await this.projectRepository.findAll(skip, limit);
|
||||
const [projects, count] = await this.projectRepository.findAndCount({
|
||||
skip: skip,
|
||||
take: limit,
|
||||
relations: {
|
||||
users: true,
|
||||
},
|
||||
select: {
|
||||
users: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
data,
|
||||
meta: buildPageFormat(page, limit, totalItems, baseUrl),
|
||||
};
|
||||
return { projects, count, paginate: true };
|
||||
}
|
||||
|
||||
async findByWorkspace(
|
||||
workspaceId: string,
|
||||
pagination: PaginationDto,
|
||||
baseUrl: string,
|
||||
): Promise<PaginatedResult<TMProject>> {
|
||||
async findByWorkspace(workspaceId: string, pagination: PaginationDto): Promise<{ projects: TMProject[]; count: number; paginate: true }> {
|
||||
await this.workspaceService.findOneOrFail(workspaceId);
|
||||
|
||||
const page = pagination.page ?? 1;
|
||||
const limit = pagination.limit ?? 10;
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
const [data, totalItems] = await this.projectRepository.findByWorkspace(workspaceId, skip, limit);
|
||||
const [projects, count] = await this.projectRepository.findAndCount({
|
||||
where: { workspaceId },
|
||||
relations: {
|
||||
users: true,
|
||||
},
|
||||
select: {
|
||||
users: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
},
|
||||
},
|
||||
skip,
|
||||
take: limit,
|
||||
});
|
||||
|
||||
return {
|
||||
data,
|
||||
meta: buildPageFormat(page, limit, totalItems, baseUrl),
|
||||
};
|
||||
return { projects, count, paginate: true };
|
||||
}
|
||||
|
||||
async findOne(id: string): Promise<TMProject> {
|
||||
const project = await this.projectRepository.findOneById(id);
|
||||
if (!project) throw new NotFoundException(`Project #${id} not found`);
|
||||
async findOneOrFail(id: string): Promise<TMProject> {
|
||||
const project = await this.projectRepository.findOne({ where: { id } });
|
||||
if (!project) throw new NotFoundException(ProjectMessage.PROJECT_NOT_FOUND);
|
||||
return project;
|
||||
}
|
||||
|
||||
async create(dto: CreateProjectDto): Promise<TMProject> {
|
||||
const { userIds, startDate, ...rest } = dto;
|
||||
|
||||
const workspace = await this.workspaceRepository.findOneById(dto.workspaceId);
|
||||
if (!workspace) throw new NotFoundException(`Workspace #${dto.workspaceId} not found`);
|
||||
const workspace = await this.workspaceService.findOneOrFail(dto.workspaceId);
|
||||
|
||||
const project = this.projectRepository.create({
|
||||
...rest,
|
||||
@@ -71,9 +88,7 @@ export class ProjectService {
|
||||
const workspaceUserIds = workspace.users.map((u) => u.id);
|
||||
const invalidUsers = userIds.filter((id) => !workspaceUserIds.includes(id));
|
||||
if (invalidUsers.length) {
|
||||
throw new BadRequestException(
|
||||
`Users [${invalidUsers.join(', ')}] are not members of this workspace`,
|
||||
);
|
||||
throw new BadRequestException(WorkSpaceMessage.USERS_DONT_BELONG_TO_THIS_WORKSPACE);
|
||||
}
|
||||
project.users = await this.userRepository.findBy({ id: In(userIds) });
|
||||
}
|
||||
@@ -82,7 +97,8 @@ export class ProjectService {
|
||||
}
|
||||
|
||||
async update(id: string, dto: UpdateProjectDto): Promise<TMProject> {
|
||||
const project = await this.findOne(id);
|
||||
const project = await this.findOneOrFail(id);
|
||||
|
||||
const { userIds, startDate, ...rest } = dto;
|
||||
|
||||
Object.assign(project, {
|
||||
@@ -93,15 +109,12 @@ export class ProjectService {
|
||||
if (userIds) {
|
||||
if (userIds.length) {
|
||||
const workspaceId = dto.workspaceId ?? project.workspaceId;
|
||||
const workspace = await this.workspaceRepository.findOneById(workspaceId);
|
||||
if (!workspace) throw new NotFoundException(`Workspace #${workspaceId} not found`);
|
||||
const workspace = await this.workspaceService.findOneOrFail(workspaceId);
|
||||
|
||||
const workspaceUserIds = workspace.users.map((u) => u.id);
|
||||
const invalidUsers = userIds.filter((uid) => !workspaceUserIds.includes(uid));
|
||||
if (invalidUsers.length) {
|
||||
throw new BadRequestException(
|
||||
`Users [${invalidUsers.join(', ')}] are not members of this workspace`,
|
||||
);
|
||||
throw new BadRequestException(WorkSpaceMessage.USERS_DONT_BELONG_TO_THIS_WORKSPACE);
|
||||
}
|
||||
project.users = await this.userRepository.findBy({ id: In(userIds) });
|
||||
} else {
|
||||
@@ -113,8 +126,27 @@ export class ProjectService {
|
||||
}
|
||||
|
||||
async remove(id: string): Promise<TMProject> {
|
||||
const project = await this.findOne(id);
|
||||
const project = await this.projectRepository.findOne({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
relations: {
|
||||
taskPhases: true,
|
||||
},
|
||||
select: {
|
||||
taskPhases: {
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if(!project) throw new NotFoundException(ProjectMessage.PROJECT_NOT_FOUND);
|
||||
|
||||
const taskPhases = project.taskPhases;
|
||||
if (taskPhases !== undefined && taskPhases.length) {
|
||||
throw new BadRequestException(ProjectMessage.PROJECT_CONTAINS_TASK_PHASES);
|
||||
}
|
||||
await this.projectRepository.delete(id);
|
||||
return project;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { BadRequestException, Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { In, Repository } from "typeorm";
|
||||
import { In, Not, Repository } from "typeorm";
|
||||
import { WorkspaceRepository } from "../repositories/workspace.repository";
|
||||
import { TMWorkspace } from "../entities/workspace.entity";
|
||||
import { CreateWorkspaceDto } from "../dto/workspace/create-workspace.dto";
|
||||
@@ -17,22 +17,20 @@ export class WorkspaceService {
|
||||
) {}
|
||||
|
||||
findAll(): Promise<TMWorkspace[]> {
|
||||
return this.workspaceRepository.find({
|
||||
relations: ["projects", "users"],
|
||||
});
|
||||
return this.workspaceRepository.find({});
|
||||
}
|
||||
|
||||
async findOneOrFail(id: string): Promise<TMWorkspace> {
|
||||
const workspace = await this.workspaceRepository.findOne({ where: { id } });
|
||||
if (!workspace) throw new NotFoundException(`Workspace #${id} not found`);
|
||||
const workspace = await this.workspaceRepository.findOneWorkSpace(id);
|
||||
if (!workspace) throw new NotFoundException(WorkSpaceMessage.WORKSPACE_NOT_FOUND);
|
||||
return workspace;
|
||||
}
|
||||
|
||||
async create(dto: CreateWorkspaceDto): Promise<TMWorkspace> {
|
||||
const { userIds, ...rest } = dto;
|
||||
|
||||
const existingWorkspace = await this.workspaceRepository.findOne({where: {name: rest.name}});
|
||||
if(existingWorkspace) {
|
||||
const existingWorkspace = await this.workspaceRepository.findOne({ where: { name: rest.name } });
|
||||
if (existingWorkspace) {
|
||||
throw new BadRequestException(WorkSpaceMessage.WORKSPACE_EXISTS);
|
||||
}
|
||||
|
||||
@@ -49,6 +47,11 @@ export class WorkspaceService {
|
||||
const workspace = await this.findOneOrFail(id);
|
||||
const { userIds, ...rest } = dto;
|
||||
|
||||
if (rest.name) {
|
||||
const existingWorkSpaceWithTheSameName = await this.workspaceRepository.findOne({ where: { name: rest.name, id: Not(id) } });
|
||||
if (existingWorkSpaceWithTheSameName) throw new BadRequestException(WorkSpaceMessage.WORKSPACE_SAME_NAME_EXISTS);
|
||||
}
|
||||
|
||||
Object.assign(workspace, rest);
|
||||
|
||||
if (userIds) {
|
||||
|
||||
@@ -1,52 +1,13 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { TMProject } from '../entities/project.entity';
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
import { TMProject } from "../entities/project.entity";
|
||||
|
||||
@Injectable()
|
||||
export class ProjectRepository {
|
||||
export class ProjectRepository extends Repository<TMProject> {
|
||||
constructor(
|
||||
@InjectRepository(TMProject)
|
||||
private readonly repository: Repository<TMProject>,
|
||||
) {}
|
||||
|
||||
findAll(skip: number, take: number) {
|
||||
return this.repository.findAndCount({
|
||||
relations: ['workspace', 'taskPhases', 'users'],
|
||||
skip,
|
||||
take,
|
||||
});
|
||||
@InjectRepository(TMProject) projectRepository: Repository<TMProject>,
|
||||
) {
|
||||
super(projectRepository.target, projectRepository.manager, projectRepository.queryRunner);
|
||||
}
|
||||
|
||||
findByWorkspace(workspaceId: string, skip: number, take: number) {
|
||||
return this.repository.findAndCount({
|
||||
where: { workspaceId },
|
||||
relations: ['taskPhases', 'users'],
|
||||
skip,
|
||||
take,
|
||||
});
|
||||
}
|
||||
|
||||
findOneById(id: string) {
|
||||
return this.repository.findOne({
|
||||
where: { id },
|
||||
relations: ['workspace', 'taskPhases', 'users'],
|
||||
});
|
||||
}
|
||||
|
||||
create(data: Partial<TMProject>) {
|
||||
return this.repository.create(data);
|
||||
}
|
||||
|
||||
save(project: TMProject) {
|
||||
return this.repository.save(project);
|
||||
}
|
||||
|
||||
update(id: string, data: Partial<TMProject>) {
|
||||
return this.repository.update(id, data);
|
||||
}
|
||||
|
||||
delete(id: string) {
|
||||
return this.repository.delete(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
import { TMWorkspace } from "../entities/workspace.entity";
|
||||
import { Repository } from 'typeorm';
|
||||
import { TMWorkspace } from '../entities/workspace.entity';
|
||||
|
||||
@Injectable()
|
||||
export class WorkspaceRepository extends Repository<TMWorkspace> {
|
||||
@@ -9,10 +9,22 @@ export class WorkspaceRepository extends Repository<TMWorkspace> {
|
||||
super(workspaceRepository.target, workspaceRepository.manager, workspaceRepository.queryRunner);
|
||||
}
|
||||
|
||||
async findOneWorkSpace(workspaceId: string): Promise<TMWorkspace | null> {
|
||||
return this.createQueryBuilder("workspace")
|
||||
.leftJoinAndSelect('workspace.users', 'user')
|
||||
.select([
|
||||
'workspace',
|
||||
'user.id',
|
||||
'user.firstName',
|
||||
'user.lastName'
|
||||
]).where('workspace.id = :workspaceId', {workspaceId})
|
||||
.getOne();
|
||||
}
|
||||
|
||||
async findByUser(userId: string): Promise<TMWorkspace[]> {
|
||||
return this.createQueryBuilder("workspace")
|
||||
.innerJoin("workspace.users", "users")
|
||||
.where("user.id = :userId", { userId })
|
||||
.where("users.id = :userId", { userId })
|
||||
.getMany();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,5 +25,6 @@ export enum PermissionEnum {
|
||||
DPAGE = "dpage",
|
||||
DMAIL = 'dmail',
|
||||
RESELLER="reseller",
|
||||
WORKSPACE="workspace"
|
||||
WORKSPACE="workspace",
|
||||
PROJECT="project"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user