@ -40,17 +40,21 @@ export class ParticipantAPI extends DataSource {
. loadOne ( ) ;
}
async participantByCargoBikeId ( id :number ) {
return await this . connection . getRepository ( Engagement )
. createQueryBuilder ( 'e' )
. relation ( Engagement , 'participantId' )
. of ( ( await this . connection . getRepository ( Engagement ) // TODO do this with a sub query
async participantsByCargoBikeId ( id :number ) {
return await this . connection . getRepository ( Engagement ) // TODO do this with a sub query
. createQueryBuilder ( 'e' )
. select ( )
. where ( '"dateRange" && daterange(CURRENT_DATE,CURRENT_DATE,\'[]\')' )
. andWhere ( '"cargoBikeId" = :id' , { id : id } )
. getOne ( ) ) ? . id
) . loadOne ( ) ;
. getMany ( )
. then ( async ( value : Engagement [ ] ) = > {
return value ? . map ( async ( engagement : Engagement ) = > {
return await this . connection . getRepository ( Engagement )
. createQueryBuilder ( 'e' )
. relation ( Engagement , 'participantId' )
. of ( engagement . id ) . loadOne ( ) ;
} ) ;
} ) ;
}
async engagementByParticipantId ( id : number ) {
@ -74,6 +78,16 @@ export class ParticipantAPI extends DataSource {
. getMany ( ) ;
}
async currentEngagementByCargoBikeId ( id : number ) {
return await this . connection . getRepository ( Engagement )
. createQueryBuilder ( 'engagement' )
. select ( )
. where ( 'engagement."cargoBikeId" = :id' , { id : id } )
. where ( '"dateRange" && daterange(CURRENT_DATE,CURRENT_DATE,\'[]\')' )
. orderBy ( 'engagement."dateRange"' , 'DESC' )
. getMany ( ) ;
}
async engagements ( offset : number , limit : number ) {
return await this . connection . getRepository ( Engagement )
. createQueryBuilder ( 'e' )