|
|
@ -181,7 +181,7 @@ export class CargoBikeAPI extends DataSource {
|
|
|
|
* @param param0 cargoBike to be updated
|
|
|
|
* @param param0 cargoBike to be updated
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
async updateCargoBike (cargoBike: any, req: any, dataSources: any) {
|
|
|
|
async updateCargoBike (cargoBike: any, req: any, dataSources: any) {
|
|
|
|
// TODO let lock cargoBike can return error to save one sql query, this will be a complex sql query
|
|
|
|
// TODO lock cargoBike can return error to save one sql query, this will be a complex sql query
|
|
|
|
if (!await this.checkId(CargoBike, 'cargobike', cargoBike.id)) {
|
|
|
|
if (!await this.checkId(CargoBike, 'cargobike', cargoBike.id)) {
|
|
|
|
return new GraphQLError('ID not found');
|
|
|
|
return new GraphQLError('ID not found');
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -196,7 +196,6 @@ export class CargoBikeAPI extends DataSource {
|
|
|
|
.where('cargoBike.id = :id', { id: cargoBike.id })
|
|
|
|
.where('cargoBike.id = :id', { id: cargoBike.id })
|
|
|
|
.getOne();
|
|
|
|
.getOne();
|
|
|
|
if (bike.id) {
|
|
|
|
if (bike.id) {
|
|
|
|
const lendingStationId = cargoBike.lendingStationId;
|
|
|
|
|
|
|
|
delete cargoBike.lendingStationId;
|
|
|
|
delete cargoBike.lendingStationId;
|
|
|
|
await this.connection.manager
|
|
|
|
await this.connection.manager
|
|
|
|
.createQueryBuilder()
|
|
|
|
.createQueryBuilder()
|
|
|
@ -204,14 +203,7 @@ export class CargoBikeAPI extends DataSource {
|
|
|
|
.set({ ...cargoBike })
|
|
|
|
.set({ ...cargoBike })
|
|
|
|
.where('id = :id', { id: bike.id })
|
|
|
|
.where('id = :id', { id: bike.id })
|
|
|
|
.execute();
|
|
|
|
.execute();
|
|
|
|
if (lendingStationId || lendingStationId === null) {
|
|
|
|
!keepLock && await this.unlockCargoBike(cargoBike.id, req, dataSources);
|
|
|
|
await this.connection.getRepository(CargoBike)
|
|
|
|
|
|
|
|
.createQueryBuilder()
|
|
|
|
|
|
|
|
.relation(CargoBike, 'lendingStation')
|
|
|
|
|
|
|
|
.of(cargoBike.id)
|
|
|
|
|
|
|
|
.set(lendingStationId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
!keepLock && this.unlockCargoBike(cargoBike.id, req, dataSources);
|
|
|
|
|
|
|
|
return await this.findCargoBikeById(bike.id);
|
|
|
|
return await this.findCargoBikeById(bike.id);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return new GraphQLError('ID not in database');
|
|
|
|
return new GraphQLError('ID not in database');
|
|
|
@ -233,11 +225,6 @@ export class CargoBikeAPI extends DataSource {
|
|
|
|
.values([cargoBike])
|
|
|
|
.values([cargoBike])
|
|
|
|
.returning('*')
|
|
|
|
.returning('*')
|
|
|
|
.execute();
|
|
|
|
.execute();
|
|
|
|
await entityManager.getRepository(CargoBike)
|
|
|
|
|
|
|
|
.createQueryBuilder('cargobike')
|
|
|
|
|
|
|
|
.relation(CargoBike, 'lendingStation')
|
|
|
|
|
|
|
|
.of(inserts.identifiers[0].id)
|
|
|
|
|
|
|
|
.set(cargoBike?.lendingStationId);
|
|
|
|
|
|
|
|
await entityManager.getRepository(CargoBike)
|
|
|
|
await entityManager.getRepository(CargoBike)
|
|
|
|
.createQueryBuilder('cargobike')
|
|
|
|
.createQueryBuilder('cargobike')
|
|
|
|
.relation(CargoBike, 'provider')
|
|
|
|
.relation(CargoBike, 'provider')
|
|
|
@ -293,15 +280,6 @@ export class CargoBikeAPI extends DataSource {
|
|
|
|
return result === 1;
|
|
|
|
return result === 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// think this can go
|
|
|
|
|
|
|
|
async findEquipmentJoinBikeById (id: number) {
|
|
|
|
|
|
|
|
return await this.connection.getRepository(Equipment)
|
|
|
|
|
|
|
|
.createQueryBuilder('equipment')
|
|
|
|
|
|
|
|
.leftJoinAndSelect('equipment.cargoBike', 'cargoBike')
|
|
|
|
|
|
|
|
.where('equipment.id = :id', { id: id })
|
|
|
|
|
|
|
|
.getOne();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async equipmentByCargoBikeId (offset: number, limit: number, id: number) {
|
|
|
|
async equipmentByCargoBikeId (offset: number, limit: number, id: number) {
|
|
|
|
return await this.connection.getRepository(Equipment)
|
|
|
|
return await this.connection.getRepository(Equipment)
|
|
|
|
.createQueryBuilder('equipment')
|
|
|
|
.createQueryBuilder('equipment')
|
|
|
@ -324,7 +302,6 @@ export class CargoBikeAPI extends DataSource {
|
|
|
|
.relation(Equipment, 'cargoBike')
|
|
|
|
.relation(Equipment, 'cargoBike')
|
|
|
|
.of(equipment.id)
|
|
|
|
.of(equipment.id)
|
|
|
|
.set(equipment.cargoBikeId);
|
|
|
|
.set(equipment.cargoBikeId);
|
|
|
|
// return this.findEquipmentJoinBikeById(inserts.identifiers[0].id);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.findEquipmentById(inserts.identifiers[0].id);
|
|
|
|
return this.findEquipmentById(inserts.identifiers[0].id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|