|
|
@ -1,6 +1,6 @@
|
|
|
|
import { DataSource } from 'apollo-datasource';
|
|
|
|
import { DataSource } from 'apollo-datasource';
|
|
|
|
import { getConnection, Connection, ObjectType } from 'typeorm';
|
|
|
|
import { getConnection, Connection, ObjectType } from 'typeorm';
|
|
|
|
import { CargoBike } from '../../model/CargoBike';
|
|
|
|
import { CargoBike, Lockable } from '../../model/CargoBike';
|
|
|
|
import { GraphQLError } from 'graphql';
|
|
|
|
import { GraphQLError } from 'graphql';
|
|
|
|
import { BikeEvent } from '../../model/BikeEvent';
|
|
|
|
import { BikeEvent } from '../../model/BikeEvent';
|
|
|
|
import { Equipment } from '../../model/Equipment';
|
|
|
|
import { Equipment } from '../../model/Equipment';
|
|
|
@ -80,7 +80,7 @@ export class CargoBikeAPI extends DataSource {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async lockEntity<MyEntity> (target: ObjectType<MyEntity>, alias: string, id: number, req: any, dataSources: any) {
|
|
|
|
async lockEntity (target: ObjectType<Lockable>, alias: string, id: number, req: any, dataSources: any) {
|
|
|
|
const token = req.headers.authorization?.replace('Bearer ', '');
|
|
|
|
const token = req.headers.authorization?.replace('Bearer ', '');
|
|
|
|
const userId = await dataSources.userAPI.getUserId(token);
|
|
|
|
const userId = await dataSources.userAPI.getUserId(token);
|
|
|
|
const lock = await this.connection.getRepository(target)
|
|
|
|
const lock = await this.connection.getRepository(target)
|
|
|
@ -97,8 +97,8 @@ export class CargoBikeAPI extends DataSource {
|
|
|
|
// eslint-disable-next-line eqeqeq
|
|
|
|
// eslint-disable-next-line eqeqeq
|
|
|
|
if (!lock?.lockedUntil || lock?.lockedBy == userId) {
|
|
|
|
if (!lock?.lockedUntil || lock?.lockedBy == userId) {
|
|
|
|
// no lock -> set lock
|
|
|
|
// no lock -> set lock
|
|
|
|
await this.connection.getRepository(CargoBike)
|
|
|
|
await this.connection.getRepository(target)
|
|
|
|
.createQueryBuilder('cargoBike')
|
|
|
|
.createQueryBuilder(alias)
|
|
|
|
.update()
|
|
|
|
.update()
|
|
|
|
.set({
|
|
|
|
.set({
|
|
|
|
lockedUntil: () => 'CURRENT_TIMESTAMP + INTERVAL \'10 MINUTE\'',
|
|
|
|
lockedUntil: () => 'CURRENT_TIMESTAMP + INTERVAL \'10 MINUTE\'',
|
|
|
|