Properly indent all source files
This commit is contained in:
parent
0e37956bdb
commit
7c5b6ec605
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dfop-api",
|
||||
"version": "1.0.0",
|
||||
"name": "definma-api",
|
||||
"version": "0.9.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -109,7 +109,7 @@ router.delete('/material/' + IdValidate.parameter(), (req, res, next) => {
|
||||
|
||||
// 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}})
|
||||
.lean().exec((err, data) => {
|
||||
.lean().exec((err, data) => {
|
||||
if (err) return next(err);
|
||||
if (data.length) {
|
||||
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'});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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
|
||||
const materialData = await MaterialModel.findOne({name: material.name}).lean().exec().catch(err => next(err)) as any;
|
||||
if (materialData instanceof Error) return false;
|
||||
if (materialData) { // could not find material_id
|
||||
if (materialData instanceof Error) return false;
|
||||
if (materialData) { // could not find material_id
|
||||
res.status(400).json({status: 'Material name already taken'});
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
async function groupResolve (material, req, next) {
|
||||
|
@ -47,23 +47,23 @@ router.put('/measurement/' + IdValidate.parameter(), async (req, res, next) => {
|
||||
|
||||
// add properties needed for sampleIdCheck
|
||||
measurement.measurement_template = data.measurement_template;
|
||||
measurement.sample_id = data.sample_id;
|
||||
if (!await sampleIdCheck(measurement, req, res, next)) return;
|
||||
measurement.sample_id = data.sample_id;
|
||||
if (!await sampleIdCheck(measurement, req, res, next)) return;
|
||||
|
||||
// check for changes
|
||||
if (measurement.values) { // fill not changed values from database
|
||||
// check for changes
|
||||
if (measurement.values) { // fill not changed values from database
|
||||
measurement.values = _.assign({}, data.values, measurement.values);
|
||||
if (!_.isEqual(measurement.values, data.values)) {
|
||||
measurement.status = globals.status.new; // set status to new
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!await templateCheck(measurement, 'change', res, next)) return;
|
||||
await MeasurementModel.findByIdAndUpdate(req.params.id, measurement, {new: true})
|
||||
.log(req).lean().exec((err, data) => {
|
||||
if (!await templateCheck(measurement, 'change', res, next)) return;
|
||||
await MeasurementModel.findByIdAndUpdate(req.params.id, measurement, {new: true})
|
||||
.log(req).lean().exec((err, data) => {
|
||||
if (err) return next(err);
|
||||
res.json(MeasurementValidate.output(data, req));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
router.delete('/measurement/' + IdValidate.parameter(), (req, res, next) => {
|
||||
|
@ -128,9 +128,9 @@ router.put('/template/:collection(measurement|condition|material)/' + IdValidate
|
||||
else {
|
||||
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;
|
||||
|
||||
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());
|
||||
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) {
|
||||
case 'condition': return ConditionTemplateModel
|
||||
case 'measurement': return MeasurementTemplateModel
|
||||
case 'material': return MaterialTemplateModel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -186,28 +186,28 @@ module.exports = router;
|
||||
|
||||
function getUsername (req, res) { // returns username or false if action is not allowed
|
||||
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;
|
||||
return req.params.username;
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
return req.authDetails.username;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
if (userData instanceof Error) return false;
|
||||
if (userData || UserValidate.isSpecialName(name)) {
|
||||
if (userData instanceof Error) return false;
|
||||
if (userData || UserValidate.isSpecialName(name)) {
|
||||
res.status(400).json({status: 'Username already taken'});
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
async function modelsCheck (models, res, next) { // check if model ids exist, returns false on error
|
||||
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])})
|
||||
.lean().exec().catch(err => next(err)) as any;
|
||||
if(!model) {
|
||||
@ -215,6 +215,6 @@ async function modelsCheck (models, res, next) { // check if model ids exist, r
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
@ -7,14 +7,14 @@ export default class MeasurementValidate {
|
||||
private static measurement = {
|
||||
values: Joi.object()
|
||||
.pattern(/.*/, Joi.alternatives()
|
||||
.try(
|
||||
.try(
|
||||
Joi.string().max(128),
|
||||
Joi.number(),
|
||||
Joi.boolean(),
|
||||
Joi.array().items(Joi.array().items(Joi.number())), // for spectra
|
||||
Joi.array()
|
||||
)
|
||||
.allow(null)
|
||||
)
|
||||
.allow(null)
|
||||
)
|
||||
};
|
||||
|
||||
|
@ -41,12 +41,12 @@ export default class SampleValidate {
|
||||
|
||||
custom_fields: Joi.object()
|
||||
.pattern(/.*/, Joi.alternatives()
|
||||
.try(
|
||||
.try(
|
||||
Joi.string().max(128),
|
||||
Joi.number(),
|
||||
Joi.boolean(),
|
||||
Joi.date()
|
||||
)
|
||||
)
|
||||
)
|
||||
}),
|
||||
|
||||
|
Reference in New Issue
Block a user