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

@ -76,6 +76,13 @@ export default {
} }
}, },
CargoBike: { 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 }) { engagement (parent: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) {
if (req.permissions.includes(Permission.ReadEngagement)) { if (req.permissions.includes(Permission.ReadEngagement)) {
return dataSources.participantAPI.engagementByCargoBikeId(offset, limit, parent.id); return dataSources.participantAPI.engagementByCargoBikeId(offset, limit, parent.id);
@ -83,9 +90,9 @@ export default {
return new GraphQLError('Insufficient Permissions'); 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)) { if (req.permissions.includes(Permission.ReadParticipant)) {
return dataSources.participantAPI.participantByCargoBikeId(parent.id); return dataSources.participantAPI.participantsByCargoBikeId(parent.id);
} else { } else {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }

@ -39,10 +39,12 @@ type CargoBike {
stickerBikeNameState: StickerBikeNameState stickerBikeNameState: StickerBikeNameState
note: String note: String
provider: Provider provider: Provider
coordinator: Participant "all participants currently engaged with the cargoBike"
participants: [Participant]
insuranceData: InsuranceData! insuranceData: InsuranceData!
lendingStation: LendingStation lendingStation: LendingStation
taxes: Taxes taxes: Taxes
currentEngagements: [Engagement]
engagement(offset: Int!, limit: Int!): [Engagement] engagement(offset: Int!, limit: Int!): [Engagement]
timeFrames: [TimeFrame] timeFrames: [TimeFrame]
isLocked: Boolean! isLocked: Boolean!
@ -129,7 +131,7 @@ input CargoBikeUpdateInput {
type InsuranceData { 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! name: String!
benefactor: String! benefactor: String!

Loading…
Cancel
Save