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

typeorm: connected to postgres with typeorm
pull/4/head
leonnicolas 4 years ago committed by GitHub
commit 7ce786d3d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,7 +1,6 @@
{ {
"env": { "env": {
"browser": true, "browser": true
"es2021": true
}, },
"extends": [ "extends": [
"standard" "standard"
@ -15,5 +14,17 @@
"@typescript-eslint" "@typescript-eslint"
], ],
"rules": { "rules": {
} "new-parens": 1,
"no-bitwise": 1,
"brace-style": "warn",
"no-namespace": 0,
"indent": ["warn", 4],
"no-internal-module": 0,
"max-classes-per-file": 0,
"no-var-requires": 0,
"array-type": 0,
"semi": 1,
"semi-style": ["error", "last"]
}
} }

@ -1,81 +1,83 @@
const {src, dest, watch, series, task} = require('gulp'); const { src, dest, watch, series, task } = require('gulp')
const ts = require('gulp-typescript'); const ts = require('gulp-typescript')
const del = require('delete'); const del = require('delete')
const eslint = require('gulp-eslint'); const eslint = require('gulp-eslint')
const nodemon = require('gulp-nodemon'); const nodemon = require('gulp-nodemon')
/** /**
* Clears the dist folder by deleting all files inside. * Clears the dist folder by deleting all files inside.
* @param cb * @param cb
*/ */
function clearDist(cb) { function clearDist (cb) {
del('dist/*', cb); del('dist/*', cb)
} }
/** /**
* Typescript compilation task. * Typescript compilation task.
* @returns {*} * @returns {*}
*/ */
function compileTypescript() { function compileTypescript () {
let tsProject = ts.createProject('tsconfig.json'); const tsProject = ts.createProject('tsconfig.json')
let tsResult = tsProject.src().pipe(tsProject()); const tsResult = tsProject.src().pipe(tsProject())
return tsResult return tsResult
//.pipe(minify()) // .pipe(minify())
.pipe(dest('dist')); .pipe(dest('dist'))
} }
/** /**
* Task for moving all remaining file from source to dist that don't need procession. * Task for moving all remaining file from source to dist that don't need procession.
* @returns {*} * @returns {*}
*/ */
function moveRemaining() { function moveRemaining () {
return src(['src/**/*', '!src/**/*.ts']) return src(['src/**/*', '!src/**/*.ts'])
.pipe(dest('dist')); .pipe(dest('dist'))
} }
function runEslint() { function runEslint () {
return src(['scripts/*.js']) return src(['src/**/*.ts'])
// eslint() attaches the lint output to the "eslint" property // eslint() attaches the lint output to the "eslint" property
// of the file object so it can be used by other modules. // of the file object so it can be used by other modules.
.pipe(eslint()) .pipe(eslint({ fix: true }))
// eslint.format() outputs the lint results to the console. // eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs). // Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format()) .pipe(eslint.format())
// To have the process exit with an error code (1) on // To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last. // lint error, return the stream and pipe to failAfterError last.
.pipe(eslint.failAfterError()); .pipe(eslint.failAfterError())
} }
task('eslint', () => { task('eslint', () => {
return src(['scripts/*.js']) return src(['src/**/*.ts'])
// eslint() attaches the lint output to the "eslint" property // eslint() attaches the lint output to the "eslint" property
// of the file object so it can be used by other modules. // of the file object so it can be used by other modules.
.pipe(eslint()) .pipe(eslint({ fix: true }))
// eslint.format() outputs the lint results to the console. // eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs). // Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format()) .pipe(eslint.format())
// To have the process exit with an error code (1) on // To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last. // lint error, return the stream and pipe to failAfterError last.
.pipe(eslint.failAfterError()); .pipe(eslint.failAfterError())
}); })
task('default', series(clearDist, compileTypescript, moveRemaining)); task('default', series(clearDist, compileTypescript, moveRemaining))
task('watch', () => { task('watch', () => {
watch('**/*.ts', runEslint); runEslint()
watch('**/*.ts', compileTypescript); compileTypescript()
watch(['src/**/*', '!src/**/*.ts'], moveRemaining()); watch('**/*.ts', runEslint)
watch('**/*.ts', compileTypescript)
// watch(['src/**/*', '!src/**/*.ts'], moveRemaining());
nodemon({ nodemon({
script: 'dist/index.js', script: 'dist/index.js',
watch: ['dist/**/*.js'], watch: ['dist/**/*.js'],
ext: 'js' ext: 'js'
}); })
}); })
task('watchnolint', () => { task('watchnolint', () => {
watch('**/*.ts', compileTypescript); watch('**/*.ts', compileTypescript)
watch(['src/**/*', '!src/**/*.ts'], moveRemaining()); // watch(['src/**/*', '!src/**/*.ts'], moveRemaining());
nodemon({ nodemon({
script: 'dist/index.js', script: 'dist/index.js',
watch: ['dist/**/*.js'], watch: ['dist/**/*.js'],
ext: 'js' ext: 'js'
}); })
}); })

@ -0,0 +1,12 @@
{
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "apollo",
"database": "apollo_test",
"synchronize": true,
"logging": false,
"entities": [
"dist/model/**/*.js"
]
}

