Skip to content

Commit aa3b700

Browse files
author
hirsch88
committed
Merge branch 'release/1.2.0'
2 parents f17ddcf + e2f8ed7 commit aa3b700

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+790
-562
lines changed

.env.example

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#
2+
# APPLICATION
3+
#
4+
APP_NAME=express-typescript-boilerplate
5+
APP_ENV=local
6+
APP_HOST=http://localhost
7+
APP_PORT=3000
8+
9+
#
10+
# LOGGING
11+
#
12+
DEBUG=app*,api*,core*
13+
LOG_LEVEL=debug
14+
LOG_ADAPTER=debug
15+
16+
#
17+
# DATABASE
18+
#
19+
# MySql
20+
DB_CLIENT=mysql
21+
DB_CONNECTION=mysql://root@localhost:3306/my_database
22+
23+
# PostGres
24+
#DB_CLIENT=pg
25+
#DB_CONNECTION=postgres://root:root@localhost:5432/my_database
26+
27+
# Knex
28+
DB_POOL_MIN=0
29+
DB_POOL_MAX=7
30+
DB_MIGRATION_DIR=./src/database/migrations
31+
DB_MIGRATION_TABLE=version
32+
DB_SEEDS_DIR=./src/database/seeds
33+
34+
#
35+
# Auth0
36+
#
37+
AUTH0_HOST=https://w3tecch.auth0.com
38+
AUTH0_OAUTH=/oauth
39+
AUTH0_API=/api/v2
40+
AUTH0_CLIENT_ID=auth0_client_id
41+
AUTH0_CLIENT_SECRET=auth0_client_secret
42+
AUTH0_AUDIENCE=https://my.auth0.com/api/v2/
43+
AUTH0_GRANT_TYPE=client_credentials

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ node_modules/
1010
bower_components/
1111
npm-debug.log
1212
yarn-error.log
13+
.env
1314

