|
|
@ -99,11 +99,10 @@ export class CargoBikeAPI extends DataSource {
|
|
|
|
const keepLock = cargoBike?.keepLock;
|
|
|
|
const keepLock = cargoBike?.keepLock;
|
|
|
|
delete cargoBike.keepLock;
|
|
|
|
delete cargoBike.keepLock;
|
|
|
|
delete cargoBike.lendingStationId;
|
|
|
|
delete cargoBike.lendingStationId;
|
|
|
|
let equipmentTypeIds: any = null;
|
|
|
|
const equipmentTypeIds = cargoBike?.equipmentTypeIds;
|
|
|
|
if (cargoBike.equipmentTypeIds) {
|
|
|
|
delete cargoBike?.equipmentTypeIds;
|
|
|
|
equipmentTypeIds = cargoBike.equipmentTypeIds;
|
|
|
|
const equipmentIds = cargoBike?.equipmentIds;
|
|
|
|
delete cargoBike.equipmentTypeIds;
|
|
|
|
delete cargoBike?.equipmentIds;
|
|
|
|
}
|
|
|
|
|
|
|
|
await this.connection.transaction(async (entityManager: EntityManager) => {
|
|
|
|
await this.connection.transaction(async (entityManager: EntityManager) => {
|
|
|
|
if (await LockUtils.isLocked(entityManager, CargoBike, 'cb', cargoBike.id, userId)) {
|
|
|
|
if (await LockUtils.isLocked(entityManager, CargoBike, 'cb', cargoBike.id, userId)) {
|
|
|
|
throw new GraphQLError('CargoBike locked by other user');
|
|
|
|
throw new GraphQLError('CargoBike locked by other user');
|
|
|
@ -119,7 +118,12 @@ export class CargoBikeAPI extends DataSource {
|
|
|
|
.createQueryBuilder('cb')
|
|
|
|
.createQueryBuilder('cb')
|
|
|
|
.relation(CargoBike, 'equipmentTypeIds')
|
|
|
|
.relation(CargoBike, 'equipmentTypeIds')
|
|
|
|
.of(cargoBike.id)
|
|
|
|
.of(cargoBike.id)
|
|
|
|
.addAndRemove(equipmentTypeIds, await this.equipmentTypeByCargoBikeId(cargoBike.id)); // TODO remove all existing relations
|
|
|
|
.addAndRemove(equipmentTypeIds, await this.equipmentTypeByCargoBikeId(cargoBike.id));
|
|
|
|
|
|
|
|
equipmentIds && await entityManager.getRepository(CargoBike)
|
|
|
|
|
|
|
|
.createQueryBuilder('cb')
|
|
|
|
|
|
|
|
.relation(CargoBike, 'equipmentIds')
|
|
|
|
|
|
|
|
.of(cargoBike.id)
|
|
|
|
|
|
|
|
.addAndRemove(equipmentIds, await this.equipmentByCargoBikeId(cargoBike.id));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
!keepLock && await LockUtils.unlockEntity(this.connection, CargoBike, 'cb', cargoBike.id, userId);
|
|
|
|
!keepLock && await LockUtils.unlockEntity(this.connection, CargoBike, 'cb', cargoBike.id, userId);
|
|
|
|
return await this.findCargoBikeById(cargoBike.id);
|
|
|
|
return await this.findCargoBikeById(cargoBike.id);
|
|
|
@ -144,7 +148,7 @@ export class CargoBikeAPI extends DataSource {
|
|
|
|
* created CargoBike and returns created bike with new ID
|
|
|
|
* created CargoBike and returns created bike with new ID
|
|
|
|
* @param param0 cargoBike to be created
|
|
|
|
* @param param0 cargoBike to be created
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
async createCargoBike ({ cargoBike }: { cargoBike: any }) {
|
|
|
|
async createCargoBike (cargoBike: any) {
|
|
|
|
let inserts: any = {};
|
|
|
|
let inserts: any = {};
|
|
|
|
await this.connection.transaction(async (entityManager:any) => {
|
|
|
|
await this.connection.transaction(async (entityManager:any) => {
|
|
|
|
inserts = await entityManager.getRepository(CargoBike)
|
|
|
|
inserts = await entityManager.getRepository(CargoBike)
|
|
|
@ -158,6 +162,11 @@ export class CargoBikeAPI extends DataSource {
|
|
|
|
.relation(CargoBike, 'equipmentTypeIds')
|
|
|
|
.relation(CargoBike, 'equipmentTypeIds')
|
|
|
|
.of(inserts.identifiers[0].id)
|
|
|
|
.of(inserts.identifiers[0].id)
|
|
|
|
.add(cargoBike.equipmentTypeIds);
|
|
|
|
.add(cargoBike.equipmentTypeIds);
|
|
|
|
|
|
|
|
cargoBike?.equipmentIds && await entityManager.getRepository(CargoBike)
|
|
|
|
|
|
|
|
.createQueryBuilder('cb')
|
|
|
|
|
|
|
|
.relation(CargoBike, 'equipmentIds')
|
|
|
|
|
|
|
|
.of(inserts.identifiers[0].id)
|
|
|
|
|
|
|
|
.add(cargoBike.equipmentIds);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
inserts.generatedMaps[0].id = inserts?.identifiers[0].id;
|
|
|
|
inserts.generatedMaps[0].id = inserts?.identifiers[0].id;
|
|
|
|
return inserts?.generatedMaps[0];
|
|
|
|
return inserts?.generatedMaps[0];
|
|
|
@ -411,14 +420,8 @@ export class CargoBikeAPI extends DataSource {
|
|
|
|
return await DBUtils.deleteEntity(this.connection, Equipment, 'e', id, userId);
|
|
|
|
return await DBUtils.deleteEntity(this.connection, Equipment, 'e', id, userId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async getEquipment (offset: number, limit: number) {
|
|
|
|
async getEquipment (offset?: number, limit?: number) {
|
|
|
|
return await this.connection.getRepository(Equipment)
|
|
|
|
return await DBUtils.getAllEntity(this.connection, Equipment, 'e', offset, limit);
|
|
|
|
.createQueryBuilder('equipment')
|
|
|
|
|
|
|
|
.leftJoinAndSelect('equipment.cargoBike', 'cargoBike')
|
|
|
|
|
|
|
|
.orderBy('title', 'ASC')
|
|
|
|
|
|
|
|
.offset(offset)
|
|
|
|
|
|
|
|
.limit(limit)
|
|
|
|
|
|
|
|
.getMany();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async createEquipmentType (equipmentType: any) {
|
|
|
|
async createEquipmentType (equipmentType: any) {
|
|
|
@ -473,13 +476,8 @@ export class CargoBikeAPI extends DataSource {
|
|
|
|
.getOne();
|
|
|
|
.getOne();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async equipmentTypes (offset: number, limit: number) {
|
|
|
|
async equipmentTypes (offset?: number, limit?: number) {
|
|
|
|
return await this.connection.getRepository(EquipmentType)
|
|
|
|
return await DBUtils.getAllEntity(this.connection, EquipmentType, 'et', offset, limit);
|
|
|
|
.createQueryBuilder('et')
|
|
|
|
|
|
|
|
.select()
|
|
|
|
|
|
|
|
.skip(offset)
|
|
|
|
|
|
|
|
.take(limit)
|
|
|
|
|
|
|
|
.getMany();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async equipmentTypeByCargoBikeId (id: number) {
|
|
|
|
async equipmentTypeByCargoBikeId (id: number) {
|
|
|
|