@@ -16,7 +16,7 @@ import {
1616} from '@common/frontend_shared/enum' ;
1717import {
1818 projectEntityToDtoWithMissionCount ,
19- projectEntityToDtoWithMissions ,
19+ projectEntityToDtoWithRequiredTags ,
2020} from '../serialization' ;
2121import TagType from '@common/entities/tagType/tag-type.entity' ;
2222import ProjectAccess from '@common/entities/auth/project-access.entity' ;
@@ -27,9 +27,10 @@ import { DefaultRights } from '@common/api/types/access-control/default-rights';
2727import { ResentProjectDto } from '@common/api/types/project/recent-projects.dto' ;
2828import { DefaultRightDto } from '@common/api/types/access-control/default-right.dto' ;
2929import { ProjectsDto } from '@common/api/types/project/projects.dto' ;
30- import { ProjectWithMissionsDto } from '@common/api/types/project/project-with-missions.dto' ;
3130import { AuthHeader } from '../endpoints/auth/parameter-decorator' ;
3231import { SortOrder } from '@common/api/types/pagination' ;
32+ import { ProjectWithRequiredTags } from '@common/api/types/project/project-with-required-tags' ;
33+ import { ProjectDto } from '@common/api/types/project/base-project.dto' ;
3334
3435const FIND_MANY_SORT_KEYS = {
3536 projectName : 'project.name' ,
@@ -188,23 +189,29 @@ export class ProjectService {
188189 } ;
189190 }
190191
191- async findOne ( uuid : string ) : Promise < ProjectWithMissionsDto > {
192- const mission = await this . projectRepository
192+ async findOne ( uuid : string ) : Promise < ProjectWithRequiredTags > {
193+ const missionPromise = this . projectRepository
193194 . createQueryBuilder ( 'project' )
194195 . where ( 'project.uuid = :uuid' , { uuid } )
195196 . leftJoinAndSelect ( 'project.creator' , 'creator' )
196- . leftJoinAndSelect ( 'project.missions' , 'missions' )
197- // TODO: remove the following two joins, there are never used in the frontend...
198- . leftJoinAndSelect ( 'missions.creator' , 'mission_creator' )
199- . leftJoinAndSelect ( 'missions.project' , 'mission_project' )
200197 . leftJoinAndSelect ( 'project.requiredTags' , 'requiredTags' )
201198 . leftJoinAndSelect ( 'project.project_accesses' , 'project_accesses' )
202199 . leftJoinAndSelect ( 'project_accesses.accessGroup' , 'accessGroup' )
203200 . leftJoinAndSelect ( 'accessGroup.memberships' , 'memberships' )
204201 . leftJoinAndSelect ( 'memberships.user' , 'user' )
205202 . getOneOrFail ( ) ;
206203
207- return projectEntityToDtoWithMissions ( mission ) ;
204+ const missionCountPromise = this . projectRepository
205+ . createQueryBuilder ( 'project' )
206+ . leftJoin ( 'project.missions' , 'missions' )
207+ . where ( 'project.uuid = :uuid' , { uuid } )
208+ . getCount ( ) ;
209+
210+ const [ mission , missionCount ] = await Promise . all ( [
211+ missionPromise ,
212+ missionCountPromise ,
213+ ] ) ;
214+ return projectEntityToDtoWithRequiredTags ( mission , missionCount ) ;
208215 }
209216
210217 async getRecentProjects (
@@ -339,7 +346,7 @@ export class ProjectService {
339346 async create (
340347 project : CreateProject ,
341348 auth : AuthHeader ,
342- ) : Promise < ProjectWithMissionsDto > {
349+ ) : Promise < ProjectDto > {
343350 const exists = await this . projectRepository . exists ( {
344351 where : { name : ILike ( project . name ) } ,
345352 } ) ;
@@ -424,13 +431,10 @@ export class ProjectService {
424431 ) ;
425432 return ( await this . projectRepository . findOneOrFail ( {
426433 where : { uuid : transactedProject . uuid } ,
427- } ) ) as unknown as ProjectWithMissionsDto ;
434+ } ) ) as unknown as ProjectDto ;
428435 }
429436
430- async update (
431- uuid : string ,
432- project : CreateProject ,
433- ) : Promise < ProjectWithMissionsDto > {
437+ async update ( uuid : string , project : CreateProject ) : Promise < ProjectDto > {
434438 const exists = await this . projectRepository . exists ( {
435439 where : { name : ILike ( project . name ) , uuid : Not ( uuid ) } ,
436440 } ) ;
@@ -449,7 +453,7 @@ export class ProjectService {
449453 } ) ;
450454 return ( await this . projectRepository . findOneOrFail ( {
451455 where : { uuid } ,
452- } ) ) as unknown as ProjectWithMissionsDto ;
456+ } ) ) as unknown as ProjectDto ;
453457 }
454458
455459 async addTagType ( uuid : string , tagTypeUUID : string ) : Promise < void > {
0 commit comments