Archived
2

WIP implementing of endpoint for raspi

This commit is contained in:
2021-03-19 14:43:58 +01:00
parent 4dc4c85fb9
commit fd5c46e86e
2 changed files with 50 additions and 3 deletions

View File

@ -109,6 +109,7 @@ router.put('/measurement/validate/' + IdValidate.parameter(), (req, res, next) =
});
router.post('/measurement/new', async (req, res, next) => {
console.log(JSON.stringify(req.body));
if (!req.auth(res, ['write', 'dev', 'admin'], 'basic')) return;
const {error, value: measurement} = MeasurementValidate.input(req.body, 'new');
@ -126,10 +127,25 @@ router.post('/measurement/new', async (req, res, next) => {
});
});
router.post('/measurement/new/raspi', (req, res) => {
router.post('/measurement/new/raspi', async (req, res) => {
if (!req.auth(res, Object.values(globals.levels))) return;
// Needed data to rebuild measurement structure
JSON.parse(String.fromCodePoint(...req._readableState.buffer.head.data)).value;
// Extract data, should normally in req.body. Suspected failure in body-parser
let data = JSON.parse(String.fromCodePoint(...req._readableState.buffer.head.data)).value;
console.log(JSON.stringify(data));
console.log(data.filename);
// Extract sample number and measurement number from filename
let numbers = data.filename.match(/(?<=_)(.*)(?=_)/m)[0];
let temp = numbers.split("_");
// Sample number
let number = temp[0];
// Measurement number
let measurementNum = temp[1];
//Get sample ID from its number
let sampleID = await SampleModel.findOne({number: number})._id;
console.log(sampleID);
});
module.exports = router;