fixed ts error

pull/14/head
leonnicolas 4 years ago
parent a73390877b
commit 6f951845cb
No known key found for this signature in database
GPG Key ID: 088D0743E2B65C07

@ -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\'',

@ -31,6 +31,11 @@ export enum StickerBikeNameState {
UNKNOWN UNKNOWN
} }
export interface Lockable {
lockedBy: number,
lockedUntil: Date
}
export class Security { export class Security {
@Column() @Column()
frameNumber: string; frameNumber: string;
@ -57,7 +62,7 @@ export class Security {
} }
@Entity() @Entity()
export class CargoBike extends Bike { export class CargoBike extends Bike implements Lockable {
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
id: number; id: number;

Loading…
Cancel
Save