From feeaaa247b2cdbc165806b87409facc0bf3ddab8 Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Wed, 23 Sep 2020 17:37:07 +0200 Subject: [PATCH] fixed type ploceCod(e)ing --- src/datasources/db/cargobikeAPI.ts | 34 ++++-------------------------- src/model/CargoBike.ts | 2 +- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/src/datasources/db/cargobikeAPI.ts b/src/datasources/db/cargobikeAPI.ts index 4508d40..3b60285 100644 --- a/src/datasources/db/cargobikeAPI.ts +++ b/src/datasources/db/cargobikeAPI.ts @@ -48,38 +48,12 @@ export class CargoBikeAPI extends DataSource { } async lockCargoBike (id: number, req: any, dataSources: any) { - const token = req.headers.authorization?.replace('Bearer ', ''); - const userId = await dataSources.userAPI.getUserId(token); - const lock = await this.connection.getRepository(CargoBike) - .createQueryBuilder('cargobike') - .select([ - 'cargobike.lockedUntil', - 'cargobike.lockedBy' - ]) - .where('id = :id', { - id: id - }) - .andWhere('cargobike.lockedUntil > CURRENT_TIMESTAMP') - .getOne(); - // eslint-disable-next-line eqeqeq - if (!lock?.lockedUntil || lock?.lockedBy == userId) { - // no lock -> set lock - await this.connection.getRepository(CargoBike) - .createQueryBuilder('cargoBike') - .update() - .set({ - lockedUntil: () => 'CURRENT_TIMESTAMP + INTERVAL \'10 MINUTE\'', - lockedBy: userId - }) - .where('id = :id', { id: id }) - .execute(); - return true; - } else { - // lock was set - return false; - } + return this.lockEntity(CargoBike, 'cargobike', id, req, dataSources); } + /** + * lock any entity that implemts Lockable + */ async lockEntity (target: ObjectType, alias: string, id: number, req: any, dataSources: any) { const token = req.headers.authorization?.replace('Bearer ', ''); const userId = await dataSources.userAPI.getUserId(token); diff --git a/src/model/CargoBike.ts b/src/model/CargoBike.ts index 2e12dcb..6d23d24 100644 --- a/src/model/CargoBike.ts +++ b/src/model/CargoBike.ts @@ -53,7 +53,7 @@ export class Security { @Column({ nullable: true }) - policeCodeing: string; + policeCoding: string; @Column({ nullable: true