Implemented ESlint and passed down the rules

This commit is contained in:
Alexis
2021-01-20 19:07:56 +01:00
parent 615cced6ed
commit b318a88023
37 changed files with 2119 additions and 568 deletions

View File

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

View File

@@ -15,4 +15,4 @@ module.exports = {
ingredients,
variables,
users,
}
};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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