refactor: order the taskPhases by order attr in projectDetail API
This commit is contained in:
@@ -5,21 +5,19 @@ import { TMProject } from "../entities/project.entity";
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ProjectRepository extends Repository<TMProject> {
|
export class ProjectRepository extends Repository<TMProject> {
|
||||||
constructor(
|
constructor(@InjectRepository(TMProject) projectRepository: Repository<TMProject>) {
|
||||||
@InjectRepository(TMProject) projectRepository: Repository<TMProject>,
|
|
||||||
) {
|
|
||||||
super(projectRepository.target, projectRepository.manager, projectRepository.queryRunner);
|
super(projectRepository.target, projectRepository.manager, projectRepository.queryRunner);
|
||||||
}
|
}
|
||||||
|
|
||||||
async findUserProjects(userId: string, wsId: string, skip?: number, take?: number): Promise<[TMProject[], number]> {
|
async findUserProjects(userId: string, wsId: string, skip?: number, take?: number): Promise<[TMProject[], number]> {
|
||||||
return this.createQueryBuilder('project')
|
return this.createQueryBuilder("project")
|
||||||
.innerJoin('project.workspace', 'workspace')
|
.innerJoin("project.workspace", "workspace")
|
||||||
.innerJoin('project.users', 'user')
|
.innerJoin("project.users", "user")
|
||||||
.where('workspace.id = :wsId', {wsId})
|
.where("workspace.id = :wsId", { wsId })
|
||||||
.andWhere('user.id = :userId', {userId})
|
.andWhere("user.id = :userId", { userId })
|
||||||
.skip(skip ?? 0)
|
.skip(skip ?? 0)
|
||||||
.take(take ?? 10)
|
.take(take ?? 10)
|
||||||
.getManyAndCount();
|
.getManyAndCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
async getProjectDetail(projectId: string): Promise<TMProject | null> {
|
async getProjectDetail(projectId: string): Promise<TMProject | null> {
|
||||||
@@ -27,31 +25,23 @@ export class ProjectRepository extends Repository<TMProject> {
|
|||||||
.leftJoinAndSelect("project.taskPhases", "taskPhase")
|
.leftJoinAndSelect("project.taskPhases", "taskPhase")
|
||||||
.leftJoinAndSelect("taskPhase.tasks", "task")
|
.leftJoinAndSelect("taskPhase.tasks", "task")
|
||||||
.leftJoinAndSelect("task.remarks", "remark")
|
.leftJoinAndSelect("task.remarks", "remark")
|
||||||
|
|
||||||
.loadRelationCountAndMap(
|
.loadRelationCountAndMap("task.attachmentCount", "task.attachments")
|
||||||
"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 })
|
.where("project.id = :projectId", { projectId })
|
||||||
|
|
||||||
.select([
|
.select([
|
||||||
"project.id",
|
"project.id",
|
||||||
"project.name",
|
"project.name",
|
||||||
"taskPhase.id",
|
"taskPhase.id",
|
||||||
"taskPhase.name",
|
"taskPhase.name",
|
||||||
|
"taskPhase.order",
|
||||||
"task.id",
|
"task.id",
|
||||||
"task.title",
|
"task.title",
|
||||||
"task.startDate",
|
"task.startDate",
|
||||||
@@ -59,7 +49,9 @@ export class ProjectRepository extends Repository<TMProject> {
|
|||||||
"remark.title",
|
"remark.title",
|
||||||
"remark.color",
|
"remark.color",
|
||||||
])
|
])
|
||||||
|
|
||||||
|
.orderBy("taskPhase.order", "ASC")
|
||||||
|
|
||||||
.getOne();
|
.getOne();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user