lockBike returns Bike or error, update bike takes keepLock

pull/14/head
leonnicolas 4 years ago
parent cbec1866c4
commit 847e78768f
No known key found for this signature in database
GPG Key ID: 088D0743E2B65C07

@ -48,7 +48,11 @@ export class CargoBikeAPI extends DataSource {
}
async lockCargoBike (id: number, req: any, dataSources: any) {
return this.lockEntity(CargoBike, 'cargobike', id, req, dataSources);
if (await this.lockEntity(CargoBike, 'cargobike', id, req, dataSources)) {
return this.findCargoBikeById(id);
} else {
return new GraphQLError('CargoBike is locked by other user');
}
}
async unlockCargoBike (id: number, req: any, dataSources: any) {
@ -162,6 +166,8 @@ export class CargoBikeAPI extends DataSource {
if (!await this.lockCargoBike(cargoBike.id, req, dataSources)) {
return new GraphQLError('Bike locked by other user');
}
const keepLock = cargoBike?.keepLock;
delete cargoBike.keepLock;
const bike = await this.connection.manager.createQueryBuilder()
.select('cargoBike')
.from(CargoBike, 'cargoBike')
@ -183,6 +189,7 @@ export class CargoBikeAPI extends DataSource {
.of(cargoBike.id)
.set(lendingStationId);
}
!keepLock && this.unlockCargoBike(cargoBike.id, req, dataSources);
return await this.findCargoBikeById(bike.id);
} else {
return new GraphQLError('ID not in database');

@ -54,6 +54,9 @@ export default {
},
isLocked (parent: any, __: any, { dataSources, req }: { dataSources: any, req: any }) {
return dataSources.cargoBikeAPI.isLocked(parent.id, req, dataSources);
},
lockedBy (): any {
return null;
}
},
Equipment: {

@ -112,6 +112,8 @@ input CargoBikeUpdateInput {
provider: String
insuranceData: InsuranceDataUpdateInput
taxes: TaxesUpdateInput
"will keep Bike locked if set to true, default = false"
keepLock: Boolean
}
type InsuranceData {
@ -711,8 +713,8 @@ type Query {
type Mutation {
"creates new cargoBike and returns cargobike with new ID"
createCargoBike(cargoBike: CargoBikeCreateInput!): CargoBike!
"lock cargoBike returns true if bike is not locked or if it doesnt exist"
lockCargoBikeById(id: ID!): Boolean!
"lock cargoBike returns bike if bike is not locked or Error"
lockCargoBikeById(id: ID!): CargoBike!
"unlock cargoBike"
unlockCargoBikeById(id: ID!): Boolean!
"updates cargoBike of given ID with supplied fields and returns updated cargoBike"

Loading…
Cancel
Save