From e4a131db8da31730a5bd2fe3d18fb916085660df Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Tue, 22 Sep 2020 23:27:11 +0200 Subject: [PATCH] .travis.yml: added travis file --- .travis.yml | 12 +++++++++++ src/datasources/db/cargobikeAPI.ts | 21 ++++++++++++++++++++ src/datasources/userserver/method.ts | 3 ++- src/datasources/userserver/userserviceAPI.ts | 9 +++++++++ src/model/CargoBike.ts | 2 +- src/resolvers/cargobikeResolver.ts | 8 ++++++++ src/schema/type-defs.ts | 2 ++ 7 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..18a272d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +dist: bionic + +language: bash + +services: + - docker + +script: + - docker login -u="$registryuser" -p="$registrypw" + - docker build -t apollo-server . + - docker tag apollo-server flotte-docker-registry.spdns.org/flotte_user-managment + - docker push apollo-server:latest \ No newline at end of file diff --git a/src/datasources/db/cargobikeAPI.ts b/src/datasources/db/cargobikeAPI.ts index 5cea37d..01307b4 100644 --- a/src/datasources/db/cargobikeAPI.ts +++ b/src/datasources/db/cargobikeAPI.ts @@ -48,6 +48,27 @@ export class CargoBikeAPI extends DataSource { .getOne())?.cargoBike; } + async lockCargoBike (id: number, req: any, dataSources: any) { + console.log("token:"); + console.log(req.headers.authorization); + const token = req.headers.authorization?.replace('Bearer ', ''); + console.log(token); + console.log(await dataSources.userAPI.getUserId(token)); + const lock = await this.connection.getRepository(CargoBike) + .createQueryBuilder('cargoBike') + .select([ + 'cargoBike.lockedUntil', + 'cargoBike.lockedBy' + ]) + .where('id = :id', { + id: id + }) + .getOne(); + //console.log(req); + console.log(lock); + return false; + } + /** * Updates CargoBike and return updated cargoBike * @param param0 cargoBike to be updated diff --git a/src/datasources/userserver/method.ts b/src/datasources/userserver/method.ts index 70ec609..5e89ef0 100644 --- a/src/datasources/userserver/method.ts +++ b/src/datasources/userserver/method.ts @@ -7,5 +7,6 @@ export enum Method { GetRoles = 0x52_4f_4c_45, GetRolePermissions = 0x50_45_52_4d, CreateRole = 0x43_52_4f_4c, - CreatePermissions = 0x43_50_45_52 + CreatePermissions = 0x43_50_45_52, + GetUserID = 0x55534552 } diff --git a/src/datasources/userserver/userserviceAPI.ts b/src/datasources/userserver/userserviceAPI.ts index 09174cd..389aff7 100644 --- a/src/datasources/userserver/userserviceAPI.ts +++ b/src/datasources/userserver/userserviceAPI.ts @@ -83,6 +83,15 @@ export class UserServerAPI extends DataSource { return response.data; } + /** + * Returns userId + * @param token + */ + async getUserId (token: String): Promise { + const response = await this.send(new RPCMessage(Method.GetUserID, { token })); + return response.data; + } + /** * Returns all permissions of the user * @param token diff --git a/src/model/CargoBike.ts b/src/model/CargoBike.ts index 5adc52b..99fb15f 100644 --- a/src/model/CargoBike.ts +++ b/src/model/CargoBike.ts @@ -142,7 +142,7 @@ export class CargoBike extends Bike { lockedBy: number; @Column({ - type: 'date', + type: 'timestamp', nullable: true }) lockedUntil: Date; diff --git a/src/resolvers/cargobikeResolver.ts b/src/resolvers/cargobikeResolver.ts index 0a2b70b..86e64e6 100644 --- a/src/resolvers/cargobikeResolver.ts +++ b/src/resolvers/cargobikeResolver.ts @@ -66,6 +66,14 @@ export default { return new GraphQLError('Insufficient Permissions'); } }, + lockCargoBikeById: (_: any, { id }: { id: number }, { dataSources, req }:{dataSources: any, req: any }) => { + if (req.permissions.includes(Permission.WriteBike)) { + + return dataSources.cargoBikeAPI.lockCargoBike(id, req, dataSources); + } else { + return new GraphQLError('Insufficient Permissions'); + } + }, updateCargoBike: (_: any, { cargoBike }: { cargoBike: any }, { dataSources, req }:{dataSources: any, req: any }) => { if (req.permissions.includes(Permission.WriteBike)) { return dataSources.cargoBikeAPI.updateCargoBike({ cargoBike }); diff --git a/src/schema/type-defs.ts b/src/schema/type-defs.ts index f6e8275..6041341 100644 --- a/src/schema/type-defs.ts +++ b/src/schema/type-defs.ts @@ -710,6 +710,8 @@ type Query { type Mutation { "creates new cargoBike and returns cargobike with new ID" createCargoBike(cargoBike: CargoBikeCreateInput!): CargoBike! + "lock cargoBike - not implemented" + lockCargoBikeById(id: ID!): Boolean! "updates cargoBike of given ID with supplied fields and returns updated cargoBike" updateCargoBike(cargoBike: CargoBikeUpdateInput!): CargoBike! "creates new peace of unique Equipment"