This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = (sequelize, DataType) => { | |
let Category = sequelize.define('Category', { | |
name: { | |
type: DataType.STRING(100), | |
allowNull: false | |
}, | |
description: { | |
type: DataType.TEXT, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = { up, down }; | |
function up (db) { | |
const User = require('../src/shared/user/model')(db.sequelize, db.Sequelize); | |
return User.sync(); | |
}; | |
function down (db) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('lolololo'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getToken (user) { | |
const secretKey = process.env.JWT || ‘stubJWT’; | |
return jwt.sign({ id: user._id, roles: user.roles }, secretKey, {expiresIn: ‘18h’}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const Controller = require('../controllers/todo'); | |
const Validator = require('../validators/todo'); | |
exports.register = (server, options, next) => { | |
// instantiate controller | |
const controller = new Controller(options.database); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const jwt = require('jsonwebtoken'); | |
const Boom = require('boom'); | |
function UserController (db) { | |
this.database = db; | |
this.model = db.User; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const Promise = require('bluebird'); | |
const jwt = require('hapi-auth-jwt2'); | |
const db = require('./database'); | |
exports.register = (server, options, next) => { | |
server.register(jwt, registerAuth); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
function TodoController (db) { | |
this.database = db; | |
this.model = db.Todo; | |
} | |
TodoController.prototype = { | |
get, | |
create |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const Controller = require('../controllers/todo'); | |
exports.register = (server, options, next) => { | |
// instantiate controller | |
const controller = new Controller(options.database); | |
server.bind(controller); | |
server.route([ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global describe, beforeEach, before, it, expect, db, server */ | |
'use strict'; | |
describe('Routes /todo', () => { | |
let token; | |
before((done) => { | |
let options = { | |
method: 'POST', | |
url: '/user', | |
payload: { |