Skip to content

Commit 065243f

Browse files
author
Gery Hirschfeld
authored
Merge pull request #96 from w3tecch/feature/auth_and_typeorm_config
Feature/auth and typeorm config
2 parents 98a342e + 5d9e259 commit 065243f

31 files changed

+747
-759
lines changed

.env.example

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ LOG_LEVEL=debug
1515
LOG_JSON=false
1616
LOG_OUTPUT=dev
1717

18-
#
19-
# AUTHORIZATION
20-
#
21-
AUTH_ROUTE=http://localhost:3333/tokeninfo
22-
2318
#
2419
# DATABASE
2520
#
@@ -30,20 +25,22 @@ TYPEORM_USERNAME=root
3025
TYPEORM_PASSWORD=
3126
TYPEORM_DATABASE=my_database
3227
TYPEORM_SYNCHRONIZE=false
33-
TYPEORM_LOGGING=false
28+
TYPEORM_LOGGING=error
29+
TYPEORM_LOGGER=advanced-console
3430

3531
#
36-
# Additional settings (optional as defaults are in env.ts)
37-
#
38-
# TYPEORM_MIGRATIONS=
39-
# TYPEORM_MIGRATIONS_DIR=
40-
# TYPEORM_ENTITIES=
41-
# TYPEORM_SUBSCRIBERS=
42-
# CONTROLLERS=
43-
# MIDDLEWARES=
44-
# INTERCEPTORS=
45-
# QUERIES=
46-
# MUTATIONS=
32+
# PATH STRUCTRUE
33+
#
34+
TYPEORM_MIGRATIONS=src/database/migrations/**/*.ts
35+
TYPEORM_MIGRATIONS_DIR=src/database/migrations
36+
TYPEORM_ENTITIES=src/api/models/**/*.ts
37+
TYPEORM_ENTITIES_DIR=src/api/models
38+
CONTROLLERS=src/api/controllers/**/*Controller.ts
39+
MIDDLEWARES=src/api/middlewares/**/*Middleware.ts
40+
INTERCEPTORS=src/api/interceptors/**/*Interceptor.ts
41+
SUBSCRIBERS=src/api/subscribers/**/*Subscriber.ts
42+
QUERIES=src/api/queries/**/*Query.ts
43+
MUTATIONS=src/api/mutations/**/*Mutation.ts
4744

4845
#
4946
# GraphQL

.env.test

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,27 @@ LOG_LEVEL=none
1515
LOG_JSON=false
1616
LOG_OUTPUT=dev
1717

18-
#
19-
# AUTHORIZATION
20-
#
21-
AUTH_ROUTE=http://localhost:3333/tokeninfo
22-
2318
#
2419
# DATABASE
2520
#
2621
TYPEORM_CONNECTION=sqlite
2722
TYPEORM_DATABASE=./mydb.sql
28-
TYPEORM_LOGGING=false
23+
TYPEORM_LOGGING=error
24+
TYPEORM_LOGGER=advanced-console
25+
26+
#
27+
# PATH STRUCTRUE
28+
#
29+
TYPEORM_MIGRATIONS=src/database/migrations/**/*.ts
30+
TYPEORM_MIGRATIONS_DIR=src/database/migrations
31+
TYPEORM_ENTITIES=src/api/models/**/*.ts
32+
TYPEORM_ENTITIES_DIR=src/api/models
33+
CONTROLLERS=src/api/controllers/**/*Controller.ts
34+
MIDDLEWARES=src/api/middlewares/**/*Middleware.ts
35+
INTERCEPTORS=src/api/interceptors/**/*Interceptor.ts
36+
SUBSCRIBERS=src/api/subscribers/**/*Subscriber.ts
37+
QUERIES=src/api/queries/**/*Query.ts
38+
MUTATIONS=src/api/mutations/**/*Mutation.ts
2939

3040
#
3141
# GraphQL

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ typings/
2020

2121
# Dist #
2222
dist/
23-
ormconfig.json
2423
tsconfig.build.json
2524

2625
# IDE #

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
],
1616
"protocol": "inspector",
1717
"env": {
18-
"NODE_ENV": "development"
18+
"NODE_ENV": "production"
1919
}
2020
}
2121
]

