Updated module tree
This commit is contained in:
@@ -4,13 +4,16 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
let router = express.Router();
|
let router = express.Router();
|
||||||
|
|
||||||
// Connection
|
// AuthGuard
|
||||||
const functions = require('../functions');
|
const authGuard = require('./middleware/authGuard');
|
||||||
|
|
||||||
// Repository
|
// Repository
|
||||||
const IngredientRepository = require('../repositories/ingredient-repository');
|
const IngredientRepository = require('../repositories/ingredient-repository');
|
||||||
const Ingredients = new IngredientRepository();
|
const Ingredients = new IngredientRepository();
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
const functions = require('../functions');
|
||||||
|
|
||||||
// ROUTES
|
// ROUTES
|
||||||
// GET ALL ------------------
|
// GET ALL ------------------
|
||||||
const getIngredients = () => {
|
const getIngredients = () => {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
let router = express.Router();
|
let router = express.Router();
|
||||||
|
|
||||||
// Connection
|
// Functions
|
||||||
const functions = require('../functions');
|
const functions = require('../functions');
|
||||||
|
|
||||||
// Repository
|
// Repository
|
||||||
|
|||||||
@@ -4,13 +4,16 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
let router = express.Router();
|
let router = express.Router();
|
||||||
|
|
||||||
// Connection
|
// AuthGuard
|
||||||
const functions = require('../functions');
|
const authGuard = require('./middleware/authGuard');
|
||||||
|
|
||||||
// Repository
|
// Repository
|
||||||
const SchoolRepository = require('../repositories/school-repository');
|
const SchoolRepository = require('../repositories/school-repository');
|
||||||
const Schools = new SchoolRepository();
|
const Schools = new SchoolRepository();
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
const functions = require('../functions');
|
||||||
|
|
||||||
// ROUTES
|
// ROUTES
|
||||||
// GET ALL ------------------
|
// GET ALL ------------------
|
||||||
const getSchools = () => {
|
const getSchools = () => {
|
||||||
@@ -20,21 +23,23 @@ const getSchools = () => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.get('/', async (req, res) => {
|
router.get(
|
||||||
getSchools()
|
'/',
|
||||||
.then(v => {
|
async (req, res) => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
getSchools()
|
||||||
res.end(JSON.stringify(v))
|
.then(v => {
|
||||||
})
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
.catch(err => {
|
res.end(JSON.stringify(v))
|
||||||
res.status(err.code).send(JSON.stringify(
|
})
|
||||||
{
|
.catch(err => {
|
||||||
"error": err.message,
|
res.status(err.code).send(JSON.stringify(
|
||||||
"code": err.code
|
{
|
||||||
})
|
"error": err.message,
|
||||||
)
|
"code": err.code
|
||||||
})
|
})
|
||||||
})
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// GET ONE ------------------
|
// GET ONE ------------------
|
||||||
@@ -45,21 +50,23 @@ const getSchool = (id) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.get('/:id/', async (req, res) => {
|
router.get(
|
||||||
getSchool(req.params.id)
|
'/:id/',
|
||||||
.then(v => {
|
async (req, res) => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
getSchool(req.params.id)
|
||||||
res.end(JSON.stringify(v))
|
.then(v => {
|
||||||
})
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
.catch(err => {
|
res.end(JSON.stringify(v))
|
||||||
res.status(err.code).send(JSON.stringify(
|
})
|
||||||
{
|
.catch(err => {
|
||||||
"error": err.message,
|
res.status(err.code).send(JSON.stringify(
|
||||||
"code": err.code
|
{
|
||||||
})
|
"error": err.message,
|
||||||
)
|
"code": err.code
|
||||||
})
|
})
|
||||||
})
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// GET SPELLS FROM ONE ------------------
|
// GET SPELLS FROM ONE ------------------
|
||||||
@@ -70,21 +77,23 @@ const getSpellsFromOne = (id) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.get('/:id/spells', async (req, res) => {
|
router.get(
|
||||||
getSpellsFromOne(req.params.id)
|
'/:id/spells',
|
||||||
.then(v => {
|
async (req, res) => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
getSpellsFromOne(req.params.id)
|
||||||
res.end(JSON.stringify(v))
|
.then(v => {
|
||||||
})
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
.catch(err => {
|
res.end(JSON.stringify(v))
|
||||||
res.status(err.code).send(JSON.stringify(
|
})
|
||||||
{
|
.catch(err => {
|
||||||
"error": err.message,
|
res.status(err.code).send(JSON.stringify(
|
||||||
"code": err.code
|
{
|
||||||
})
|
"error": err.message,
|
||||||
)
|
"code": err.code
|
||||||
})
|
})
|
||||||
})
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// CREATE ONE ------------------
|
// CREATE ONE ------------------
|
||||||
@@ -95,21 +104,24 @@ const addSchool = (s) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.post('/', async (req, res) => {
|
router.post(
|
||||||
addSchool(req.body)
|
'/',
|
||||||
.then(v => {
|
authGuard(['SUBMIT_SCHOOL']),
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
async (req, res) => {
|
||||||
res.send(JSON.stringify(v))
|
addSchool(req.body)
|
||||||
})
|
.then(v => {
|
||||||
.catch(err => {
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.send(JSON.stringify(v))
|
||||||
{
|
})
|
||||||
"error": err.message,
|
.catch(err => {
|
||||||
"code": err.code
|
res.status(err.code).send(JSON.stringify(
|
||||||
})
|
{
|
||||||
)
|
"error": err.message,
|
||||||
})
|
"code": err.code
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// UPDATE ONE ------------------
|
// UPDATE ONE ------------------
|
||||||
const updateSchool = (id, s) => {
|
const updateSchool = (id, s) => {
|
||||||
@@ -119,21 +131,23 @@ const updateSchool = (id, s) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.put('/:id/', async (req, res) => {
|
router.put(
|
||||||
updateSchool(req.params.id, req.body)
|
'/:id/',
|
||||||
.then(v => {
|
async (req, res) => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
updateSchool(req.params.id, req.body)
|
||||||
res.send(JSON.stringify(v))
|
.then(v => {
|
||||||
})
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
.catch(err => {
|
res.send(JSON.stringify(v))
|
||||||
res.status(err.code).send(JSON.stringify(
|
})
|
||||||
{
|
.catch(err => {
|
||||||
"error": err.message,
|
res.status(err.code).send(JSON.stringify(
|
||||||
"code": err.code
|
{
|
||||||
})
|
"error": err.message,
|
||||||
)
|
"code": err.code
|
||||||
})
|
})
|
||||||
})
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// DELETE ONE ------------------
|
// DELETE ONE ------------------
|
||||||
@@ -144,21 +158,23 @@ const deleteSchool = (id) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.delete('/:id/', async (req, res) => {
|
router.delete(
|
||||||
deleteSchool(req.params.id)
|
'/:id/',
|
||||||
.then(v => {
|
async (req, res) => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
deleteSchool(req.params.id)
|
||||||
res.send(JSON.stringify(v))
|
.then(v => {
|
||||||
})
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
.catch(err => {
|
res.send(JSON.stringify(v))
|
||||||
res.status(err.code).send(JSON.stringify(
|
})
|
||||||
{
|
.catch(err => {
|
||||||
"error": err.message,
|
res.status(err.code).send(JSON.stringify(
|
||||||
"code": err.code
|
{
|
||||||
})
|
"error": err.message,
|
||||||
)
|
"code": err.code
|
||||||
})
|
})
|
||||||
})
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// Param validations
|
// Param validations
|
||||||
router.param('id', functions.paramIntCheck)
|
router.param('id', functions.paramIntCheck)
|
||||||
|
|||||||
@@ -4,9 +4,6 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
let router = express.Router();
|
let router = express.Router();
|
||||||
|
|
||||||
// Connection
|
|
||||||
const functions = require('../functions');
|
|
||||||
|
|
||||||
// AuthGuard
|
// AuthGuard
|
||||||
const authGuard = require('./middleware/authGuard');
|
const authGuard = require('./middleware/authGuard');
|
||||||
|
|
||||||
@@ -14,6 +11,9 @@ const authGuard = require('./middleware/authGuard');
|
|||||||
const SpellReposity = require('../repositories/spell-repository');
|
const SpellReposity = require('../repositories/spell-repository');
|
||||||
const Spells = new SpellReposity();
|
const Spells = new SpellReposity();
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
const functions = require('../functions');
|
||||||
|
|
||||||
// ROUTES
|
// ROUTES
|
||||||
// GET ALL PUBLIC ------------------
|
// GET ALL PUBLIC ------------------
|
||||||
const getPublicSpells = (name, description, level, charge, cost, ritual) => {
|
const getPublicSpells = (name, description, level, charge, cost, ritual) => {
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
let router = express.Router();
|
let router = express.Router();
|
||||||
|
|
||||||
|
// AuthGuard
|
||||||
|
const authGuard = require('./middleware/authGuard');
|
||||||
|
|
||||||
// Repository
|
// Repository
|
||||||
const UserRepository = require('../repositories/user-repository');
|
const UserRepository = require('../repositories/user-repository');
|
||||||
const Users = new UserRepository();
|
const Users = new UserRepository();
|
||||||
|
|||||||
@@ -4,13 +4,16 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
let router = express.Router();
|
let router = express.Router();
|
||||||
|
|
||||||
// Connection
|
// AuthGuard
|
||||||
const functions = require('../functions');
|
const authGuard = require('./middleware/authGuard');
|
||||||
|
|
||||||
// Repository
|
// Repository
|
||||||
const VariableRepository = require('../repositories/variable-repository');
|
const VariableRepository = require('../repositories/variable-repository');
|
||||||
const Variables = new VariableRepository();
|
const Variables = new VariableRepository();
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
const functions = require('../functions');
|
||||||
|
|
||||||
// ROUTES
|
// ROUTES
|
||||||
// GET ALL ------------------
|
// GET ALL ------------------
|
||||||
const getvariables = () => {
|
const getvariables = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user