code improvements
This commit is contained in:
@ -25,21 +25,7 @@ router.get('/materials', (req, res, next) => {
|
||||
MaterialValidate.query(req.query, ['dev', 'admin'].indexOf(req.authDetails.level) >= 0);
|
||||
if (error) return res400(error, res);
|
||||
|
||||
let conditions;
|
||||
|
||||
if (filters.hasOwnProperty('status')) {
|
||||
if(filters.status === 'all') {
|
||||
conditions = {$or: [{status: globals.status.val}, {status: globals.status.new}]}
|
||||
}
|
||||
else {
|
||||
conditions = {status: filters.status};
|
||||
}
|
||||
}
|
||||
else { // default
|
||||
conditions = {status: globals.status.val};
|
||||
}
|
||||
|
||||
MaterialModel.find(conditions).sort({name: 1}).populate('group_id').populate('supplier_id')
|
||||
MaterialModel.find(filters).sort({name: 1}).populate('group_id').populate('supplier_id')
|
||||
.lean().exec((err, data) => {
|
||||
if (err) return next(err);
|
||||
|
||||
|
@ -22,16 +22,12 @@ import globals from '../globals';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// TODO: do not use streaming for spectrum filenames
|
||||
|
||||
|
||||
router.get('/samples', async (req, res, next) => {
|
||||
if (!req.auth(res, ['read', 'write', 'dev', 'admin'], 'all')) return;
|
||||
|
||||
const {error, value: filters} = SampleValidate.query(req.query, ['dev', 'admin'].indexOf(req.authDetails.level) >= 0);
|
||||
console.log(error);
|
||||
if (error) return res400(error, res);
|
||||
console.log(filters.filters);
|
||||
|
||||
// spectral data and csv not allowed for read/write users
|
||||
if ((filters.fields.find(e => e.indexOf('.' + globals.spectrum.dpt) >= 0) || filters.output !== 'json') &&
|
||||
@ -388,7 +384,6 @@ router.get('/samples', async (req, res, next) => {
|
||||
projection._id = false;
|
||||
}
|
||||
queryPtr.push({$project: projection});
|
||||
console.log(JSON.stringify(query));
|
||||
// use streaming when including spectrum files
|
||||
if (!fieldsToAdd.find(e => e.indexOf(globals.spectrum.spectrum + '.' + globals.spectrum.dpt) >= 0)) {
|
||||
collection.aggregate(query).allowDiskUse(true).exec((err, data) => {
|
||||
@ -687,8 +682,6 @@ async function numberGenerate (sample, req, res, next) {
|
||||
const sampleData = await SampleModel
|
||||
.aggregate([
|
||||
{$match: {number: new RegExp('^' + req.authDetails.location + '[0-9]+$', 'm')}},
|
||||
// {$addFields: {number2: {$toDecimal: {$arrayElemAt: [{$split: [{$arrayElemAt:
|
||||
// [{$split: ['$number', 'Rng']}, 1]}, '_']}, 0]}}}}, // not working with MongoDb 3.6
|
||||
{$addFields: {sortNumber: {$let: {
|
||||
vars: {tmp: {$concat: ['000000000000000000000000000000',
|
||||
{$arrayElemAt: [{$split:
|
||||
@ -701,7 +694,6 @@ async function numberGenerate (sample, req, res, next) {
|
||||
.exec()
|
||||
.catch(err => next(err));
|
||||
if (sampleData instanceof Error) return false;
|
||||
console.log(sampleData);
|
||||
let number = (sampleData[0] ? Number(sampleData[0].number.replace(/[^0-9]+/g, '')) : 0);
|
||||
if (numberBuffer[req.authDetails.location] && numberBuffer[req.authDetails.location] >= number) {
|
||||
number = numberBuffer[req.authDetails.location];
|
||||
|
@ -64,8 +64,6 @@ router.put('/template/:collection(measurement|condition|material)/' + IdValidate
|
||||
}
|
||||
|
||||
if (!_.isEqual(_.pick(templateData, _.keys(template)), template)) { // data was changed
|
||||
console.log(template);
|
||||
console.log(templateData);
|
||||
if (!template.parameters || _.isEqual(templateData.parameters, template.parameters)) { // only name was changed
|
||||
model(req).findByIdAndUpdate(req.params.id, {name: template.name}, {new: true})
|
||||
.log(req).lean().exec((err, data) => {
|
||||
|
@ -199,7 +199,6 @@ export default class SampleValidate {
|
||||
data.filters[i] = decodeURIComponent(data.filters[i]);
|
||||
}
|
||||
catch (ignore) {}
|
||||
console.log(data.filters[i]);
|
||||
data.filters[i] = JSON.parse(data.filters[i]);
|
||||
data.filters[i].values = data.filters[i].values.map(e => { // validate filter values
|
||||
if (e === null) { // null values are always allowed
|
||||
@ -241,7 +240,6 @@ export default class SampleValidate {
|
||||
validator = Joi.object(this.sample);
|
||||
}
|
||||
const {value, error} = validator.validate({[field]: e});
|
||||
console.log(error);
|
||||
if (error) throw error; // reject invalid values
|
||||
return value[field];
|
||||
});
|
||||
|
@ -75,7 +75,7 @@ export default class UserValidate { // validate input for user
|
||||
}).validate(data);
|
||||
}
|
||||
else {
|
||||
return{error: 'No parameter specified!', value: {}};
|
||||
return {error: 'No parameter specified!', value: {}};
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user