.vscode/settings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"cSpell.enabled": true,
44
"files.exclude": {
55
"tsconfig.build.json": true,
6-
"ormconfig.json": true
76
},
87
"importSorter.generalConfiguration.sortOnBeforeSave": true,
98
"files.trimTrailingWhitespace": true,

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ The swagger and the monitor route can be altered in the `.env` file.
228228
| **test/unit/** *.test.ts | Unit tests |
229229
| .env.example | Environment configurations |
230230
| .env.test | Test environment configurations |
231-
| ormconfig.json | TypeORM configuration for the database. Used by seeds and the migration. (generated file) |
232231
| mydb.sql | SQLite database for integration tests. Ignored by git and only available after integration tests |
233232

234233
![divider](./w3tec-divider.png)
@@ -390,7 +389,6 @@ npm start db.seed
390389
| `npm start "db.seed -L"` | Log database queries to the terminal |
391390
| `npm start "db.seed --factories <path>"` | Add a different path to your factories (Default: `src/database/`) |
392391
| `npm start "db.seed --seeds <path>"` | Add a different path to your seeds (Default: `src/database/seeds/`) |
393-
| `npm start "db.seed --config <file>"` | Path to your ormconfig.json file |
394392
395393
![divider](./w3tec-divider.png)
396394

commands/ormconfig.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

package-scripts.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
* Starts the builded app from the dist directory
1212
*/
1313
start: {
14-
script: 'node dist/app.js',
14+
script: 'cross-env NODE_ENV=production node dist/app.js',
1515
description: 'Starts the builded app from the dist directory'
1616
},
1717
/**
@@ -30,9 +30,7 @@ module.exports = {
3030
setup: {
3131
script: series(
3232
'yarn install',
33-
'nps db.drop',
34-
'nps db.migrate',
35-
'nps db.seed'
33+
'nps db.setup',
3634
),
3735
description: 'Setup`s the development environment(yarn & database)'
3836
},
@@ -42,7 +40,6 @@ module.exports = {
4240
config: {
4341
script: series(
4442
runFast('./commands/tsconfig.ts'),
45-
runFast('./commands/ormconfig.ts')
4643
),
4744
hiddenFromHelp: true
4845
},
@@ -147,8 +144,15 @@ module.exports = {
147144
drop: {
148145
script: runFast('./node_modules/typeorm/cli.js schema:drop'),
149146
description: 'Drops the schema of the database'
147+
},
148+
setup: {
149+
script: series(
150+
'nps db.drop',
151+
'nps db.migrate',
152+
'nps db.seed'
153+
),
154+
description: 'Recreates the database with seeded data'
150155
}
151-
152156
},
153157
/**
154158
* These run various kinds of tests. Default is unit.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
}
3939
],
4040
"dependencies": {
41+
"@types/bcrypt": "^2.0.0",
4142
"@types/bluebird": "^3.5.18",
4243
"@types/body-parser": "^1.16.7",
4344
"@types/chalk": "^2.2.0",
@@ -55,6 +56,7 @@
5556
"@types/supertest": "^2.0.4",
5657
"@types/uuid": "^3.4.3",
5758
"@types/winston": "^2.3.7",
59+
"bcrypt": "^2.0.1",
5860
"body-parser": "^1.18.2",
5961
"chalk": "^2.3.0",
6062
"class-validator": "^0.8.5",
@@ -92,7 +94,7 @@
9294
"ts-node": "^6.0.0",
9395
"tslint": "^5.8.0",
9496
"typedi": "^0.7.2",
95-
"typeorm": "^0.2.1",
97+
"typeorm": "^0.2.5",
9698
"typeorm-typedi-extensions": "^0.2.1",
9799
"typescript": "2.8.3",
98100
"uuid": "^3.1.0",

src/api/controllers/PetController.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ export class PetController {
2121

2222
@Get('/:id')
2323
@OnUndefined(PetNotFoundError)
24-
public one( @Param('id') id: string): Promise<Pet | undefined> {
24+
public one(@Param('id') id: string): Promise<Pet | undefined> {
2525
return this.petService.findOne(id);
2626
}
2727

2828
@Post()
29-
public create( @Body() pet: Pet): Promise<Pet> {
29+
public create(@Body() pet: Pet): Promise<Pet> {
3030
return this.petService.create(pet);
3131
}
3232

3333
@Put('/:id')
34-
public update( @Param('id') id: string, @Body() pet: Pet): Promise<Pet> {
34+
public update(@Param('id') id: string, @Body() pet: Pet): Promise<Pet> {
3535
return this.petService.update(id, pet);
3636
}
3737

3838
@Delete('/:id')
39-
public delete( @Param('id') id: string): Promise<void> {
39+
public delete(@Param('id') id: string): Promise<void> {
4040
return this.petService.delete(id);
4141
}
4242

0 commit comments

Comments
 (0)