Updated module tree

This commit is contained in:
Alexis
2021-01-19 21:27:06 +01:00
parent e8ca2416b7
commit e2061d6595
6 changed files with 125 additions and 100 deletions

View File

@@ -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 = () => {

View File

@@ -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

View File

@@ -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,7 +23,9 @@ const getSchools = () => {
throw err throw err
}) })
} }
router.get('/', async (req, res) => { router.get(
'/',
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')
@@ -34,7 +39,7 @@ router.get('/', async (req, res) => {
}) })
) )
}) })
}) })
// GET ONE ------------------ // GET ONE ------------------
@@ -45,7 +50,9 @@ const getSchool = (id) => {
throw err throw err
}) })
} }
router.get('/:id/', async (req, res) => { router.get(
'/:id/',
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')
@@ -59,7 +66,7 @@ router.get('/:id/', async (req, res) => {
}) })
) )
}) })
}) })
// GET SPELLS FROM ONE ------------------ // GET SPELLS FROM ONE ------------------
@@ -70,7 +77,9 @@ const getSpellsFromOne = (id) => {
throw err throw err
}) })
} }
router.get('/:id/spells', async (req, res) => { router.get(
'/:id/spells',
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')
@@ -84,7 +93,7 @@ router.get('/:id/spells', async (req, res) => {
}) })
) )
}) })
}) })
// CREATE ONE ------------------ // CREATE ONE ------------------
@@ -95,7 +104,10 @@ const addSchool = (s) => {
throw err throw err
}) })
} }
router.post('/', async (req, res) => { router.post(
'/',
authGuard(['SUBMIT_SCHOOL']),
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')
@@ -109,7 +121,7 @@ router.post('/', async (req, res) => {
}) })
) )
}) })
}) })
// UPDATE ONE ------------------ // UPDATE ONE ------------------
const updateSchool = (id, s) => { const updateSchool = (id, s) => {
@@ -119,7 +131,9 @@ const updateSchool = (id, s) => {
throw err throw err
}) })
} }
router.put('/:id/', async (req, res) => { router.put(
'/:id/',
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')
@@ -133,7 +147,7 @@ router.put('/:id/', async (req, res) => {
}) })
) )
}) })
}) })
// DELETE ONE ------------------ // DELETE ONE ------------------
@@ -144,7 +158,9 @@ const deleteSchool = (id) => {
throw err throw err
}) })
} }
router.delete('/:id/', async (req, res) => { router.delete(
'/:id/',
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')
@@ -158,7 +174,7 @@ router.delete('/:id/', async (req, res) => {
}) })
) )
}) })
}) })
// Param validations // Param validations
router.param('id', functions.paramIntCheck) router.param('id', functions.paramIntCheck)

View File

@@ -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) => {

View File

@@ -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();

View File

@@ -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 = () => {