Merge pull request #13 from flotte-goes-smart/dev

Dev
pull/14/head
leonnicolas 4 years ago committed by GitHub
commit 52382352f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,12 @@
dist: bionic
language: bash
services:
- docker
script:
- docker login -u="$DOCKER_USER" -p="$DOCKER_PW" https://flotte-docker-registry.spdns.org/
- docker build -t apollo-server .
- docker tag apollo-server flotte-docker-registry.spdns.org/flotte_user-managment
- docker push apollo-server:latest

@ -1,5 +1,8 @@
# API-server # API-server
Apollo server written in typescript that handles business logic. Apollo server written in typescript that handles business logic.
[![Build Status](https://travis-ci.com/flotte-goes-smart/apollo-server.svg?token=YfRmpHAXqyUafCgSEexw&branch=main)](https://travis-ci.com/flotte-goes-smart/apollo-server)
## Assumptions ## Assumptions
Userserver and postgres are running e.g. with Julius' Docker Compose. Userserver and postgres are running e.g. with Julius' Docker Compose.
## Usage ## Usage

@ -48,6 +48,27 @@ export class CargoBikeAPI extends DataSource {
.getOne())?.cargoBike; .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 * Updates CargoBike and return updated cargoBike
* @param param0 cargoBike to be updated * @param param0 cargoBike to be updated

@ -7,5 +7,6 @@ export enum Method {
GetRoles = 0x52_4f_4c_45, GetRoles = 0x52_4f_4c_45,
GetRolePermissions = 0x50_45_52_4d, GetRolePermissions = 0x50_45_52_4d,
CreateRole = 0x43_52_4f_4c, CreateRole = 0x43_52_4f_4c,
CreatePermissions = 0x43_50_45_52 CreatePermissions = 0x43_50_45_52,
GetUserID = 0x55534552
} }

@ -83,6 +83,15 @@ export class UserServerAPI extends DataSource {
return response.data; return response.data;
} }
/**
* Returns userId
* @param token
*/
async getUserId (token: String): Promise<number> {
const response = await this.send<any>(new RPCMessage(Method.GetUserID, { token }));
return response.data;
}
/** /**
* Returns all permissions of the user * Returns all permissions of the user
* @param token * @param token

@ -142,7 +142,7 @@ export class CargoBike extends Bike {
lockedBy: number; lockedBy: number;
@Column({ @Column({
type: 'date', type: 'timestamp',
nullable: true nullable: true
}) })
lockedUntil: Date; lockedUntil: Date;

@ -66,6 +66,14 @@ export default {
return new GraphQLError('Insufficient Permissions'); 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 }) => { updateCargoBike: (_: any, { cargoBike }: { cargoBike: any }, { dataSources, req }:{dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.WriteBike)) { if (req.permissions.includes(Permission.WriteBike)) {
return dataSources.cargoBikeAPI.updateCargoBike({ cargoBike }); return dataSources.cargoBikeAPI.updateCargoBike({ cargoBike });

@ -710,6 +710,8 @@ type Query {
type Mutation { type Mutation {
"creates new cargoBike and returns cargobike with new ID" "creates new cargoBike and returns cargobike with new ID"
createCargoBike(cargoBike: CargoBikeCreateInput!): CargoBike! createCargoBike(cargoBike: CargoBikeCreateInput!): CargoBike!
"lock cargoBike - not implemented"
lockCargoBikeById(id: ID!): Boolean!
"updates cargoBike of given ID with supplied fields and returns updated cargoBike" "updates cargoBike of given ID with supplied fields and returns updated cargoBike"
updateCargoBike(cargoBike: CargoBikeUpdateInput!): CargoBike! updateCargoBike(cargoBike: CargoBikeUpdateInput!): CargoBike!
"creates new peace of unique Equipment" "creates new peace of unique Equipment"

Loading…
Cancel
Save