1415
# OS generated files #
1516
.DS_Store

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"typescript.tsdk": "./node_modules/typescript/lib",
33
"files.exclude": {
4-
"src/**/*.js": true,
4+
"src/**/*.js": false,
55
"test/**/*.js": true
66
},
77
"vsicons.presets.angular": false,

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ The port will be displayed to you as `http://0.0.0.0:3000` (or if you prefer IPv
5050
* Run `npm run build` to generated all JavaScript files from your TypeScript sources. After this step you can deploy the app on any server.
5151
* There is also a vscode task for this called build.
5252
* To start the builded app use `npm start`.
53-
* With `npm run zip` it will generate the JavaScript source and pack them into to a deployable zip file into the dist folder.
54-
55-
### Docs
56-
* Run `npm run docs` to generate all doc files and serve it on `http://0.0.0.0:8080`
5753

5854
### Seed
5955
* Run `npm run db:seed` to seed some data into the database
@@ -67,8 +63,13 @@ The port will be displayed to you as `http://0.0.0.0:3000` (or if you prefer IPv
6763
* [aurelia-typescript-boilerplate](https://github.com/w3tecch/aurelia-typescript-boilerplate) - An Aurelia starter kit with TypeScript
6864

6965
## Documentations
70-
* [Auth0 API Documentation](https://auth0.com/docs/api/management/v2#!/Users/get_users)
66+
* [Express](https://expressjs.com/)
67+
* [Knex](http://knexjs.org/)
68+
* [Bookshelf](http://bookshelfjs.org/)
7169
* [Bookshelf Cheatsheet](http://ricostacruz.com/cheatsheets/bookshelf.html)
70+
* [Inversify](http://inversify.io/)
71+
* [Inversify Express Utils](https://github.com/inversify/inversify-express-utils)
72+
* [Auth0 API Documentation](https://auth0.com/docs/api/management/v2#!/Users/get_users)
7273

7374
## License
7475
[MIT](/LICENSE)

build/tasks/zip.js

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

gulpfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
'use strict';
2+
23
var requireDir = require('require-dir');
34
var tasks = requireDir('./build/tasks');

knexfile.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import * as _ from 'lodash';
2-
3-
const config = require('./src/config');
4-
5-
let databaseConfig = {};
6-
7-
_.forOwn(_.clone(config), (value, key) => databaseConfig[`${key}`] = value.database);
8-
9-
module.exports = databaseConfig;
1+
require('dotenv').config();
2+
3+
module.exports = {
4+
client: process.env.DB_CLIENT,
5+
connection: process.env.DB_CONNECTION,
6+
migrations: {
7+
directory: process.env.DB_MIGRATION_DIR,
8+
tableName: process.env.DB_MIGRATION_TABLE
9+
},
10+
seeds: {
11+
directory: process.env.DB_SEEDS_DIR
12+
}
13+
};

package.json

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "express-typescript-boilerplate",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "Boilerplate for an restful express-application written in TypeScript.",
55
"main": "src/index.ts",
66
"scripts": {
@@ -14,13 +14,9 @@
1414
"build": "./node_modules/.bin/gulp build",
1515
"clean": "./node_modules/.bin/gulp clean",
1616
"zip": "./node_modules/.bin/gulp zip",
17-
"docs": "npm run docs:generate && npm run docs:server",
18-
"docs:generate": "./node_modules/.bin/gulp docs",
19-
"docs:server": "./node_modules/.bin/http-server ./docs --cors",
2017
"db:migrate": "./node_modules/.bin/knex migrate:latest",
2118
"db:migrate:rollback": "./node_modules/.bin/knex migrate:rollback",
2219
"db:seed": "./node_modules/.bin/knex seed:run",
23-
"db:clean": "./node_modules/.bin/ts-node ./src/console/CleanDatabaseCommand.ts",
2420
"db:refresh": "npm run db:drop && npm run db:migrate",
2521
"start": "node src/index.js"
2622
},
@@ -57,11 +53,13 @@
5753
"@types/bookshelf": "^0.8.38",
5854
"@types/cors": "^2.8.1",
5955
"@types/debug": "0.0.29",
56+
"@types/dotenv": "^4.0.0",
6057
"@types/express": "^4.0.35",
6158
"@types/faker": "^4.1.0",
6259
"@types/helmet": "0.0.34",
6360
"@types/inversify": "^2.0.33",
6461
"@types/inversify-express-utils": "^2.0.0",
62+
"@types/jest": "^19.2.2",
6563
"@types/knex": "0.0.47",
6664
"@types/lodash": "^4.14.63",
6765
"@types/morgan": "^1.7.32",
@@ -72,25 +70,13 @@
7270
"body-parser": "^1.17.1",
7371
"bookshelf": "^0.10.3",
7472
"bookshelf-camelcase": "^1.1.4",
73+
"class-validator": "^0.7.0",
7574
"compression": "^1.6.2",
7675
"cors": "^2.8.1",
7776
"debug": "^2.6.0",
77+
"dotenv": "^4.0.0",
7878
"express": "^4.14.0",
7979
"faker": "^3.1.0",
80-
"helmet": "^3.4.0",
81-
"inversify": "^4.1.0",
82-
"inversify-express-utils": "^3.5.1",
83-
"knex": "^0.12.7",
84-
"lodash": "^4.17.4",
85-
"morgan": "^1.7.0",
86-
"pg": "^6.1.5",
87-
"reflect-metadata": "^0.1.10",
88-
"request": "^2.81.0",
89-
"serve-favicon": "^2.4.2",
90-
"ts-node": "^2.0.0",
91-
"typescript": "^2.3.2",
92-
"winston": "^2.3.1",
93-
"@types/jest": "^19.2.2",
9480
"gulp": "^3.9.1",
9581
"gulp-clean": "^0.3.2",
9682
"gulp-concat": "^2.6.1",
@@ -106,20 +92,30 @@
10692
"gulp-typedoc": "^2.0.2",
10793
"gulp-typescript": "^3.1.4",
10894
"gulp-zip": "^3.2.0",
95+
"helmet": "^3.4.0",
10996
"http-server": "^0.9.0",
97+
"inversify": "^4.1.0",
98+
"inversify-express-utils": "^3.5.1",
11099
"jasmine-spec-reporter": "^4.0.0",
111100
"jest": "^19.0.2",
101+
"knex": "^0.12.7",
102+
"lodash": "^4.17.4",
103+
"morgan": "^1.7.0",
112104
"nodemon": "^1.11.0",
113105
"path": "^0.12.7",
106+
"pg": "^6.1.5",
107+
"reflect-metadata": "^0.1.10",
114108
"request": "^2.79.0",
115109
"require-dir": "^0.3.1",
116110
"run-sequence": "^1.2.2",
111+
"serve-favicon": "^2.4.2",
117112
"sqlite3": "^3.1.8",
118113
"ts-jest": "^19.0.11",
114+
"ts-node": "^2.0.0",
119115
"tslint": "^4.3.1",
120-
"typedoc": "^0.5.5",
121116
"typescript": "^2.2.1",
122-
"typings": "^2.1.0"
117+
"typings": "^2.1.0",
118+
"winston": "^2.3.1"
123119
},
124120
"jest": {
125121
"transform": {

src/api/controllers/HomeController.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@ import * as express from 'express';
22
import { Controller, Get, Response } from 'inversify-express-utils';
33
import { injectable } from 'inversify';
44

5+
/**
6+
* HomeController is a public controller to give some
7+
* information about this api
8+
*
9+
* @export
10+
* @class HomeController
11+
*/
512
@injectable()
613
@Controller('/')
714
export class HomeController {
815

916
@Get('/')
10-
public get(@Response() res: express.Response): any {
17+
public get( @Response() res: express.Response): any {
1118
const pkg = require('../../../package.json');
1219
return res.json({
1320
name: pkg.name,
Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,58 @@
11
import { injectable, inject } from 'inversify';
2-
import { Controller, Get, RequestParam } from 'inversify-express-utils';
3-
import TYPES from '../../constants/types';
4-
import * as core from '../../core';
5-
import { UserService } from '../services';
2+
import { Controller, Get, Post, Put, Delete, RequestParam, RequestBody, Response } from 'inversify-express-utils';
3+
import { my } from 'my-express';
4+
import { Log } from '../../core/log';
5+
import { UserService } from '../services/UsersService';
6+
import { Types } from '../../constants/Types';
67

7-
const log = new core.Log('api:ctrl.UserController');
8+
const log = new Log('api:ctrl.UserController');
89

910
/**
10-
* UserController
11+
* UserController is in charge of the user resource and should
12+
* provide all crud actions.
1113
*
1214
* @export
1315
* @class UserController
1416
*/
1517
@injectable()
16-
@Controller('/users')
18+
@Controller('/v1/user')
1719
export class UserController {
1820

19-
constructor( @inject(TYPES.UserService) private userService: UserService) { }
21+
constructor( @inject(Types.UserService) private userService: UserService) { }
2022

2123
@Get('/')
22-
public async findAll(): Promise<any> {
24+
public async findAll( @Response() res: my.Response): Promise<any> {
2325
log.debug('findAll');
2426
const users = await this.userService.findAll();
25-
return users.toJSON();
27+
return res.found(users.toJSON());
2628
}
2729

2830
@Get('/:id')
29-
public async findOne( @RequestParam('id') id: string): Promise<any> {
31+
public async findOne( @Response() res: my.Response, @RequestParam('id') id: string): Promise<any> {
3032
log.debug('findOne ', id);
3133
const user = await this.userService.findOne(parseInt(id, 10));
32-
return user.toJSON();
34+
return res.found(user.toJSON());
35+
}
36+
37+
@Post('/')
38+
public async create( @Response() res: my.Response, @RequestBody() body: any): Promise<any> {
39+
log.debug('create ', body);
40+
const user = await this.userService.create(body);
41+
return res.created(user.toJSON());
42+
}
43+
44+
@Put('/:id')
45+
public async update( @Response() res: my.Response, @RequestParam('id') id: string, @RequestBody() body: any): Promise<any> {
46+
log.debug('update ', body);
47+
const user = await this.userService.update(parseInt(id, 10), body);
48+
return res.updated(user.toJSON());
49+
}
50+
51+
@Delete('/:id')
52+
public async destroy( @Response() res: my.Response, @RequestParam('id') id: string): Promise<any> {
53+
log.debug('destroy ', id);
54+
await this.userService.destroy(parseInt(id, 10));
55+
return res.destroyed();
3356
}
3457

3558
}

0 commit comments

Comments
 (0)