From 87fd338088c5e8d0afdc473965f1346bcd1950b9 Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Fri, 11 Sep 2020 18:41:03 +0200 Subject: [PATCH 1/3] Dockerfile: db connection works out of Docker container. --- Dockerfile | 5 +++-- README.md | 6 +++++- ormconfig.json | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index b83fbf7..6b03e8e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,12 +3,13 @@ WORKDIR / COPY ./src /src COPY ./package*.json ./ -COPY ./gulpfile.js ./tsconfig.json ./tslint.json ./ - +COPY ./gulpfile.js ./tsconfig.json ./ +COPY ./ormconfig.json ./ RUN npm install RUN npm install -g gulp RUN npm install gulp RUN gulp EXPOSE 4000 +EXPOSE 5432 CMD ["npm", "start"] \ No newline at end of file diff --git a/README.md b/README.md index 85bb912..1eef3b9 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,14 @@ Apollo server written in typescript that handles business logic. ## Usage +### Configure Postgres +Install postgresql and configure it, so the Database is accessible from remote hosts (only necessary for docker container [Here](https://wiki.archlinux.org/index.php/PostgreSQL)) + +See postgres client config in __ormconfig.json__ ### Docker ```bash docker build -t . -docker run --rm -p 4000:4000 +docker run --rm --network="host" ``` The Dockerfile is pretty stupid and could produce a smaller image, e.g. with multistage build. ### Compile and run diff --git a/ormconfig.json b/ormconfig.json index 1fa2192..250b347 100644 --- a/ormconfig.json +++ b/ormconfig.json @@ -1,6 +1,6 @@ { "type": "postgres", - "host": "localhost", + "host": "127.17.42.1", "port": 5432, "username": "apollo", "database": "apollo_test", From 85e1d95631f51cf783ce5c873fc817af5d4f78ef Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Fri, 11 Sep 2020 19:15:01 +0200 Subject: [PATCH 2/3] type-des: first test mutation --- src/datasources/db/cargobikeAPI.ts | 24 +++++++++++++++++++++++- src/resolvers/cargobikeResolver.ts | 4 ++++ src/schema/type-defs.ts | 3 ++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/datasources/db/cargobikeAPI.ts b/src/datasources/db/cargobikeAPI.ts index 824195e..a88844e 100644 --- a/src/datasources/db/cargobikeAPI.ts +++ b/src/datasources/db/cargobikeAPI.ts @@ -1,9 +1,15 @@ import { DataSource } from 'apollo-datasource' - +import { getConnection, Connection } from 'typeorm' +import { CargoBike } from '../../model/CargoBike' /** * extended datasource to feed resolvers with data about cargoBikes */ export class CargoBikeAPI extends DataSource { + connection : Connection + constructor(){ + super() + this.connection = getConnection() + } /** * Finds cargo bike by id */ @@ -13,4 +19,20 @@ export class CargoBikeAPI extends DataSource { name: token } } + + async updateBike ({ id, token, name }:{id:any, token: string, name: string }) { + const bike = new CargoBike() + bike.id = id + bike.description = token + bike.name = name + this.connection.manager.save(bike) + return { + success: true, + message: token, + bike: { + id, + name + } + } + } } diff --git a/src/resolvers/cargobikeResolver.ts b/src/resolvers/cargobikeResolver.ts index 56da61a..bca1077 100644 --- a/src/resolvers/cargobikeResolver.ts +++ b/src/resolvers/cargobikeResolver.ts @@ -2,5 +2,9 @@ export default { Query: { cargobike: (_: any, { id, token }:{id: any, token: string}, { dataSources }:{dataSources: any}) => dataSources.cargoBikeAPI.findCargoBikeById({ id, token }) + }, + Mutation: { + addBike: (_:any, { id, token, name }:{id: any, token: string, name:string}, { dataSources }:{dataSources: any }) => + dataSources.cargoBikeAPI.updateBike({ id, token, name }) } } diff --git a/src/schema/type-defs.ts b/src/schema/type-defs.ts index aaf7b2a..1c3739c 100644 --- a/src/schema/type-defs.ts +++ b/src/schema/type-defs.ts @@ -265,9 +265,10 @@ type UpdateBikeResponse { message: String bike: CargoBike } + "for testing" type Mutation { - addBike(id: ID!):UpdateBikeResponse + addBike(id: ID!, token: String!, name: String):UpdateBikeResponse } ` From dc36ad431a888986f285f195e0ac9d9a13cc3c34 Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Sat, 12 Sep 2020 00:22:08 +0200 Subject: [PATCH 3/3] type-defs.ts: added types and queries --- .eslintrc.json | 3 +- package-lock.json | 10 -- package.json | 3 +- src/datasources/db/cargobikeAPI.ts | 3 +- src/resolvers/cargobikeResolver.ts | 2 +- src/schema/type-defs.ts | 150 ++++++++++++++++++++++------- 6 files changed, 123 insertions(+), 48 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index e5f07eb..0517186 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,6 +1,7 @@ { + "root": true, "env": { - "browser": true + "node": true }, "extends": [ "standard" diff --git a/package-lock.json b/package-lock.json index cc30dd9..d5e0b5a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -260,11 +260,6 @@ "@types/node": "*" } }, - "@types/bluebird": { - "version": "3.5.32", - "resolved": "https://registry.npmjs.org/@types/bluebird/-/bluebird-3.5.32.tgz", - "integrity": "sha512-dIOxFfI0C+jz89g6lQ+TqhGgPQ0MxSnh/E4xuC0blhFtyW269+mPG5QeLgbdwst/LvdP8o1y0o/Gz5EHXLec/g==" - }, "@types/body-parser": { "version": "1.19.0", "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.0.tgz", @@ -444,11 +439,6 @@ "@types/mime": "*" } }, - "@types/validator": { - "version": "13.1.0", - "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.1.0.tgz", - "integrity": "sha512-gHUHI6pJaANIO2r6WcbT7+WMgbL9GZooR4tWpuBOETpDIqFNxwaJluE+6rj6VGYe8k6OkfhbHz2Fkm8kl06Igw==" - }, "@types/ws": { "version": "7.2.6", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-7.2.6.tgz", diff --git a/package.json b/package.json index 6acd53a..cc9fd74 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "node dist/index.js", + "lint": "eslint --config .eslintrc.json --fix src/**/*.ts", "start:ci": "node dist/index.js" }, "keywords": [], @@ -29,8 +30,6 @@ "typescript": "^4.0.2" }, "dependencies": { - "@types/bluebird": "^3.5.32", - "@types/validator": "^13.1.0", "apollo-server": "^2.17.0", "graphql": "^15.3.0", "pg": "^8.3.3", diff --git a/src/datasources/db/cargobikeAPI.ts b/src/datasources/db/cargobikeAPI.ts index a88844e..1a3709d 100644 --- a/src/datasources/db/cargobikeAPI.ts +++ b/src/datasources/db/cargobikeAPI.ts @@ -6,10 +6,11 @@ import { CargoBike } from '../../model/CargoBike' */ export class CargoBikeAPI extends DataSource { connection : Connection - constructor(){ + constructor () { super() this.connection = getConnection() } + /** * Finds cargo bike by id */ diff --git a/src/resolvers/cargobikeResolver.ts b/src/resolvers/cargobikeResolver.ts index bca1077..a7c89db 100644 --- a/src/resolvers/cargobikeResolver.ts +++ b/src/resolvers/cargobikeResolver.ts @@ -1,6 +1,6 @@ export default { Query: { - cargobike: (_: any, { id, token }:{id: any, token: string}, { dataSources }:{dataSources: any}) => + CargobikeById: (_: any, { id, token }:{id: any, token: string}, { dataSources }:{dataSources: any}) => dataSources.cargoBikeAPI.findCargoBikeById({ id, token }) }, Mutation: { diff --git a/src/schema/type-defs.ts b/src/schema/type-defs.ts index 1c3739c..517cbdf 100644 --- a/src/schema/type-defs.ts +++ b/src/schema/type-defs.ts @@ -40,6 +40,7 @@ type CargoBike { provider: Provider coordinator: Coordinator insuranceData: InsuranceData + loantimes: [LoanTimes] } type InsuranceData { @@ -55,6 +56,7 @@ type Coordinator { note: String corgoBikes: [CargoBike]! } + enum Group{ KL LI @@ -65,6 +67,7 @@ enum Group{ TS TK } + """ The BikeModel can be used for instantiate new bikes with a given model. It should only be used to fill in default values. @@ -74,6 +77,7 @@ type BikeModel { id: ID! name: String dimensionsAndLoad: DimensionsAndLoad! + technicalEquipment: TechnicalEquipment! } type ActiveMentor { @@ -81,6 +85,31 @@ type ActiveMentor { start: Date! end: Date! mentor: ContactInformation! + usernamefLotte: String + usernameSlack: String + memberADFC: Boolean! + locationZIPs: [String] + roleCoreTeam: Boolean! + roleCoordinator: Boolean! + roleEmployeADFC: Boolean! + """ + Wahr, wenn die Person Pate ist. + """ + roleMentor: Boolean! + roleAmbulanz: Boolean! + roleBringer: Boolean! + "Date of workshop to become Mentor dt. Pate" + workshopMentor: Date + "Date of last Erste Hilfe Kurs?" + workshopAmbulance: Date + """ + Note the kommentierte Infodaten Tabelle. + This value is calculated form other values. + It is true, if the person is not on the black list and not retired + and is either Mentor dt. Pate or Partner Mentor dt. Partnerpate for at least one bike. + """ + distributedActiveBikeParte: Boolean! + reserve: String } type Taxes { @@ -102,6 +131,7 @@ type ChainSwap { timeOfSwap: Date keyNumberOldAXAChain: String } + """ This type represents a piece of equipment that represents a real physical object. The object must be unique. So it is possible to tell it apart from similar objects by a serial number. @@ -195,26 +225,25 @@ enum StickerBikeNameState { UNKNOWN } +"(dt. Anbieter)" type Provider { id: ID! name: String! formularName: String - address: String + address: Address "If Club, at what court registered" registeredAt: String registerNumber: String providerContactPerson: [ContactInformation] - email: String - phone: String isPrivatePerson: Boolean! - organisations: Organisation + organisation: Organisation cargoBikes: [CargoBike]! } type ContactInformation { id: ID! name: String! - firstName: String! + firstName: String retiredAt: Date phoneExtern: String phone2Extern: String @@ -222,42 +251,61 @@ type ContactInformation { phone2Intern: String emailExtern: String emailIntern: String - usernamefLotte: String - usernameSlack: String - memberADFC: Boolean! - locationZIPs: [String] - roleCoreTeam: Boolean! - roleCoordinator: Boolean! - roleEmployeADFC: Boolean! - """ - Wahr, wenn die Person Pate ist. - """ - roleMentor: Boolean! - roleAmbulanz: Boolean! - roleBringer: Boolean! - "Date of workshop to become Mentor dt. Pate" - workshopMentor: Date - "Date of last Erste Hilfe Kurs?" - workshopAmbulance: Date + note: String - """ - Note the kommentierte Infodaten Tabelle. - This value is calculated form other values. - It is true, if the person is not on the black list and not retired - and is either Mentor dt. Pate or Partner Mentor dt. Partnerpate for at least one bike. - """ - distributedActiveBikeParte: Boolean! - reserve: String + } type Organisation{ id: ID! + "(dt. Ausleihstation)" + lendinglocation: [LendingStation] "registration number of association" associationNo: String + otherdata: String +} + +"(dt. Standort)" +type LendingStation { + id: ID! + contactInformation: [ContactInformation]! + address: Address + loanTimes: LoanTimes + loanPeriods: [LoanPeriod]! +} + +"(dt. Ausleihzeiten)" +type LoanTimes { + notes: String +} + +"(dt. Zeitscheibe)" +type LoanPeriod{ + id: ID! + from: Date! + to: Date + note: String + lendingstation: LendingStation! + cargobike: CargoBike! +} + +type Address { + street: String + number: String + zip: String } type Query { - cargobike(token:String!,id:ID!): CargoBike + CargobikeById(token:String!,id:ID!): CargoBike + Cargobikes(token:String!): [CargoBike]! + CargobikesByProvider(token:String!,providerId:ID!): [CargoBike]! + ProviderById(token:String!,id:ID!): Provider + Providers(token:String!): [Provider]! + ActiveMentorById(token:String!,id:ID!): ActiveMentor + ActiveMentors(token:String!): [ActiveMentor]! + lendingStationById(token:String!, id:ID!): LendingStation + lendingStations(token:String!): [LendingStation]! + contactInformation(token:String!): [ContactInformation]! } type UpdateBikeResponse { @@ -266,9 +314,45 @@ type UpdateBikeResponse { bike: CargoBike } -"for testing" +input CargoBikeInput { + "if null, then new bike will be created, else old bike will be updated" + id: ID + "see column A in info tabelle" + group: Group + name: String + modelName: String + numberOfWheels: Int + forCargo: Boolean + forChildren: Boolean + numberOfChildren: Int + serialno: String + """ + Safety is a custom type, that stores information about security features. + TODO: Should this be calles Security? + """ + security: String + """ + Does not refere to an extra table in the database. + """ + technicalEquipment: String + """ + Does not refere to an extra table in the database. + """ + dimensionsAndLoad: String + "Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2" + otherEquipment: String + "Sticker State" + stickerBikeNameState: String + note: String + provider: String + coordinator: String + insuranceData: String +} type Mutation { - addBike(id: ID!, token: String!, name: String):UpdateBikeResponse + "for testing" + addBike(id: ID!, token: String!, name: String): UpdateBikeResponse! + "if id: null, then new bike will be created, else old bike will be updated" + cargoBike(token:String!,cargoBike: CargoBikeInput): UpdateBikeResponse! } `