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