Implemented ESlint and passed down the rules
This commit is contained in:
@@ -1,6 +1,3 @@
|
|||||||
// MODULES
|
|
||||||
const fs = require('fs');
|
|
||||||
|
|
||||||
// Setting up the database connection
|
// Setting up the database connection
|
||||||
const knex = require('knex')({
|
const knex = require('knex')({
|
||||||
client: "mysql",
|
client: "mysql",
|
||||||
|
|||||||
@@ -1,35 +1,35 @@
|
|||||||
const regexInt = RegExp(/^[1-9]\d*$/)
|
const regexInt = RegExp(/^[1-9]\d*$/);
|
||||||
const regexXSS = RegExp(/<[^>]*script/)
|
const regexXSS = RegExp(/<[^>]*script/);
|
||||||
|
|
||||||
// Check if int for param validation
|
// Check if int for param validation
|
||||||
const paramIntCheck = (req, res, next, input) => {
|
const paramIntCheck = (req, res, next, input) => {
|
||||||
try {
|
try {
|
||||||
if (regexInt.test(input)) {
|
if (regexInt.test(input)) {
|
||||||
next()
|
next();
|
||||||
} else {
|
} else {
|
||||||
throw new Error
|
throw new Error;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
res.status(err.code).send(JSON.stringify({
|
res.status(err.code).send(JSON.stringify({
|
||||||
"message": "Le paramètre doit être un entier non-nul.",
|
"message": "Le paramètre doit être un entier non-nul.",
|
||||||
"code": 403,
|
"code": 403,
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// Check if script injection attempt
|
// Check if script injection attempt
|
||||||
const isXSSAttempt = (string) => {
|
const isXSSAttempt = (string) => {
|
||||||
return regexXSS.test(string);
|
return regexXSS.test(string);
|
||||||
}
|
};
|
||||||
|
|
||||||
// Check if object is null
|
// Check if object is null
|
||||||
const isEmptyObject = (obj) => {
|
const isEmptyObject = (obj) => {
|
||||||
return (Object.keys(obj).length === 0 && obj.constructor === Object);
|
return (Object.keys(obj).length === 0 && obj.constructor === Object);
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
paramIntCheck,
|
paramIntCheck,
|
||||||
isXSSAttempt,
|
isXSSAttempt,
|
||||||
isEmptyObject
|
isEmptyObject
|
||||||
}
|
};
|
||||||
@@ -6,11 +6,10 @@ const bodyParser = require('body-parser');
|
|||||||
const helmet = require('helmet');
|
const helmet = require('helmet');
|
||||||
const morgan = require('morgan');
|
const morgan = require('morgan');
|
||||||
const cors = require('cors'); // module to format the json response
|
const cors = require('cors'); // module to format the json response
|
||||||
const dotenv = require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
|
||||||
// CONSTANTS
|
// CONSTANTS
|
||||||
const port = 2814;
|
const port = 2814;
|
||||||
const base_url = 'http://localhost:2814/api';
|
|
||||||
|
|
||||||
// Import routes
|
// Import routes
|
||||||
const routes = require('./routes');
|
const routes = require('./routes');
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
'use strict'
|
|
||||||
const bookshelf = require('../database/bookshelf').bookshelf;
|
const bookshelf = require('../database/bookshelf').bookshelf;
|
||||||
|
|
||||||
require('./user-model');
|
require('./user-model');
|
||||||
@@ -9,6 +8,6 @@ let APIToken = bookshelf.Model.extend({
|
|||||||
user() {
|
user() {
|
||||||
return this.belongsTo('User', 'user_uuid', 'uuid');
|
return this.belongsTo('User', 'user_uuid', 'uuid');
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
module.exports = bookshelf.model('APIToken', APIToken);
|
module.exports = bookshelf.model('APIToken', APIToken);
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
'use strict'
|
const bookshelf = require('../database/bookshelf').bookshelf;
|
||||||
const bookshelf = require('../database/bookshelf').bookshelf
|
|
||||||
|
|
||||||
require('./spell-model')
|
require('./spell-model');
|
||||||
|
|
||||||
let Ingredient = bookshelf.Model.extend({
|
let Ingredient = bookshelf.Model.extend({
|
||||||
tableName: 'ingredient',
|
tableName: 'ingredient',
|
||||||
spells() {
|
spells() {
|
||||||
return this.belongsToMany('Spell', 'spell_ingredient')
|
return this.belongsToMany('Spell', 'spell_ingredient');
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
module.exports = bookshelf.model('Ingredient', Ingredient)
|
module.exports = bookshelf.model('Ingredient', Ingredient);
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
'use strict'
|
const bookshelf = require('../database/bookshelf').bookshelf;
|
||||||
const bookshelf = require('../database/bookshelf').bookshelf
|
|
||||||
|
|
||||||
require('./school-model')
|
require('./school-model');
|
||||||
|
|
||||||
let MetaSchool = bookshelf.Model.extend({
|
let MetaSchool = bookshelf.Model.extend({
|
||||||
tableName: 'meta_school',
|
tableName: 'meta_school',
|
||||||
schools() {
|
schools() {
|
||||||
return this.hasMany('School')
|
return this.hasMany('School');
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
module.exports = bookshelf.model('MetaSchool', MetaSchool)
|
module.exports = bookshelf.model('MetaSchool', MetaSchool);
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
const bookshelf = require('../database/bookshelf').bookshelf
|
const bookshelf = require('../database/bookshelf').bookshelf;
|
||||||
|
|
||||||
require('./role-model')
|
require('./role-model');
|
||||||
|
|
||||||
let Permission = bookshelf.Model.extend({
|
let Permission = bookshelf.Model.extend({
|
||||||
tableName: 'permission',
|
tableName: 'permission',
|
||||||
hidden: ['id'],
|
hidden: ['id'],
|
||||||
role() {
|
role() {
|
||||||
return this.belongsToMany('Role', 'role_permission')
|
return this.belongsToMany('Role', 'role_permission');
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
module.exports = bookshelf.model('Permission', Permission);
|
module.exports = bookshelf.model('Permission', Permission);
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
const bookshelf = require('../database/bookshelf').bookshelf
|
const bookshelf = require('../database/bookshelf').bookshelf;
|
||||||
|
|
||||||
require('./permission-model')
|
require('./permission-model');
|
||||||
|
|
||||||
let Role = bookshelf.Model.extend({
|
let Role = bookshelf.Model.extend({
|
||||||
tableName: 'role',
|
tableName: 'role',
|
||||||
permissions() {
|
permissions() {
|
||||||
return this.belongsToMany('Permission', 'role_permission');
|
return this.belongsToMany('Permission', 'role_permission');
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
module.exports = bookshelf.model('Role', Role);
|
module.exports = bookshelf.model('Role', Role);
|
||||||
@@ -1,17 +1,16 @@
|
|||||||
'use strict'
|
const bookshelf = require('../database/bookshelf').bookshelf;
|
||||||
const bookshelf = require('../database/bookshelf').bookshelf
|
|
||||||
|
|
||||||
require('./spell-model')
|
require('./spell-model');
|
||||||
require('./meta-school-model')
|
require('./meta-school-model');
|
||||||
|
|
||||||
let School = bookshelf.Model.extend({
|
let School = bookshelf.Model.extend({
|
||||||
tableName: 'school',
|
tableName: 'school',
|
||||||
spells() {
|
spells() {
|
||||||
return this.belongsToMany('Spell', 'spell_school')
|
return this.belongsToMany('Spell', 'spell_school');
|
||||||
},
|
},
|
||||||
meta_schools() {
|
meta_schools() {
|
||||||
return this.belongsTo('MetaSchool', 'meta_school_id')
|
return this.belongsTo('MetaSchool', 'meta_school_id');
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
module.exports = bookshelf.model('School', School)
|
module.exports = bookshelf.model('School', School);
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
'use strict'
|
const bookshelf = require('../database/bookshelf').bookshelf;
|
||||||
const bookshelf = require('../database/bookshelf').bookshelf
|
|
||||||
|
|
||||||
require('./school-model')
|
require('./school-model');
|
||||||
require('./variable-model')
|
require('./variable-model');
|
||||||
require('./ingredient-model')
|
require('./ingredient-model');
|
||||||
|
|
||||||
let Spell = bookshelf.Model.extend({
|
let Spell = bookshelf.Model.extend({
|
||||||
tableName: 'spell',
|
tableName: 'spell',
|
||||||
@@ -20,6 +19,6 @@ let Spell = bookshelf.Model.extend({
|
|||||||
ingredients() {
|
ingredients() {
|
||||||
return this.belongsToMany( 'Ingredient', 'spell_ingredient' );
|
return this.belongsToMany( 'Ingredient', 'spell_ingredient' );
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
module.exports = bookshelf.model('Spell', Spell)
|
module.exports = bookshelf.model('Spell', Spell);
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
'use strict'
|
|
||||||
const bookshelf = require('../database/bookshelf').bookshelf;
|
const bookshelf = require('../database/bookshelf').bookshelf;
|
||||||
|
|
||||||
require('./role-model');
|
require('./role-model');
|
||||||
@@ -13,6 +12,6 @@ let User = bookshelf.Model.extend({
|
|||||||
spells() {
|
spells() {
|
||||||
return this.hasMany('Spell', 'author_id');
|
return this.hasMany('Spell', 'author_id');
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
module.exports = bookshelf.model('User', User)
|
module.exports = bookshelf.model('User', User);
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
'use strict'
|
const bookshelf = require('../database/bookshelf').bookshelf;
|
||||||
const bookshelf = require('../database/bookshelf').bookshelf
|
|
||||||
|
|
||||||
require('./spell-model')
|
require('./spell-model');
|
||||||
|
|
||||||
let Variable = bookshelf.Model.extend({
|
let Variable = bookshelf.Model.extend({
|
||||||
tableName: 'variable',
|
tableName: 'variable',
|
||||||
spells() {
|
spells() {
|
||||||
return this.belongsToMany('Spell', 'spell_variable')
|
return this.belongsToMany('Spell', 'spell_variable');
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
module.exports = bookshelf.model('Variable', Variable)
|
module.exports = bookshelf.model('Variable', Variable);
|
||||||
1527
api/package-lock.json
generated
1527
api/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -40,5 +40,34 @@
|
|||||||
"mysql": "^2.18.1",
|
"mysql": "^2.18.1",
|
||||||
"nodemailer": "^6.4.17",
|
"nodemailer": "^6.4.17",
|
||||||
"uuid": "^8.2.0"
|
"uuid": "^8.2.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"babel-eslint": "^10.1.0",
|
||||||
|
"eslint": "^7.18.0",
|
||||||
|
"eslint-plugin-import": "^2.22.1"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"env": {
|
||||||
|
"es6": true,
|
||||||
|
"browser": true
|
||||||
|
},
|
||||||
|
"parser": "babel-eslint",
|
||||||
|
"rules": {
|
||||||
|
"accessor-pairs": "warn",
|
||||||
|
"array-callback-return": "error",
|
||||||
|
"brace-style": "warn",
|
||||||
|
"consistent-return": "error",
|
||||||
|
"default-case": "error",
|
||||||
|
"eqeqeq": "warn",
|
||||||
|
"no-case-declarations": "error",
|
||||||
|
"no-empty-pattern": "warn",
|
||||||
|
"no-fallthrough": "error",
|
||||||
|
"no-unused-vars": "error",
|
||||||
|
"no-useless-catch": "error",
|
||||||
|
"no-var": "error",
|
||||||
|
"semi": "warn",
|
||||||
|
"no-extra-semi": "error",
|
||||||
|
"yoda": "warn"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
'use strict'
|
|
||||||
// Bookshelf
|
// Bookshelf
|
||||||
const bookshelf = require('../database/bookshelf').bookshelf
|
const bookshelf = require('../database/bookshelf').bookshelf;
|
||||||
const model = require('../models/ingredient-model')
|
const model = require('../models/ingredient-model');
|
||||||
|
|
||||||
// Model validation
|
// Model validation
|
||||||
const Validator = require('jsonschema').Validator
|
const Validator = require('jsonschema').Validator;
|
||||||
const validator = new Validator()
|
const validator = new Validator();
|
||||||
const IngredientValidation = require("../validations/IngredientValidation")
|
const IngredientValidation = require("../validations/IngredientValidation");
|
||||||
validator.addSchema(IngredientValidation, "/IngredientValidation")
|
validator.addSchema(IngredientValidation, "/IngredientValidation");
|
||||||
|
|
||||||
// Validations
|
// Validations
|
||||||
const isXSSAttempt = require('../functions').isXSSAttempt
|
const isXSSAttempt = require('../functions').isXSSAttempt;
|
||||||
const isEmptyObject = require('../functions').isEmptyObject
|
const isEmptyObject = require('../functions').isEmptyObject;
|
||||||
|
|
||||||
class IngredientRepository {
|
class IngredientRepository {
|
||||||
|
|
||||||
@@ -23,16 +22,16 @@ class IngredientRepository {
|
|||||||
new model()
|
new model()
|
||||||
.fetchAll({ withRelated: ['spells'] })
|
.fetchAll({ withRelated: ['spells'] })
|
||||||
.then(v => {
|
.then(v => {
|
||||||
resolve(v.toJSON({ omitPivot: true }))
|
resolve(v.toJSON({ omitPivot: true }));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
reject({
|
reject({
|
||||||
"message": "Il n'existe aucun ingrédient disponible.",
|
"message": "Il n'existe aucun ingrédient disponible.",
|
||||||
"code": 404,
|
"code": 404,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -42,16 +41,16 @@ class IngredientRepository {
|
|||||||
.where({ 'id': id })
|
.where({ 'id': id })
|
||||||
.fetch({ withRelated: ['spells'] })
|
.fetch({ withRelated: ['spells'] })
|
||||||
.then(v => {
|
.then(v => {
|
||||||
resolve(v.toJSON({ omitPivot: true }))
|
resolve(v.toJSON({ omitPivot: true }));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
reject({
|
reject({
|
||||||
"message": "L'ingrédient en question n'a pas pu être trouvé.",
|
"message": "L'ingrédient en question n'a pas pu être trouvé.",
|
||||||
"code": 404,
|
"code": 404,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getSpellsFromOne(id) {
|
getSpellsFromOne(id) {
|
||||||
@@ -60,16 +59,16 @@ class IngredientRepository {
|
|||||||
.where({ 'id': id })
|
.where({ 'id': id })
|
||||||
.fetch({ withRelated: ['spells', 'spells.schools', 'spells.variables', 'spells.ingredients', 'spells.schools.meta_schools'] })
|
.fetch({ withRelated: ['spells', 'spells.schools', 'spells.variables', 'spells.ingredients', 'spells.schools.meta_schools'] })
|
||||||
.then(v => {
|
.then(v => {
|
||||||
resolve(v.toJSON({ omitPivot: true }))
|
resolve(v.toJSON({ omitPivot: true }));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
reject({
|
reject({
|
||||||
"message": "Les sortilèges liés à cet ingrédient n'ont pas pu être récupérés.",
|
"message": "Les sortilèges liés à cet ingrédient n'ont pas pu être récupérés.",
|
||||||
"code": 404,
|
"code": 404,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addOne(igr) {
|
addOne(igr) {
|
||||||
@@ -99,24 +98,24 @@ class IngredientRepository {
|
|||||||
transacting: t
|
transacting: t
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.then(v => {
|
.then(v => {
|
||||||
return v.load(['spells'])
|
return v.load(['spells']);
|
||||||
})
|
})
|
||||||
.then(v => {
|
.then(v => {
|
||||||
resolve(this.getOne(v.id))
|
resolve(this.getOne(v.id));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
reject({
|
reject({
|
||||||
"message": "Une erreur d'insertion s'est produite.",
|
"message": "Une erreur d'insertion s'est produite.",
|
||||||
"code": 500,
|
"code": 500,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updateOne(id, igr) {
|
updateOne(id, igr) {
|
||||||
@@ -150,33 +149,33 @@ class IngredientRepository {
|
|||||||
transacting: t
|
transacting: t
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.then(v => {
|
.then(v => {
|
||||||
return v.load(['spells'])
|
return v.load(['spells']);
|
||||||
})
|
})
|
||||||
.then(v => {
|
.then(v => {
|
||||||
resolve(this.getOne(v.id))
|
resolve(this.getOne(v.id));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
reject({
|
reject({
|
||||||
"message": "Une erreur d'insertion s'est produite.",
|
"message": "Une erreur d'insertion s'est produite.",
|
||||||
"code": 500,
|
"code": 500,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
reject({
|
reject({
|
||||||
"message": "L'ingrédient en question n'a pas été trouvé.",
|
"message": "L'ingrédient en question n'a pas été trouvé.",
|
||||||
"code": 404,
|
"code": 404,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteOne(id) {
|
deleteOne(id) {
|
||||||
@@ -185,23 +184,23 @@ class IngredientRepository {
|
|||||||
.where({ 'id': id })
|
.where({ 'id': id })
|
||||||
.fetch({ require: true, withRelated: ['spells'] })
|
.fetch({ require: true, withRelated: ['spells'] })
|
||||||
.then(v => {
|
.then(v => {
|
||||||
v.spells().detach()
|
v.spells().detach();
|
||||||
v.destroy()
|
v.destroy();
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
resolve({
|
resolve({
|
||||||
'message': 'Ingredient with ID ' + id + ' successfully deleted !'
|
'message': 'Ingredient with ID ' + id + ' successfully deleted !'
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
reject({
|
reject({
|
||||||
"message": "L'ingrédient en question n'a pas été trouvé.",
|
"message": "L'ingrédient en question n'a pas été trouvé.",
|
||||||
"code": 404,
|
"code": 404,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = IngredientRepository
|
module.exports = IngredientRepository;
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
'use strict'
|
|
||||||
// Bookshelf
|
// Bookshelf
|
||||||
const bookshelf = require('../database/bookshelf').bookshelf
|
|
||||||
const model = require('../models/meta-school-model')
|
const model = require('../models/meta-school-model')
|
||||||
|
|
||||||
// Model validation
|
// Model validation
|
||||||
@@ -9,9 +7,6 @@ const validator = new Validator()
|
|||||||
const MetaSchoolValidation = require("../validations/MetaSchoolValidation")
|
const MetaSchoolValidation = require("../validations/MetaSchoolValidation")
|
||||||
validator.addSchema(MetaSchoolValidation, "/MetaSchoolValidation")
|
validator.addSchema(MetaSchoolValidation, "/MetaSchoolValidation")
|
||||||
|
|
||||||
// Validations
|
|
||||||
const regexXSS = RegExp(/<[^>]*script/)
|
|
||||||
|
|
||||||
class MetaSchoolRepository {
|
class MetaSchoolRepository {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -28,7 +23,7 @@ class MetaSchoolRepository {
|
|||||||
console.log(err)
|
console.log(err)
|
||||||
reject({
|
reject({
|
||||||
"message": "Il n'existe aucune grande école disponible.",
|
"message": "Il n'existe aucune grande école disponible.",
|
||||||
"code": 404,
|
"code": 404
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -46,7 +41,7 @@ class MetaSchoolRepository {
|
|||||||
console.log(err)
|
console.log(err)
|
||||||
reject({
|
reject({
|
||||||
"message": "La grande école en question n'a pas pu être trouvée.",
|
"message": "La grande école en question n'a pas pu être trouvée.",
|
||||||
"code": 404,
|
"code": 404
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
'use strict'
|
|
||||||
// Bookshelf
|
// Bookshelf
|
||||||
const bookshelf = require('../database/bookshelf').bookshelf
|
const bookshelf = require('../database/bookshelf').bookshelf;
|
||||||
const model = require('../models/school-model')
|
const model = require('../models/school-model');
|
||||||
|
|
||||||
// Model validation
|
// Model validation
|
||||||
const Validator = require('jsonschema').Validator
|
const Validator = require('jsonschema').Validator;
|
||||||
const validator = new Validator()
|
const validator = new Validator();
|
||||||
const SchoolValidation = require("../validations/SchoolValidation")
|
const SchoolValidation = require("../validations/SchoolValidation");
|
||||||
validator.addSchema(SchoolValidation, "/SchoolValidation")
|
validator.addSchema(SchoolValidation, "/SchoolValidation");
|
||||||
|
|
||||||
// Validations
|
// Validations
|
||||||
const isXSSAttempt = require('../functions').isXSSAttempt
|
const isXSSAttempt = require('../functions').isXSSAttempt;
|
||||||
const isEmptyObject = require('../functions').isEmptyObject
|
const isEmptyObject = require('../functions').isEmptyObject;
|
||||||
|
|
||||||
class SchoolRepository {
|
class SchoolRepository {
|
||||||
|
|
||||||
@@ -23,7 +22,7 @@ class SchoolRepository {
|
|||||||
new model()
|
new model()
|
||||||
.fetchAll({ withRelated: ['meta_schools'] })
|
.fetchAll({ withRelated: ['meta_schools'] })
|
||||||
.then(v => {
|
.then(v => {
|
||||||
resolve(v.toJSON({ omitPivot: true }))
|
resolve(v.toJSON({ omitPivot: true }));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@@ -31,8 +30,8 @@ class SchoolRepository {
|
|||||||
"message": "Il n'existe aucune école disponible.",
|
"message": "Il n'existe aucune école disponible.",
|
||||||
"code": 404,
|
"code": 404,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getOne(id) {
|
getOne(id) {
|
||||||
@@ -41,7 +40,7 @@ class SchoolRepository {
|
|||||||
.where({ 'id': id })
|
.where({ 'id': id })
|
||||||
.fetch({ withRelated: ['meta_schools'] })
|
.fetch({ withRelated: ['meta_schools'] })
|
||||||
.then(v => {
|
.then(v => {
|
||||||
resolve(v.toJSON({ omitPivot: true }))
|
resolve(v.toJSON({ omitPivot: true }));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@@ -49,8 +48,8 @@ class SchoolRepository {
|
|||||||
"message": "L'école en question n'a pas pu être trouvée.",
|
"message": "L'école en question n'a pas pu être trouvée.",
|
||||||
"code": 404,
|
"code": 404,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getSpellsFromOne(id) {
|
getSpellsFromOne(id) {
|
||||||
@@ -59,7 +58,7 @@ class SchoolRepository {
|
|||||||
.where({ 'id': id })
|
.where({ 'id': id })
|
||||||
.fetch({ withRelated: ['spells', 'spells.schools', 'spells.variables', 'spells.ingredients', 'spells.schools.meta_schools'] })
|
.fetch({ withRelated: ['spells', 'spells.schools', 'spells.variables', 'spells.ingredients', 'spells.schools.meta_schools'] })
|
||||||
.then(v => {
|
.then(v => {
|
||||||
resolve(v.toJSON({ omitPivot: true }))
|
resolve(v.toJSON({ omitPivot: true }));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@@ -67,8 +66,8 @@ class SchoolRepository {
|
|||||||
"message": "Les sortilèges de cette école n'ont pas pu être récupérés.",
|
"message": "Les sortilèges de cette école n'ont pas pu être récupérés.",
|
||||||
"code": 404,
|
"code": 404,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addOne(s) {
|
addOne(s) {
|
||||||
@@ -99,8 +98,8 @@ class SchoolRepository {
|
|||||||
transacting: t
|
transacting: t
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.then(v => {
|
.then(v => {
|
||||||
return v.load(['meta_schools']);
|
return v.load(['meta_schools']);
|
||||||
@@ -109,14 +108,14 @@ class SchoolRepository {
|
|||||||
resolve(this.getOne(v.id));
|
resolve(this.getOne(v.id));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
reject({
|
reject({
|
||||||
"message": "Une erreur d'insertion s'est produite.",
|
"message": "Une erreur d'insertion s'est produite.",
|
||||||
"code": 500,
|
"code": 500,
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updateOne(id, s) {
|
updateOne(id, s) {
|
||||||
@@ -151,23 +150,23 @@ class SchoolRepository {
|
|||||||
transacting: t
|
transacting: t
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.then(v => {
|
.then(v => {
|
||||||
return v.load(['meta_schools'])
|
return v.load(['meta_schools']);
|
||||||
})
|
})
|
||||||
.then(v => {
|
.then(v => {
|
||||||
resolve(this.getOne(v.id))
|
resolve(this.getOne(v.id));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
reject({
|
reject({
|
||||||
"message": "Une erreur d'insertion s'est produite.",
|
"message": "Une erreur d'insertion s'est produite.",
|
||||||
"code": 500,
|
"code": 500,
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@@ -175,9 +174,9 @@ class SchoolRepository {
|
|||||||
"message": "L'école en question n'a pas été trouvée.",
|
"message": "L'école en question n'a pas été trouvée.",
|
||||||
"code": 404,
|
"code": 404,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteOne(id) {
|
deleteOne(id) {
|
||||||
@@ -186,13 +185,13 @@ class SchoolRepository {
|
|||||||
.where({ 'id': id })
|
.where({ 'id': id })
|
||||||
.fetch({ require: true, withRelated: ['spells', 'meta_schools'] })
|
.fetch({ require: true, withRelated: ['spells', 'meta_schools'] })
|
||||||
.then(v => {
|
.then(v => {
|
||||||
v.spells().detach()
|
v.spells().detach();
|
||||||
v.destroy()
|
v.destroy();
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
resolve({
|
resolve({
|
||||||
'message': 'School with ID ' + id + ' successfully deleted !'
|
'message': 'School with ID ' + id + ' successfully deleted !'
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@@ -200,9 +199,9 @@ class SchoolRepository {
|
|||||||
"message": "L'école en question n'a pas été trouvée.",
|
"message": "L'école en question n'a pas été trouvée.",
|
||||||
"code": 404,
|
"code": 404,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = SchoolRepository
|
module.exports = SchoolRepository;
|
||||||
@@ -23,12 +23,24 @@ class SpellRepository {
|
|||||||
|
|
||||||
let query = new model();
|
let query = new model();
|
||||||
|
|
||||||
if (name) { query.where('name', 'like', `%${name}%`) }
|
if (name) {
|
||||||
if (description) { query.where('description', 'like', `%${description}%`) }
|
query.where('name', 'like', `%${name}%`)
|
||||||
if (level) { query.where({ 'level': level }) }
|
}
|
||||||
if (charge) { query.where({ 'charge': charge }) }
|
if (description) {
|
||||||
if (cost) { query.where({ 'cost': cost }) }
|
query.where('description', 'like', `%${description}%`)
|
||||||
if (ritual) { query.where({ 'is_ritual': ritual }) }
|
}
|
||||||
|
if (level) {
|
||||||
|
query.where({ 'level': level })
|
||||||
|
}
|
||||||
|
if (charge) {
|
||||||
|
query.where({ 'charge': charge })
|
||||||
|
}
|
||||||
|
if (cost) {
|
||||||
|
query.where({ 'cost': cost })
|
||||||
|
}
|
||||||
|
if (ritual) {
|
||||||
|
query.where({ 'is_ritual': ritual })
|
||||||
|
}
|
||||||
|
|
||||||
query.fetchAll({ withRelated: ['schools.meta_schools', 'variables', 'ingredients', 'author'] })
|
query.fetchAll({ withRelated: ['schools.meta_schools', 'variables', 'ingredients', 'author'] })
|
||||||
.then(v => {
|
.then(v => {
|
||||||
@@ -49,12 +61,24 @@ class SpellRepository {
|
|||||||
|
|
||||||
let query = new model().where({ 'public': 1 })
|
let query = new model().where({ 'public': 1 })
|
||||||
|
|
||||||
if (name) { query.where('name', 'like', `%${name}%`) }
|
if (name) {
|
||||||
if (description) { query.where('description', 'like', `%${description}%`) }
|
query.where('name', 'like', `%${name}%`)
|
||||||
if (level) { query.where({ 'level': level }) }
|
}
|
||||||
if (charge) { query.where({ 'charge': charge }) }
|
if (description) {
|
||||||
if (cost) { query.where({ 'cost': cost }) }
|
query.where('description', 'like', `%${description}%`)
|
||||||
if (ritual) { query.where({ 'is_ritual': ritual }) }
|
}
|
||||||
|
if (level) {
|
||||||
|
query.where({ 'level': level })
|
||||||
|
}
|
||||||
|
if (charge) {
|
||||||
|
query.where({ 'charge': charge })
|
||||||
|
}
|
||||||
|
if (cost) {
|
||||||
|
query.where({ 'cost': cost })
|
||||||
|
}
|
||||||
|
if (ritual) {
|
||||||
|
query.where({ 'is_ritual': ritual })
|
||||||
|
}
|
||||||
|
|
||||||
query.fetchAll({ withRelated: ['schools.meta_schools', 'variables', 'ingredients', 'author'] })
|
query.fetchAll({ withRelated: ['schools.meta_schools', 'variables', 'ingredients', 'author'] })
|
||||||
.then(v => {
|
.then(v => {
|
||||||
@@ -226,18 +250,21 @@ class SpellRepository {
|
|||||||
let schools = spell.related('school');
|
let schools = spell.related('school');
|
||||||
return spell.schools().detach(schools, { transacting: t });
|
return spell.schools().detach(schools, { transacting: t });
|
||||||
}
|
}
|
||||||
|
return spell
|
||||||
})
|
})
|
||||||
.tap(spell => {
|
.tap(spell => {
|
||||||
if (s.variables) {
|
if (s.variables) {
|
||||||
let variables = spell.related('variable');
|
let variables = spell.related('variable');
|
||||||
return spell.variables().detach(variables, { transacting: t });
|
return spell.variables().detach(variables, { transacting: t });
|
||||||
}
|
}
|
||||||
|
return spell;
|
||||||
})
|
})
|
||||||
.tap(spell => {
|
.tap(spell => {
|
||||||
if (s.ingredients) {
|
if (s.ingredients) {
|
||||||
let ingredients = spell.related('ingredient');
|
let ingredients = spell.related('ingredient');
|
||||||
return spell.ingredients().detach(ingredients, { transacting: t });
|
return spell.ingredients().detach(ingredients, { transacting: t });
|
||||||
}
|
}
|
||||||
|
return spell;
|
||||||
})
|
})
|
||||||
.tap(spell => {
|
.tap(spell => {
|
||||||
return spell
|
return spell
|
||||||
|
|||||||
@@ -360,7 +360,7 @@ class UserRepository {
|
|||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
// If the account already has an API key linked...
|
// If the account already has an API key linked...
|
||||||
if (err.errno == 1062) {
|
if (err.errno === 1062) {
|
||||||
this.fetchAPIKey(user.uuid)
|
this.fetchAPIKey(user.uuid)
|
||||||
.then(old_api_key => {
|
.then(old_api_key => {
|
||||||
reject({
|
reject({
|
||||||
@@ -473,7 +473,7 @@ class UserRepository {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Unhandled errors
|
// Unhandled errors
|
||||||
.catch(err => {
|
.catch(() => {
|
||||||
reject({
|
reject({
|
||||||
"message": "Une erreur inconnue est survenue.",
|
"message": "Une erreur inconnue est survenue.",
|
||||||
"code": 500,
|
"code": 500,
|
||||||
@@ -541,7 +541,7 @@ class UserRepository {
|
|||||||
resolve(v.toJSON({ omitPivot: true }));
|
resolve(v.toJSON({ omitPivot: true }));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err);
|
reject(err);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
'use strict'
|
|
||||||
// Bookshelf
|
// Bookshelf
|
||||||
const bookshelf = require('../database/bookshelf').bookshelf
|
const bookshelf = require('../database/bookshelf').bookshelf;
|
||||||
const model = require('../models/variable-model')
|
const model = require('../models/variable-model');
|
||||||
|
|
||||||
// Model validation
|
// Model validation
|
||||||
const Validator = require('jsonschema').Validator
|
const Validator = require('jsonschema').Validator;
|
||||||
const validator = new Validator()
|
const validator = new Validator();
|
||||||
const VariableValidation = require("../validations/VariableValidation")
|
const VariableValidation = require("../validations/VariableValidation");
|
||||||
validator.addSchema(VariableValidation, "/VariableValidation")
|
validator.addSchema(VariableValidation, "/VariableValidation");
|
||||||
|
|
||||||
// Validations
|
// Validations
|
||||||
const isXSSAttempt = require('../functions').isXSSAttempt
|
const isXSSAttempt = require('../functions').isXSSAttempt;
|
||||||
const isEmptyObject = require('../functions').isEmptyObject
|
const isEmptyObject = require('../functions').isEmptyObject;
|
||||||
|
|
||||||
class VariableRepository {
|
class VariableRepository {
|
||||||
|
|
||||||
@@ -23,16 +22,16 @@ class VariableRepository {
|
|||||||
new model()
|
new model()
|
||||||
.fetchAll({ withRelated: ['spells'] })
|
.fetchAll({ withRelated: ['spells'] })
|
||||||
.then(v => {
|
.then(v => {
|
||||||
resolve(v.toJSON({ omitPivot: true }))
|
resolve(v.toJSON({ omitPivot: true }));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
reject({
|
reject({
|
||||||
"message": "Il n'existe aucune variable disponible.",
|
"message": "Il n'existe aucune variable disponible.",
|
||||||
"code": 404,
|
"code": 404,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -42,16 +41,16 @@ class VariableRepository {
|
|||||||
.where({ 'id': id })
|
.where({ 'id': id })
|
||||||
.fetch({ withRelated: ['spells'] })
|
.fetch({ withRelated: ['spells'] })
|
||||||
.then(v => {
|
.then(v => {
|
||||||
resolve(v.toJSON({ omitPivot: true }))
|
resolve(v.toJSON({ omitPivot: true }));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
reject({
|
reject({
|
||||||
"message": "La variable en question n'a pas pu être trouvée.",
|
"message": "La variable en question n'a pas pu être trouvée.",
|
||||||
"code": 404,
|
"code": 404,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getSpellsFromOne(id) {
|
getSpellsFromOne(id) {
|
||||||
@@ -60,16 +59,16 @@ class VariableRepository {
|
|||||||
.where({ 'id': id })
|
.where({ 'id': id })
|
||||||
.fetch({ withRelated: ['spells', 'spells.schools', 'spells.variables', 'spells.ingredients', 'spells.schools.meta_schools'] })
|
.fetch({ withRelated: ['spells', 'spells.schools', 'spells.variables', 'spells.ingredients', 'spells.schools.meta_schools'] })
|
||||||
.then(v => {
|
.then(v => {
|
||||||
resolve(v.toJSON({ omitPivot: true }))
|
resolve(v.toJSON({ omitPivot: true }));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
reject({
|
reject({
|
||||||
"message": "Les sortilèges liés à cette variable n'ont pas pu être récupérés.",
|
"message": "Les sortilèges liés à cette variable n'ont pas pu être récupérés.",
|
||||||
"code": 404,
|
"code": 404,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addOne(vr) {
|
addOne(vr) {
|
||||||
@@ -98,24 +97,24 @@ class VariableRepository {
|
|||||||
transacting: t
|
transacting: t
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.then(v => {
|
.then(v => {
|
||||||
return v.load(['spells'])
|
return v.load(['spells']);
|
||||||
})
|
})
|
||||||
.then(v => {
|
.then(v => {
|
||||||
resolve(this.getOne(v.id))
|
resolve(this.getOne(v.id));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
reject({
|
reject({
|
||||||
"message": "Une erreur d'insertion s'est produite.",
|
"message": "Une erreur d'insertion s'est produite.",
|
||||||
"code": 500,
|
"code": 500,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updateOne(id, vr) {
|
updateOne(id, vr) {
|
||||||
@@ -148,33 +147,33 @@ class VariableRepository {
|
|||||||
transacting: t
|
transacting: t
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.then(v => {
|
.then(v => {
|
||||||
return v.load(['spells'])
|
return v.load(['spells']);
|
||||||
})
|
})
|
||||||
.then(v => {
|
.then(v => {
|
||||||
resolve(this.getOne(v.id))
|
resolve(this.getOne(v.id));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
reject({
|
reject({
|
||||||
"message": "Une erreur d'insertion s'est produite.",
|
"message": "Une erreur d'insertion s'est produite.",
|
||||||
"code": 500,
|
"code": 500,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
reject({
|
reject({
|
||||||
"message": "La variable en question n'a pas été trouvée.",
|
"message": "La variable en question n'a pas été trouvée.",
|
||||||
"code": 404,
|
"code": 404,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteOne(id) {
|
deleteOne(id) {
|
||||||
@@ -183,23 +182,23 @@ class VariableRepository {
|
|||||||
.where({ 'id': id })
|
.where({ 'id': id })
|
||||||
.fetch({ require: true, withRelated: ['spells'] })
|
.fetch({ require: true, withRelated: ['spells'] })
|
||||||
.then(v => {
|
.then(v => {
|
||||||
v.spells().detach()
|
v.spells().detach();
|
||||||
v.destroy()
|
v.destroy();
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
resolve({
|
resolve({
|
||||||
'message': 'Variable with ID ' + id + ' successfully deleted !'
|
'message': 'Variable with ID ' + id + ' successfully deleted !'
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
reject({
|
reject({
|
||||||
"message": "La variable en question n'a pas été trouvée.",
|
"message": "La variable en question n'a pas été trouvée.",
|
||||||
"code": 404,
|
"code": 404,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = VariableRepository
|
module.exports = VariableRepository;
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
'use strict'
|
|
||||||
// Router
|
// Router
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
let router = express.Router();
|
let router = express.Router();
|
||||||
@@ -12,18 +11,18 @@ const Users = new UserRepository();
|
|||||||
const generateAPIToken = (mail, password) => {
|
const generateAPIToken = (mail, password) => {
|
||||||
return Users.genAPIToken(mail, password)
|
return Users.genAPIToken(mail, password)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get('/genToken', async (req, res) => {
|
router.get('/genToken', async (req, res) => {
|
||||||
generateAPIToken(req.body.mail, req.body.password)
|
generateAPIToken(req.body.mail, req.body.password)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(err))
|
res.status(err.code).send(JSON.stringify(err));
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
@@ -15,4 +15,4 @@ module.exports = {
|
|||||||
ingredients,
|
ingredients,
|
||||||
variables,
|
variables,
|
||||||
users,
|
users,
|
||||||
}
|
};
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
// Router
|
// Router
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
let router = express.Router();
|
let router = express.Router();
|
||||||
@@ -19,17 +17,17 @@ const functions = require('../functions');
|
|||||||
const getIngredients = () => {
|
const getIngredients = () => {
|
||||||
return Ingredients.getAll()
|
return Ingredients.getAll()
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get(
|
router.get(
|
||||||
'/',
|
'/',
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
getIngredients()
|
getIngredients()
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -37,26 +35,26 @@ router.get(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// GET ONE ------------------
|
// GET ONE ------------------
|
||||||
const getIngredient = (id) => {
|
const getIngredient = (id) => {
|
||||||
return Ingredients.getOne(id)
|
return Ingredients.getOne(id)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get(
|
router.get(
|
||||||
'/:id/',
|
'/:id/',
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
getIngredient(req.params.id)
|
getIngredient(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -64,26 +62,26 @@ router.get(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// GET SPELLS FROM ONE ------------------
|
// GET SPELLS FROM ONE ------------------
|
||||||
const getSpellsFromOne = (id) => {
|
const getSpellsFromOne = (id) => {
|
||||||
return Ingredients.getSpellsFromOne(id)
|
return Ingredients.getSpellsFromOne(id)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get(
|
router.get(
|
||||||
'/:id/spells',
|
'/:id/spells',
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
getSpellsFromOne(req.params.id)
|
getSpellsFromOne(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -91,27 +89,27 @@ router.get(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// CREATE ONE ------------------
|
// CREATE ONE ------------------
|
||||||
const addIngredient = (igr) => {
|
const addIngredient = (igr) => {
|
||||||
return Ingredients.addOne(igr)
|
return Ingredients.addOne(igr)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.post(
|
router.post(
|
||||||
'/',
|
'/',
|
||||||
authGuard(['SUBMIT_INGREDIENTS']),
|
authGuard(['SUBMIT_INGREDIENTS']),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
addIngredient(req.body)
|
addIngredient(req.body)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.send(JSON.stringify(v))
|
res.send(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -119,27 +117,27 @@ router.post(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// UPDATE ONE ------------------
|
// UPDATE ONE ------------------
|
||||||
const updateIngredient = (id, igr) => {
|
const updateIngredient = (id, igr) => {
|
||||||
return Ingredients.updateOne(id, igr)
|
return Ingredients.updateOne(id, igr)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.put(
|
router.put(
|
||||||
'/:id/',
|
'/:id/',
|
||||||
authGuard(['SUBMIT_INGREDIENTS', 'MODIFY_INGREDIENTS']),
|
authGuard(['SUBMIT_INGREDIENTS', 'MODIFY_INGREDIENTS']),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
updateIngredient(req.params.id, req.body)
|
updateIngredient(req.params.id, req.body)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.send(JSON.stringify(v))
|
res.send(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -147,27 +145,27 @@ router.put(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// DELETE ONE ------------------
|
// DELETE ONE ------------------
|
||||||
const deleteIngredient = (id) => {
|
const deleteIngredient = (id) => {
|
||||||
return Ingredients.deleteOne(id)
|
return Ingredients.deleteOne(id)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.delete(
|
router.delete(
|
||||||
'/:id/',
|
'/:id/',
|
||||||
authGuard(['SUBMIT_INGREDIENTS', 'MODIFY_INGREDIENTS', 'DELETE_INGREDIENTS']),
|
authGuard(['SUBMIT_INGREDIENTS', 'MODIFY_INGREDIENTS', 'DELETE_INGREDIENTS']),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
deleteIngredient(req.params.id)
|
deleteIngredient(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.send(JSON.stringify(v))
|
res.send(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -175,11 +173,11 @@ router.delete(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
// Param validations
|
// Param validations
|
||||||
router.param('id', functions.paramIntCheck)
|
router.param('id', functions.paramIntCheck);
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router;
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
// Router
|
// Router
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
let router = express.Router();
|
let router = express.Router();
|
||||||
@@ -16,15 +14,15 @@ const MetaSchools = new MetaSchoolRepository();
|
|||||||
const getMetaSchools = () => {
|
const getMetaSchools = () => {
|
||||||
return MetaSchools.getAll()
|
return MetaSchools.getAll()
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get('/', async (req, res) => {
|
router.get('/', async (req, res) => {
|
||||||
getMetaSchools()
|
getMetaSchools()
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -32,24 +30,24 @@ router.get('/', async (req, res) => {
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// GET ONE ------------------
|
// GET ONE ------------------
|
||||||
const getMetaSchool = (id) => {
|
const getMetaSchool = (id) => {
|
||||||
return MetaSchools.getOne(id)
|
return MetaSchools.getOne(id)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get('/:id/', async (req, res) => {
|
router.get('/:id/', async (req, res) => {
|
||||||
getMetaSchool(req.params.id)
|
getMetaSchool(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -57,11 +55,11 @@ router.get('/:id/', async (req, res) => {
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
// Param validations
|
// Param validations
|
||||||
router.param('id', functions.paramIntCheck)
|
router.param('id', functions.paramIntCheck);
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router;
|
||||||
@@ -11,13 +11,13 @@ const authGuard = (permissions) => {
|
|||||||
|
|
||||||
// Uses repo to validate the associated perms with the token
|
// Uses repo to validate the associated perms with the token
|
||||||
Users.checkAPITokenPerms(api_token, permissions)
|
Users.checkAPITokenPerms(api_token, permissions)
|
||||||
.then(v => {
|
.then(() => {
|
||||||
next();
|
next();
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(err))
|
res.status(err.code).send(JSON.stringify(err));
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = authGuard;
|
module.exports = authGuard;
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
// Router
|
// Router
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
let router = express.Router();
|
let router = express.Router();
|
||||||
@@ -19,17 +17,17 @@ const functions = require('../functions');
|
|||||||
const getSchools = () => {
|
const getSchools = () => {
|
||||||
return Schools.getAll()
|
return Schools.getAll()
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get(
|
router.get(
|
||||||
'/',
|
'/',
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
getSchools()
|
getSchools()
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -37,26 +35,26 @@ router.get(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// GET ONE ------------------
|
// GET ONE ------------------
|
||||||
const getSchool = (id) => {
|
const getSchool = (id) => {
|
||||||
return Schools.getOne(id)
|
return Schools.getOne(id)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get(
|
router.get(
|
||||||
'/:id/',
|
'/:id/',
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
getSchool(req.params.id)
|
getSchool(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -64,26 +62,26 @@ router.get(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// GET SPELLS FROM ONE ------------------
|
// GET SPELLS FROM ONE ------------------
|
||||||
const getSpellsFromOne = (id) => {
|
const getSpellsFromOne = (id) => {
|
||||||
return Schools.getSpellsFromOne(id)
|
return Schools.getSpellsFromOne(id)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get(
|
router.get(
|
||||||
'/:id/spells',
|
'/:id/spells',
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
getSpellsFromOne(req.params.id)
|
getSpellsFromOne(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -91,27 +89,27 @@ router.get(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// CREATE ONE ------------------
|
// CREATE ONE ------------------
|
||||||
const addSchool = (s) => {
|
const addSchool = (s) => {
|
||||||
return Schools.addOne(s)
|
return Schools.addOne(s)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.post(
|
router.post(
|
||||||
'/',
|
'/',
|
||||||
authGuard(['SUBMIT_SCHOOL']),
|
authGuard(['SUBMIT_SCHOOL']),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
addSchool(req.body)
|
addSchool(req.body)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.send(JSON.stringify(v))
|
res.send(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -119,26 +117,26 @@ router.post(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
// UPDATE ONE ------------------
|
// UPDATE ONE ------------------
|
||||||
const updateSchool = (id, s) => {
|
const updateSchool = (id, s) => {
|
||||||
return Schools.updateOne(id, s)
|
return Schools.updateOne(id, s)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.put(
|
router.put(
|
||||||
'/:id/',
|
'/:id/',
|
||||||
authGuard(['SUBMIT_SCHOOLS', 'MODIFY_SCHOOLS']),
|
authGuard(['SUBMIT_SCHOOLS', 'MODIFY_SCHOOLS']),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
updateSchool(req.params.id, req.body)
|
updateSchool(req.params.id, req.body)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.send(JSON.stringify(v))
|
res.send(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -146,27 +144,27 @@ router.put(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// DELETE ONE ------------------
|
// DELETE ONE ------------------
|
||||||
const deleteSchool = (id) => {
|
const deleteSchool = (id) => {
|
||||||
return Schools.deleteOne(id)
|
return Schools.deleteOne(id)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.delete(
|
router.delete(
|
||||||
'/:id/',
|
'/:id/',
|
||||||
authGuard(['SUBMIT_SCHOOLS', 'MODIFY_SCHOOLS', 'DELETE_SCHOOLS']),
|
authGuard(['SUBMIT_SCHOOLS', 'MODIFY_SCHOOLS', 'DELETE_SCHOOLS']),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
deleteSchool(req.params.id)
|
deleteSchool(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.send(JSON.stringify(v))
|
res.send(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -174,11 +172,11 @@ router.delete(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
// Param validations
|
// Param validations
|
||||||
router.param('id', functions.paramIntCheck)
|
router.param('id', functions.paramIntCheck);
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router;
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
// Router
|
// Router
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
let router = express.Router();
|
let router = express.Router();
|
||||||
@@ -19,17 +17,17 @@ const functions = require('../functions');
|
|||||||
const getPublicSpells = (name, description, level, charge, cost, ritual) => {
|
const getPublicSpells = (name, description, level, charge, cost, ritual) => {
|
||||||
return Spells.getAllPublic(name, description, level, charge, cost, ritual)
|
return Spells.getAllPublic(name, description, level, charge, cost, ritual)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get(
|
router.get(
|
||||||
'//:name?/:description?/:level?/:charge?/:cost?/:ritual?/',
|
'//:name?/:description?/:level?/:charge?/:cost?/:ritual?/',
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
getPublicSpells(req.query.name, req.query.description, req.query.level, req.query.charge, req.query.cost, req.query.ritual)
|
getPublicSpells(req.query.name, req.query.description, req.query.level, req.query.charge, req.query.cost, req.query.ritual)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -37,26 +35,26 @@ router.get(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
// GET ALL ------------------
|
// GET ALL ------------------
|
||||||
const getSpells = (name, description, level, charge, cost, ritual) => {
|
const getSpells = (name, description, level, charge, cost, ritual) => {
|
||||||
return Spells.getAll(name, description, level, charge, cost, ritual)
|
return Spells.getAll(name, description, level, charge, cost, ritual)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get(
|
router.get(
|
||||||
'/private/:name?/:description?/:level?/:charge?/:cost?/:ritual?/',
|
'/private/:name?/:description?/:level?/:charge?/:cost?/:ritual?/',
|
||||||
authGuard(['SECRET_SPELLS']),
|
authGuard(['SECRET_SPELLS']),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
getSpells(req.query.name, req.query.description, req.query.level, req.query.charge, req.query.cost, req.query.ritual)
|
getSpells(req.query.name, req.query.description, req.query.level, req.query.charge, req.query.cost, req.query.ritual)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -64,25 +62,25 @@ router.get(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
// GET SOME ------------------
|
// GET SOME ------------------
|
||||||
const getSomeSpells = (page) => {
|
const getSomeSpells = (page) => {
|
||||||
return Spells.getPage(page)
|
return Spells.getPage(page)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get(
|
router.get(
|
||||||
'/page/:page',
|
'/page/:page',
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
getSomeSpells(req.params.page)
|
getSomeSpells(req.params.page)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -90,25 +88,25 @@ router.get(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
// GET ONE ------------------
|
// GET ONE ------------------
|
||||||
const getSpell = (id) => {
|
const getSpell = (id) => {
|
||||||
return Spells.getOne(id)
|
return Spells.getOne(id)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get(
|
router.get(
|
||||||
'/:id/',
|
'/:id/',
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
getSpell(req.params.id)
|
getSpell(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -116,27 +114,27 @@ router.get(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// CREATE ONE ------------------
|
// CREATE ONE ------------------
|
||||||
const addSpell = (s) => {
|
const addSpell = (s) => {
|
||||||
return Spells.addOne(s)
|
return Spells.addOne(s)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.post(
|
router.post(
|
||||||
'/',
|
'/',
|
||||||
authGuard(['SUBMIT_SPELLS']),
|
authGuard(['SUBMIT_SPELLS']),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
addSpell(req.body)
|
addSpell(req.body)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.send(JSON.stringify(v))
|
res.send(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -144,27 +142,27 @@ router.post(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// UPDATE ONE ------------------
|
// UPDATE ONE ------------------
|
||||||
const updateSpell = (id, s) => {
|
const updateSpell = (id, s) => {
|
||||||
return Spells.updateOne(id, s)
|
return Spells.updateOne(id, s)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.put(
|
router.put(
|
||||||
'/:id/',
|
'/:id/',
|
||||||
authGuard(['SUBMIT_SPELLS', 'MODIFY_SPELLS']),
|
authGuard(['SUBMIT_SPELLS', 'MODIFY_SPELLS']),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
updateSpell(req.params.id, req.body)
|
updateSpell(req.params.id, req.body)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.send(JSON.stringify(v))
|
res.send(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -172,27 +170,27 @@ router.put(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// DELETE ONE ------------------
|
// DELETE ONE ------------------
|
||||||
const deleteSpell = (id) => {
|
const deleteSpell = (id) => {
|
||||||
return Spells.deleteOne(id)
|
return Spells.deleteOne(id)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.delete(
|
router.delete(
|
||||||
'/:id/',
|
'/:id/',
|
||||||
authGuard(['SUBMIT_SPELLS', 'MODIFY_SPELLS', 'DELETE_SPELLS']),
|
authGuard(['SUBMIT_SPELLS', 'MODIFY_SPELLS', 'DELETE_SPELLS']),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
deleteSpell(req.params.id)
|
deleteSpell(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.send(JSON.stringify(v))
|
res.send(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -200,12 +198,12 @@ router.delete(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
// Param validations
|
// Param validations
|
||||||
router.param('id', functions.paramIntCheck)
|
router.param('id', functions.paramIntCheck);
|
||||||
router.param('page', functions.paramIntCheck)
|
router.param('page', functions.paramIntCheck);
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router;
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
// Router
|
// Router
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
let router = express.Router();
|
let router = express.Router();
|
||||||
|
|
||||||
// AuthGuard
|
// AuthGuard
|
||||||
const authGuard = require('./middleware/authGuard');
|
// const authGuard = require('./middleware/authGuard');
|
||||||
|
|
||||||
// Repository
|
// Repository
|
||||||
const UserRepository = require('../repositories/user-repository');
|
const UserRepository = require('../repositories/user-repository');
|
||||||
@@ -16,14 +14,14 @@ const Users = new UserRepository();
|
|||||||
const getUsers = () => {
|
const getUsers = () => {
|
||||||
return Users.getAll()
|
return Users.getAll()
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get('/', async (req, res) => {
|
router.get('/', async (req, res) => {
|
||||||
getUsers()
|
getUsers()
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -31,23 +29,23 @@ router.get('/', async (req, res) => {
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// GET ONE FROM UUID ------------------
|
// GET ONE FROM UUID ------------------
|
||||||
const getUserByUUID = (uuid) => {
|
const getUserByUUID = (uuid) => {
|
||||||
return Users.getOneByUUID(uuid)
|
return Users.getOneByUUID(uuid)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get('/:uuid/', async (req, res) => {
|
router.get('/:uuid/', async (req, res) => {
|
||||||
getUserByUUID(req.params.uuid)
|
getUserByUUID(req.params.uuid)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -55,22 +53,22 @@ router.get('/:uuid/', async (req, res) => {
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
// GET SPELLS FROM ONE ------------------
|
// GET SPELLS FROM ONE ------------------
|
||||||
const getSpellsFromUser = (uuid) => {
|
const getSpellsFromUser = (uuid) => {
|
||||||
return Users.getSpellsFromOne(uuid)
|
return Users.getSpellsFromOne(uuid)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get('/:uuid/spells', async (req, res) => {
|
router.get('/:uuid/spells', async (req, res) => {
|
||||||
getSpellsFromUser(req.params.uuid)
|
getSpellsFromUser(req.params.uuid)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -78,23 +76,23 @@ router.get('/:uuid/spells', async (req, res) => {
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// CHECK IF MAIL IS AVAILABLE ------------------
|
// CHECK IF MAIL IS AVAILABLE ------------------
|
||||||
const checkIfEmailAvailable = (mail) => {
|
const checkIfEmailAvailable = (mail) => {
|
||||||
return Users.checkIfEmailAvailable(mail)
|
return Users.checkIfEmailAvailable(mail)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get('/available/:mail/', async (req, res) => {
|
router.get('/available/:mail/', async (req, res) => {
|
||||||
checkIfEmailAvailable(req.params.mail)
|
checkIfEmailAvailable(req.params.mail)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -102,23 +100,23 @@ router.get('/available/:mail/', async (req, res) => {
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// CREATE ONE ------------------
|
// CREATE ONE ------------------
|
||||||
const addUser = (u) => {
|
const addUser = (u) => {
|
||||||
return Users.addOne(u)
|
return Users.addOne(u)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.post('/', async (req, res) => {
|
router.post('/', async (req, res) => {
|
||||||
addUser(req.body)
|
addUser(req.body)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.send(JSON.stringify(v))
|
res.send(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -126,9 +124,9 @@ router.post('/', async (req, res) => {
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// VERIFY A USER
|
// VERIFY A USER
|
||||||
@@ -136,13 +134,13 @@ const verifyUser = (token) => {
|
|||||||
return Users.verifyUser(token)
|
return Users.verifyUser(token)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
throw err;
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get('/verification/:token', async (req, res) => {
|
router.get('/verification/:token', async (req, res) => {
|
||||||
verifyUser(req.params.token)
|
verifyUser(req.params.token)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.send(JSON.stringify(v))
|
res.send(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -150,22 +148,22 @@ router.get('/verification/:token', async (req, res) => {
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// LOG A USER ------------------
|
// LOG A USER ------------------
|
||||||
const logUser = (mail, password) => {
|
const logUser = (mail, password) => {
|
||||||
return Users.logUser(mail, password)
|
return Users.logUser(mail, password)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.post('/login', async (req, res) => {
|
router.post('/login', async (req, res) => {
|
||||||
logUser(req.body.mail, req.body.password)
|
logUser(req.body.mail, req.body.password)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -173,8 +171,8 @@ router.post('/login', async (req, res) => {
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
'use strict'
|
'use strict';
|
||||||
|
|
||||||
// Router
|
// Router
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
@@ -19,17 +19,17 @@ const functions = require('../functions');
|
|||||||
const getvariables = () => {
|
const getvariables = () => {
|
||||||
return Variables.getAll()
|
return Variables.getAll()
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get(
|
router.get(
|
||||||
'/',
|
'/',
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
getvariables()
|
getvariables()
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -37,26 +37,26 @@ router.get(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// GET ONE ------------------
|
// GET ONE ------------------
|
||||||
const getVariable = (id) => {
|
const getVariable = (id) => {
|
||||||
return Variables.getOne(id)
|
return Variables.getOne(id)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get(
|
router.get(
|
||||||
'/:id/',
|
'/:id/',
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
getVariable(req.params.id)
|
getVariable(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -64,26 +64,26 @@ router.get(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// GET SPELLS FROM ONE ------------------
|
// GET SPELLS FROM ONE ------------------
|
||||||
const getSpellsFromOne = (id) => {
|
const getSpellsFromOne = (id) => {
|
||||||
return Variables.getSpellsFromOne(id)
|
return Variables.getSpellsFromOne(id)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.get(
|
router.get(
|
||||||
'/:id/spells',
|
'/:id/spells',
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
getSpellsFromOne(req.params.id)
|
getSpellsFromOne(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.end(JSON.stringify(v))
|
res.end(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -91,27 +91,27 @@ router.get(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// CREATE ONE ------------------
|
// CREATE ONE ------------------
|
||||||
const addVariable = (vr) => {
|
const addVariable = (vr) => {
|
||||||
return Variables.addOne(vr)
|
return Variables.addOne(vr)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.post(
|
router.post(
|
||||||
'/',
|
'/',
|
||||||
authGuard(['SUBMIT_VARIABLES']),
|
authGuard(['SUBMIT_VARIABLES']),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
addVariable(req.body)
|
addVariable(req.body)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.send(JSON.stringify(v))
|
res.send(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -119,27 +119,27 @@ router.post(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// UPDATE ONE ------------------
|
// UPDATE ONE ------------------
|
||||||
const updateVariable = (id, vr) => {
|
const updateVariable = (id, vr) => {
|
||||||
return Variables.updateOne(id, vr)
|
return Variables.updateOne(id, vr)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.put(
|
router.put(
|
||||||
'/:id/',
|
'/:id/',
|
||||||
authGuard(['SUBMIT_VARIABLES', 'MODIFY_VARIABLES']),
|
authGuard(['SUBMIT_VARIABLES', 'MODIFY_VARIABLES']),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
updateVariable(req.params.id, req.body)
|
updateVariable(req.params.id, req.body)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.send(JSON.stringify(v))
|
res.send(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -147,27 +147,27 @@ router.put(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// DELETE ONE ------------------
|
// DELETE ONE ------------------
|
||||||
const deleteVariable = (id) => {
|
const deleteVariable = (id) => {
|
||||||
return Variables.deleteOne(id)
|
return Variables.deleteOne(id)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
throw err
|
throw err;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
router.delete(
|
router.delete(
|
||||||
'/:id/',
|
'/:id/',
|
||||||
authGuard(['SUBMIT_VARIABLES', 'MODIFY_VARIABLES', 'DELETE_VARIABLES']),
|
authGuard(['SUBMIT_VARIABLES', 'MODIFY_VARIABLES', 'DELETE_VARIABLES']),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
deleteVariable(req.params.id)
|
deleteVariable(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8');
|
||||||
res.send(JSON.stringify(v))
|
res.send(JSON.stringify(v));
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.status(err.code).send(JSON.stringify(
|
||||||
@@ -175,11 +175,11 @@ router.delete(
|
|||||||
"error": err.message,
|
"error": err.message,
|
||||||
"code": err.code
|
"code": err.code
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
// Param validations
|
// Param validations
|
||||||
router.param('id', functions.paramIntCheck)
|
router.param('id', functions.paramIntCheck);
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router;
|
||||||
@@ -14,8 +14,8 @@ const getTemplateFile = (path) => {
|
|||||||
} else {
|
} else {
|
||||||
resolve(html);
|
resolve(html);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,12 +50,12 @@ const sendRegistrationMail = (data) => {
|
|||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
const sendBanEmail = (date) => {
|
// const sendBanEmail = (date) => {
|
||||||
return null;
|
// return null;
|
||||||
}
|
// };
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
sendRegistrationMail,
|
sendRegistrationMail,
|
||||||
}
|
};
|
||||||
@@ -91,7 +91,7 @@
|
|||||||
<p>Votre compte Auracle a bien été enregistré et est rattaché à cette adresse mail.</p>
|
<p>Votre compte Auracle a bien été enregistré et est rattaché à cette adresse mail.</p>
|
||||||
<p>Cependant, afin de garantir la sécurité de vos données, votre compte doit être vérifié avant votre
|
<p>Cependant, afin de garantir la sécurité de vos données, votre compte doit être vérifié avant votre
|
||||||
première connexion. Vous pouvez
|
première connexion. Vous pouvez
|
||||||
<a href="http: //localhost:2814/api/v1/users/verification/{{ user.token }}">
|
<a href="http://localhost:2814/api/v1/users/verification/{{ user.token }}">
|
||||||
suivre ce lien afin de confirmer votre inscription.
|
suivre ce lien afin de confirmer votre inscription.
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -6,6 +6,6 @@ const Ingredient = {
|
|||||||
"description": { "type": "string" }
|
"description": { "type": "string" }
|
||||||
},
|
},
|
||||||
"required": ["name", "description"]
|
"required": ["name", "description"]
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = Ingredient
|
module.exports = Ingredient;
|
||||||
@@ -7,6 +7,6 @@ const MetaSchool = {
|
|||||||
"schools": { "type": "array" }
|
"schools": { "type": "array" }
|
||||||
},
|
},
|
||||||
"required": ["name", "description"]
|
"required": ["name", "description"]
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = MetaSchool
|
module.exports = MetaSchool;
|
||||||
@@ -7,6 +7,6 @@ const School = {
|
|||||||
"meta_school_id": { "type": "number" },
|
"meta_school_id": { "type": "number" },
|
||||||
},
|
},
|
||||||
"required": ["name", "description", "meta_school_id"]
|
"required": ["name", "description", "meta_school_id"]
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = School
|
module.exports = School;
|
||||||
@@ -34,6 +34,6 @@ const Spell = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["name", "description"]
|
"required": ["name", "description"]
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = Spell
|
module.exports = Spell;
|
||||||
@@ -7,6 +7,6 @@ const User = {
|
|||||||
"password": { "type": "string" },
|
"password": { "type": "string" },
|
||||||
},
|
},
|
||||||
"required": ["name", "password", "mail"]
|
"required": ["name", "password", "mail"]
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = User
|
module.exports = User;
|
||||||
@@ -5,6 +5,6 @@ const Variable = {
|
|||||||
"description": { "type": "string" },
|
"description": { "type": "string" },
|
||||||
},
|
},
|
||||||
"required": ["description"]
|
"required": ["description"]
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = Variable
|
module.exports = Variable;
|
||||||
Reference in New Issue
Block a user