Skip to content

Commit 9d7be1c

Browse files
author
hirsch88
committed
house cleaning
1 parent 82cad2a commit 9d7be1c

File tree

24 files changed

+121
-101
lines changed

24 files changed

+121
-101
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ The port will be displayed to you as `http://0.0.0.0:3000` (or if you prefer IPv
5151
* There is also a vscode task for this called build.
5252
* To start the builded app use `npm start`.
5353

54-
### Docs
55-
* Run `npm run docs` to generate all doc files and serve it on `http://0.0.0.0:8080`
56-
5754
### Seed
5855
* Run `npm run db:seed` to seed some data into the database
5956

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');

package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
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",
@@ -116,7 +113,6 @@
116113
"ts-jest": "^19.0.11",
117114
"ts-node": "^2.0.0",
118115
"tslint": "^4.3.1",
119-
"typedoc": "^0.5.5",
120116
"typescript": "^2.2.1",
121117
"typings": "^2.1.0",
122118
"winston": "^2.3.1"

src/api/controllers/UserController.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { injectable, inject } from 'inversify';
22
import { Controller, Get, Post, Put, Delete, RequestParam, RequestBody, Response } from 'inversify-express-utils';
33
import { my } from 'my-express';
4-
import { Log } from '../../core';
4+
import { Log } from '../../core/log';
55
import { UserService } from '../services';
6-
import TYPES from '../../constants/types';
6+
import { Types } from '../../constants/Types';
77

88
const log = new Log('api:ctrl.UserController');
99

@@ -17,7 +17,7 @@ const log = new Log('api:ctrl.UserController');
1717
@Controller('/v1/user')
1818
export class UserController {
1919

20-
constructor( @inject(TYPES.UserService) private userService: UserService) { }
20+
constructor( @inject(Types.UserService) private userService: UserService) { }
2121

2222
@Get('/')
2323
public async findAll( @Response() res: my.Response): Promise<any> {

src/api/middlewares/index.ts

Whitespace-only changes.

src/api/models/User.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as core from '../../core';
2-
import { Tables } from '../../database/Tables';
1+
import { Bookshelf } from '../../core/Bookshelf';
2+
import { Tables } from '../../constants/Tables';
33

44

5-
export class User extends core.Bookshelf.Model<User> {
5+
export class User extends Bookshelf.Model<User> {
66

77
public static async fetchById(id: number): Promise<User> {
88
return await User.where<User>({ id: id }).fetch();

src/api/services/UsersService.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { injectable, inject, named } from 'inversify';
21
import * as Bookshelf from 'bookshelf';
3-
import * as core from '../../core';
4-
import * as models from '../models';
5-
import * as repo from '../repositories';
2+
import { injectable, inject, named } from 'inversify';
3+
import { Repository } from '../../constants/Targets';
4+
import { Types } from '../../constants/Types';
5+
import { Log } from '../../core/log';
66
import { NotFoundException } from '../exceptions';
7-
import TYPES from '../../constants/types';
8-
import TAGS from '../../constants/tags';
97
import { UserCreateRequest } from '../request/UserCreateRequest';
108
import { UserUpdateRequest } from '../request/UserUpdateRequest';
9+
import { UserRepository } from '../repositories';
10+
import { User } from '../models';
1111

12-
const log = new core.Log('api:services:UserService');
12+
const log = new Log('api:services:UserService');
1313

1414
/**
1515
* UserService
@@ -21,15 +21,15 @@ const log = new core.Log('api:services:UserService');
2121
export class UserService {
2222

2323
constructor(
24-
@inject(TYPES.UserRepository) @named(TAGS.UserRepository) public userRepo: typeof repo.UserRepository
24+
@inject(Types.UserRepository) @named(Repository.UserRepository) public userRepo: typeof UserRepository
2525
) {
2626
}
2727

28-
public async findAll(): Promise<Bookshelf.Collection<models.User>> {
28+
public async findAll(): Promise<Bookshelf.Collection<User>> {
2929
return this.userRepo.findAll();
3030
}
3131

32-
public async findOne(id: number): Promise<models.User> {
32+
public async findOne(id: number): Promise<User> {
3333
let user = await this.userRepo.findOne(id);
3434
if (user === null) {
3535
log.warn(`User with the id=${id} was not found!`);
@@ -38,7 +38,7 @@ export class UserService {
3838
return user;
3939
}
4040

41-
public async create(data: any): Promise<models.User> {
41+
public async create(data: any): Promise<User> {
4242
// Validate request payload
4343
const request = new UserCreateRequest(data);
4444
await request.validate();
@@ -48,7 +48,7 @@ export class UserService {
4848
return user;
4949
}
5050

51-
public async update(id: number, newUser: any): Promise<models.User> {
51+
public async update(id: number, newUser: any): Promise<User> {
5252
const oldUserModel = await this.findOne(id);
5353
let oldUser = oldUserModel.toJSON();
5454
const request = new UserUpdateRequest(oldUser);

src/app.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import * as express from 'express';
66
import * as favicon from 'serve-favicon';
77
import * as bodyParser from 'body-parser';
88
import * as compression from 'compression';
9-
import * as core from './core';
9+
import { Bootstrap } from './core/Bootstrap';
10+
import { Log } from './core/log';
1011
import container from './container';
1112

1213
/**
@@ -15,34 +16,41 @@ import container from './container';
1516
* This is the place to add any other express module and register
1617
* all your custom middlewares and routes
1718
*/
18-
const app = core.Bootstrap.getApp()
19+
const app = Bootstrap.getApp()
20+
1921
// Enabling the cors headers
2022
.options('*', cors())
2123
.use(cors())
24+
2225
// Helmet helps you secure your Express apps by setting various HTTP headers. It's not a silver bullet, but it can help!
2326
.use(helmet())
2427
.use(helmet.noCache())
2528
.use(helmet.hsts({
2629
maxAge: 31536000,
2730
includeSubdomains: true
2831
}))
32+
2933
// Compress response bodies for all request that traverse through the middleware
3034
.use(compression())
35+
3136
// Parse incoming request bodies in a middleware before your handlers, available under the req.body property.
3237
.use(bodyParser.json())
3338
.use(bodyParser.urlencoded({
3439
extended: true
3540
}))
41+
3642
// Serve static filles like images from the public folder
3743
.use(express.static(`${__dirname}/public`))
44+
3845
// A favicon is a visual cue that client software, like browsers, use to identify a site
3946
.use(favicon(path.join(__dirname, 'public', 'favicon.ico')))
47+
4048
// HTTP request logger middleware for node.js
4149
.use(morgan('dev', {
4250
stream: {
43-
write: core.Log.info
51+
write: Log.info
4452
}
4553
}));
4654

4755

48-
export default core.Bootstrap.build(app, container);
56+
export default Bootstrap.build(app, container);

src/constants/Tables.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const Tables = {
2+
Users: 'users'
3+
};

src/constants/Targets.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const Controller = {
2+
HomeController: 'HomeController',
3+
UserController: 'UserController'
4+
};
5+
6+
export const Repository = {
7+
UserRepository: 'UserRepository'
8+
};

0 commit comments

Comments
 (0)