721
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -12,6 +12,7 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"@types/node": "^14.10.0",
"@typescript-eslint/eslint-plugin": "^4.1.0", "@typescript-eslint/eslint-plugin": "^4.1.0",
"@typescript-eslint/parser": "^4.1.0", "@typescript-eslint/parser": "^4.1.0",
"delete": "^1.1.0", "delete": "^1.1.0",
@ -28,7 +29,12 @@
"typescript": "^4.0.2" "typescript": "^4.0.2"
}, },
"dependencies": { "dependencies": {
"@types/bluebird": "^3.5.32",
"@types/validator": "^13.1.0",
"apollo-server": "^2.17.0", "apollo-server": "^2.17.0",
"graphql": "^15.3.0" "graphql": "^15.3.0",
"pg": "^8.3.3",
"reflect-metadata": "^0.1.13",
"typeorm": "^0.2.26"
} }
} }

@ -1,20 +1,16 @@
import { DataSource } from 'apollo-datasource'; import { DataSource } from 'apollo-datasource'
/** /**
* extended datasource to feed resolvers with data about cargoBikes * extended datasource to feed resolvers with data about cargoBikes
*/ */
export class CargoBikeAPI extends DataSource { export class CargoBikeAPI extends DataSource {
constructor() {
super();
// this.store = store;
}
/** /**
* Finds cargo bike by id * Finds cargo bike by id
*/ */
async findCargoBikeById({ id }:{id: any}){ async findCargoBikeById ({ id, token }:{id: any, token:string}) {
return { return {
id, id,
name: "hello world" name: token
}; }
} }
} }

@ -0,0 +1,17 @@
/*
import {Sequelize} from 'sequelize-typescript';
export class DButils {
dbclient: any;
constructor(){
this.dbclient = new Sequelize({
database: 'apollo',
dialect: 'postgres',
username: 'postgres',
password: 'apollo',
storage: ':memory:',
models: [__dirname + '/models'], // or [Player, Team],
});
}
}
*/

@ -1,17 +1,13 @@
import { DataSource} from 'apollo-datasource'; import { DataSource } from 'apollo-datasource'
/** /**
* fetches datafrom user server, especially validates user tokens * fetches datafrom user server, especially validates user tokens
*/ */
export class UserServerAPI extends DataSource{ export class UserServerAPI extends DataSource {
constructor() {
super();
}
/** /**
* validates user token * validates user token
*/ */
async validateToken(token:string){ async validateToken (token:string) {
return true; return true
} }
} }

@ -1,16 +1,22 @@
import { ApolloServer } from 'apollo-server'; import { ApolloServer } from 'apollo-server'
import bikeresolver from './resolvers/cargobikeResolver'; import bikeresolver from './resolvers/cargobikeResolver'
import { CargoBikeAPI } from './datasources/db/cargobikeAPI'; import { CargoBikeAPI } from './datasources/db/cargobikeAPI'
import typeDefs from './schema/type-defs'; import typeDefs from './schema/type-defs'
import 'reflect-metadata'
import { createConnection } from 'typeorm'
createConnection().then(async () => {
console.log('connected to db')
}).catch(error => console.log(error))
const server = new ApolloServer({ const server = new ApolloServer({
resolvers:[bikeresolver], resolvers: [bikeresolver],
typeDefs, typeDefs,
dataSources: () => ({ dataSources: () => ({
cargoBikeAPI: new CargoBikeAPI(), cargoBikeAPI: new CargoBikeAPI()
}) })
}); })
console.log(__dirname)
server.listen() server.listen()
.then(({ url }) => console.log(`Server ready at ${url} `)); .then(({ url }) => console.log(`Server ready at ${url} `))

@ -0,0 +1,13 @@
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'
@Entity()
export class CargoBike {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@Column()
description: string;
}

@ -1,6 +1,6 @@
export default { export default {
Query: { Query: {
cargobike: (_: any,{ id }:{id: any},{dataSources}:{dataSources: any}) => cargobike: (_: any, { id, token }:{id: any, token: string}, { dataSources }:{dataSources: any}) =>
dataSources.cargoBikeAPI.findCargoBikeById( { id } ) dataSources.cargoBikeAPI.findCargoBikeById({ id, token })
}, }
}; }

@ -1,4 +1,4 @@
import { gql } from 'apollo-server'; import { gql } from 'apollo-server'
export default gql` export default gql`
@ -32,7 +32,7 @@ type CargoBike {
events: [BikeEvent] events: [BikeEvent]
equipment: [Equipment] equipment: [Equipment]
"Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2" "Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2"
otherEquipment: [String] otherEquipment: String
chainSwaps: [ChainSwap] chainSwaps: [ChainSwap]
"Sticker State" "Sticker State"
stickerBikeNameState: StickerBikeNameState stickerBikeNameState: StickerBikeNameState
@ -75,6 +75,7 @@ type BikeModel {
name: String name: String
dimensionsAndLoad: DimensionsAndLoad! dimensionsAndLoad: DimensionsAndLoad!
} }
type ActiveMentor { type ActiveMentor {
id: ID! id: ID!
start: Date! start: Date!
@ -254,8 +255,19 @@ type Organisation{
"registration number of association" "registration number of association"
associationNo: String associationNo: String
} }
type Query { type Query {
cargobike(token:String!,id:ID!): CargoBike cargobike(token:String!,id:ID!): CargoBike
} }
`; type UpdateBikeResponse {
success: Boolean
message: String
bike: CargoBike
}
"for testing"
type Mutation {
addBike(id: ID!):UpdateBikeResponse
}
`

@ -10,7 +10,9 @@
"allowJs": true, "allowJs": true,
"moduleResolution": "node", "moduleResolution": "node",
"module": "commonjs", "module": "commonjs",
"esModuleInterop": true "esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}, },
"include": [ "include": [
"src/**/*" "src/**/*"

Loading…
Cancel
Save