From 6f951845cb54a7a87f7c98bafd65544e8c9f3204 Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Wed, 23 Sep 2020 17:30:29 +0200 Subject: [PATCH] fixed ts error --- src/datasources/db/cargobikeAPI.ts | 8 ++++---- src/model/CargoBike.ts | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/datasources/db/cargobikeAPI.ts b/src/datasources/db/cargobikeAPI.ts index 54c3fd0..4508d40 100644 --- a/src/datasources/db/cargobikeAPI.ts +++ b/src/datasources/db/cargobikeAPI.ts @@ -1,6 +1,6 @@ import { DataSource } from 'apollo-datasource'; import { getConnection, Connection, ObjectType } from 'typeorm'; -import { CargoBike } from '../../model/CargoBike'; +import { CargoBike, Lockable } from '../../model/CargoBike'; import { GraphQLError } from 'graphql'; import { BikeEvent } from '../../model/BikeEvent'; import { Equipment } from '../../model/Equipment'; @@ -80,7 +80,7 @@ export class CargoBikeAPI extends DataSource { } } - async lockEntity (target: ObjectType, alias: string, id: number, req: any, dataSources: any) { + 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); const lock = await this.connection.getRepository(target) @@ -97,8 +97,8 @@ export class CargoBikeAPI extends DataSource { // eslint-disable-next-line eqeqeq if (!lock?.lockedUntil || lock?.lockedBy == userId) { // no lock -> set lock - await this.connection.getRepository(CargoBike) - .createQueryBuilder('cargoBike') + await this.connection.getRepository(target) + .createQueryBuilder(alias) .update() .set({ lockedUntil: () => 'CURRENT_TIMESTAMP + INTERVAL \'10 MINUTE\'', diff --git a/src/model/CargoBike.ts b/src/model/CargoBike.ts index 1dca1bd..2e12dcb 100644 --- a/src/model/CargoBike.ts +++ b/src/model/CargoBike.ts @@ -31,6 +31,11 @@ export enum StickerBikeNameState { UNKNOWN } +export interface Lockable { + lockedBy: number, + lockedUntil: Date +} + export class Security { @Column() frameNumber: string; @@ -57,7 +62,7 @@ export class Security { } @Entity() -export class CargoBike extends Bike { +export class CargoBike extends Bike implements Lockable { @PrimaryGeneratedColumn() id: number;