Merge pull request #46 in DEFINMA/definma-api from proper-indentation to master
* commit '7c5b6ec605e7ecd3d4cc9ba59c41f45ef4783c80': Properly indent all source files
This commit is contained in:
commit
a08bfd9922
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dfop-api",
|
"name": "definma-api",
|
||||||
"version": "1.0.0",
|
"version": "0.9.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -109,7 +109,7 @@ router.delete('/material/' + IdValidate.parameter(), (req, res, next) => {
|
|||||||
|
|
||||||
// check if there are still samples referencing this material
|
// check if there are still samples referencing this material
|
||||||
SampleModel.find({'material_id': new mongoose.Types.ObjectId(req.params.id), status: {$ne: globals.status.del}})
|
SampleModel.find({'material_id': new mongoose.Types.ObjectId(req.params.id), status: {$ne: globals.status.del}})
|
||||||
.lean().exec((err, data) => {
|
.lean().exec((err, data) => {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
if (data.length) {
|
if (data.length) {
|
||||||
return res.status(400).json({status: 'Material still in use'});
|
return res.status(400).json({status: 'Material still in use'});
|
||||||
@ -124,7 +124,7 @@ router.delete('/material/' + IdValidate.parameter(), (req, res, next) => {
|
|||||||
res.status(404).json({status: 'Not found'});
|
res.status(404).json({status: 'Not found'});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.put('/material/restore/' + IdValidate.parameter(), (req, res, next) => {
|
router.put('/material/restore/' + IdValidate.parameter(), (req, res, next) => {
|
||||||
@ -190,12 +190,12 @@ module.exports = router;
|
|||||||
|
|
||||||
async function nameCheck (material, res, next) { // check if name was already taken
|
async function nameCheck (material, res, next) { // check if name was already taken
|
||||||
const materialData = await MaterialModel.findOne({name: material.name}).lean().exec().catch(err => next(err)) as any;
|
const materialData = await MaterialModel.findOne({name: material.name}).lean().exec().catch(err => next(err)) as any;
|
||||||
if (materialData instanceof Error) return false;
|
if (materialData instanceof Error) return false;
|
||||||
if (materialData) { // could not find material_id
|
if (materialData) { // could not find material_id
|
||||||
res.status(400).json({status: 'Material name already taken'});
|
res.status(400).json({status: 'Material name already taken'});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function groupResolve (material, req, next) {
|
async function groupResolve (material, req, next) {
|
||||||
|
@ -47,23 +47,23 @@ router.put('/measurement/' + IdValidate.parameter(), async (req, res, next) => {
|
|||||||
|
|
||||||
// add properties needed for sampleIdCheck
|
// add properties needed for sampleIdCheck
|
||||||
measurement.measurement_template = data.measurement_template;
|
measurement.measurement_template = data.measurement_template;
|
||||||
measurement.sample_id = data.sample_id;
|
measurement.sample_id = data.sample_id;
|
||||||
if (!await sampleIdCheck(measurement, req, res, next)) return;
|
if (!await sampleIdCheck(measurement, req, res, next)) return;
|
||||||
|
|
||||||
// check for changes
|
// check for changes
|
||||||
if (measurement.values) { // fill not changed values from database
|
if (measurement.values) { // fill not changed values from database
|
||||||
measurement.values = _.assign({}, data.values, measurement.values);
|
measurement.values = _.assign({}, data.values, measurement.values);
|
||||||
if (!_.isEqual(measurement.values, data.values)) {
|
if (!_.isEqual(measurement.values, data.values)) {
|
||||||
measurement.status = globals.status.new; // set status to new
|
measurement.status = globals.status.new; // set status to new
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!await templateCheck(measurement, 'change', res, next)) return;
|
if (!await templateCheck(measurement, 'change', res, next)) return;
|
||||||
await MeasurementModel.findByIdAndUpdate(req.params.id, measurement, {new: true})
|
await MeasurementModel.findByIdAndUpdate(req.params.id, measurement, {new: true})
|
||||||
.log(req).lean().exec((err, data) => {
|
.log(req).lean().exec((err, data) => {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
res.json(MeasurementValidate.output(data, req));
|
res.json(MeasurementValidate.output(data, req));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete('/measurement/' + IdValidate.parameter(), (req, res, next) => {
|
router.delete('/measurement/' + IdValidate.parameter(), (req, res, next) => {
|
||||||
|
@ -128,9 +128,9 @@ router.put('/template/:collection(measurement|condition|material)/' + IdValidate
|
|||||||
else {
|
else {
|
||||||
res.json(TemplateValidate.output(templateData));
|
res.json(TemplateValidate.output(templateData));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/template/:collection(measurement|condition|material)/new', async (req, res, next) => {
|
router.post('/template/:collection(measurement|condition|material)/new', async (req, res, next) => {
|
||||||
if (!req.auth(res, ['dev', 'admin'], 'basic')) return;
|
if (!req.auth(res, ['dev', 'admin'], 'basic')) return;
|
||||||
|
|
||||||
const {error, value: template} = TemplateValidate.input(req.body, 'new');
|
const {error, value: template} = TemplateValidate.input(req.body, 'new');
|
||||||
@ -144,15 +144,15 @@ router.post('/template/:collection(measurement|condition|material)/new', async (
|
|||||||
db.log(req, req.params.collection + '_templates', {_id: data._id}, data.toObject());
|
db.log(req, req.params.collection + '_templates', {_id: data._id}, data.toObject());
|
||||||
res.json(TemplateValidate.output(data.toObject()));
|
res.json(TemplateValidate.output(data.toObject()));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
||||||
function model (req) { // return right template model
|
function model (req) { // return right template model
|
||||||
switch (req.params.collection) {
|
switch (req.params.collection) {
|
||||||
case 'condition': return ConditionTemplateModel
|
case 'condition': return ConditionTemplateModel
|
||||||
case 'measurement': return MeasurementTemplateModel
|
case 'measurement': return MeasurementTemplateModel
|
||||||
case 'material': return MaterialTemplateModel
|
case 'material': return MaterialTemplateModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,28 +186,28 @@ module.exports = router;
|
|||||||
|
|
||||||
function getUsername (req, res) { // returns username or false if action is not allowed
|
function getUsername (req, res) { // returns username or false if action is not allowed
|
||||||
req.params.username = req.params[0]; // because of path regex
|
req.params.username = req.params[0]; // because of path regex
|
||||||
if (req.params.username !== undefined) { // different username than request user
|
if (req.params.username !== undefined) { // different username than request user
|
||||||
if (!req.auth(res, ['admin'], 'basic')) return false;
|
if (!req.auth(res, ['admin'], 'basic')) return false;
|
||||||
return req.params.username;
|
return req.params.username;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return req.authDetails.username;
|
return req.authDetails.username;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function usernameCheck (name, res, next) { // check if username is already taken
|
async function usernameCheck (name, res, next) { // check if username is already taken
|
||||||
const userData = await UserModel.findOne({name: name}).lean().exec().catch(err => next(err)) as any;
|
const userData = await UserModel.findOne({name: name}).lean().exec().catch(err => next(err)) as any;
|
||||||
if (userData instanceof Error) return false;
|
if (userData instanceof Error) return false;
|
||||||
if (userData || UserValidate.isSpecialName(name)) {
|
if (userData || UserValidate.isSpecialName(name)) {
|
||||||
res.status(400).json({status: 'Username already taken'});
|
res.status(400).json({status: 'Username already taken'});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function modelsCheck (models, res, next) { // check if model ids exist, returns false on error
|
async function modelsCheck (models, res, next) { // check if model ids exist, returns false on error
|
||||||
let result = true;
|
let result = true;
|
||||||
for (let i in models) {
|
for (let i in models) {
|
||||||
const model = await ModelModel.findOne({'models._id': mongoose.Types.ObjectId(models[i])})
|
const model = await ModelModel.findOne({'models._id': mongoose.Types.ObjectId(models[i])})
|
||||||
.lean().exec().catch(err => next(err)) as any;
|
.lean().exec().catch(err => next(err)) as any;
|
||||||
if(!model) {
|
if(!model) {
|
||||||
@ -215,6 +215,6 @@ async function modelsCheck (models, res, next) { // check if model ids exist, r
|
|||||||
result = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
@ -7,14 +7,14 @@ export default class MeasurementValidate {
|
|||||||
private static measurement = {
|
private static measurement = {
|
||||||
values: Joi.object()
|
values: Joi.object()
|
||||||
.pattern(/.*/, Joi.alternatives()
|
.pattern(/.*/, Joi.alternatives()
|
||||||
.try(
|
.try(
|
||||||
Joi.string().max(128),
|
Joi.string().max(128),
|
||||||
Joi.number(),
|
Joi.number(),
|
||||||
Joi.boolean(),
|
Joi.boolean(),
|
||||||
Joi.array().items(Joi.array().items(Joi.number())), // for spectra
|
Joi.array().items(Joi.array().items(Joi.number())), // for spectra
|
||||||
Joi.array()
|
Joi.array()
|
||||||
)
|
)
|
||||||
.allow(null)
|
.allow(null)
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -41,12 +41,12 @@ export default class SampleValidate {
|
|||||||
|
|
||||||
custom_fields: Joi.object()
|
custom_fields: Joi.object()
|
||||||
.pattern(/.*/, Joi.alternatives()
|
.pattern(/.*/, Joi.alternatives()
|
||||||
.try(
|
.try(
|
||||||
Joi.string().max(128),
|
Joi.string().max(128),
|
||||||
Joi.number(),
|
Joi.number(),
|
||||||
Joi.boolean(),
|
Joi.boolean(),
|
||||||
Joi.date()
|
Joi.date()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user