src: bug fix

pull/14/head
leonnicolas 4 years ago
parent 3d32d6bcff
commit 0098d9b3bf
No known key found for this signature in database
GPG Key ID: 088D0743E2B65C07

@ -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')

@ -76,6 +76,13 @@ export default {
}
},
CargoBike: {
currentEngagements (parent: any, __: any, { dataSources, req }: { dataSources: any, req: any }) {
if (req.permissions.includes(Permission.ReadEngagement)) {
return dataSources.participantAPI.currentEngagementByCargoBikeId(parent.id);
} else {
return new GraphQLError('Insufficient Permissions');
}
},
engagement (parent: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) {
if (req.permissions.includes(Permission.ReadEngagement)) {
return dataSources.participantAPI.engagementByCargoBikeId(offset, limit, parent.id);
@ -83,9 +90,9 @@ export default {
return new GraphQLError('Insufficient Permissions');
}
},
coordinator (parent: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) { // TODO should be done with engagements
participants (parent: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) { // TODO should be done with engagements
if (req.permissions.includes(Permission.ReadParticipant)) {
return dataSources.participantAPI.participantByCargoBikeId(parent.id);
return dataSources.participantAPI.participantsByCargoBikeId(parent.id);
} else {
return new GraphQLError('Insufficient Permissions');
}

@ -39,10 +39,12 @@ type CargoBike {
stickerBikeNameState: StickerBikeNameState
note: String
provider: Provider
coordinator: Participant
"all participants currently engaged with the cargoBike"
participants: [Participant]
insuranceData: InsuranceData!
lendingStation: LendingStation
taxes: Taxes
currentEngagements: [Engagement]
engagement(offset: Int!, limit: Int!): [Engagement]
timeFrames: [TimeFrame]
isLocked: Boolean!
@ -129,7 +131,7 @@ input CargoBikeUpdateInput {
type InsuranceData {
"""
Eventuelly, this field will become an enum or a separate data table and user can choose from a pool of insurance companies.
Eventually, this field will become an enum or a separate data table and user can choose from a pool of insurance companies.
"""
name: String!
benefactor: String!

Loading…
Cancel
Save