refactor: order the taskPhases by order attr in projectDetail API

This commit is contained in:
2026-07-12 14:52:24 +03:30
parent 1440b62373
commit 8e23a06793
@@ -5,21 +5,19 @@ import { TMProject } from "../entities/project.entity";
@Injectable()
export class ProjectRepository extends Repository<TMProject> {
constructor(
@InjectRepository(TMProject) projectRepository: Repository<TMProject>,
) {
constructor(@InjectRepository(TMProject) projectRepository: Repository<TMProject>) {
super(projectRepository.target, projectRepository.manager, projectRepository.queryRunner);
}
async findUserProjects(userId: string, wsId: string, skip?: number, take?: number): Promise<[TMProject[], number]> {
return this.createQueryBuilder('project')
.innerJoin('project.workspace', 'workspace')
.innerJoin('project.users', 'user')
.where('workspace.id = :wsId', {wsId})
.andWhere('user.id = :userId', {userId})
.skip(skip ?? 0)
.take(take ?? 10)
.getManyAndCount();
return this.createQueryBuilder("project")
.innerJoin("project.workspace", "workspace")
.innerJoin("project.users", "user")
.where("workspace.id = :wsId", { wsId })
.andWhere("user.id = :userId", { userId })
.skip(skip ?? 0)
.take(take ?? 10)
.getManyAndCount();
}
async getProjectDetail(projectId: string): Promise<TMProject | null> {
@@ -27,31 +25,23 @@ export class ProjectRepository extends Repository<TMProject> {
.leftJoinAndSelect("project.taskPhases", "taskPhase")
.leftJoinAndSelect("taskPhase.tasks", "task")
.leftJoinAndSelect("task.remarks", "remark")
.loadRelationCountAndMap(
"task.attachmentCount",
"task.attachments",
.loadRelationCountAndMap("task.attachmentCount", "task.attachments")
.loadRelationCountAndMap("task.checkListItemCount", "task.checkListItems")
.loadRelationCountAndMap("task.completedCheckListItemCount", "task.checkListItems", "completedCheckListItems", (qb) =>
qb.where("completedCheckListItems.isDone = :isDone", { isDone: true }),
)
.loadRelationCountAndMap(
"task.checkListItemCount",
"task.checkListItems",
)
.loadRelationCountAndMap(
"task.completedCheckListItemCount",
"task.checkListItems",
"completedCheckListItems",
(qb) => qb.where("completedCheckListItems.isDone = :isDone", { isDone: true }),
)
.where("project.id = :projectId", { projectId })
.select([
"project.id",
"project.name",
"taskPhase.id",
"taskPhase.name",
"taskPhase.order",
"task.id",
"task.title",
"task.startDate",
@@ -59,7 +49,9 @@ export class ProjectRepository extends Repository<TMProject> {
"remark.title",
"remark.color",
])
.orderBy("taskPhase.order", "ASC")
.getOne();
}
}