feat: added project detail API

This commit is contained in:
2026-07-06 14:05:38 +03:30
parent 5715cbe9b1
commit 5964a9b20d
4 changed files with 51 additions and 2 deletions
@@ -1,4 +1,4 @@
import { BadRequestException, Injectable, NotFoundException } from "@nestjs/common";
import { BadRequestException, ForbiddenException, Injectable, NotFoundException } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { In, Repository } from "typeorm";
import { ProjectRepository } from "../repositories/project.repository";
@@ -124,7 +124,11 @@ export class ProjectService {
return project;
}
async findUserProjects(userId: string, wsId: string, pagination: PaginationDto): Promise<{ projects: TMProject[]; count: number; paginate: true }> {
async findUserProjects(
userId: string,
wsId: string,
pagination: PaginationDto,
): Promise<{ projects: TMProject[]; count: number; paginate: true }> {
const page = pagination.page ?? 1;
const limit = pagination.limit ?? 10;
const skip = (page - 1) * limit;
@@ -133,4 +137,21 @@ export class ProjectService {
return { projects, count, paginate: true };
}
async getProjectDetail(projectId: string, userId: string): Promise<TMProject | null> {
const project = await this.projectRepository.findOne({
where: { id: projectId },
relations: {
users: true,
},
});
if (!project) throw new NotFoundException(ProjectMessage.PROJECT_NOT_FOUND);
const isUserMember = project.users.some(user => user.id === userId);
if(!isUserMember) throw new ForbiddenException(ProjectMessage.NOT_MEMBER_OF_PROJECT);
const projectDetail = await this.projectRepository.getProjectDetail(projectId);
return projectDetail;
}
}