WIP implementing of endpoint for raspi
This commit is contained in:
parent
4dc4c85fb9
commit
fd5c46e86e
@ -187,3 +187,34 @@
|
||||
$ref: 'api.yaml#/components/responses/403'
|
||||
500:
|
||||
$ref: 'api.yaml#/components/responses/500'
|
||||
|
||||
/measurement/new/raspi:
|
||||
post:
|
||||
summary: add measurement
|
||||
description: 'Auth: basic, levels: write, dev, admin'
|
||||
x-doc: 'Adds status: 0 automatically'
|
||||
tags:
|
||||
- /measurement
|
||||
security:
|
||||
- BasicAuth: []
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: 'api.yaml#/components/schemas/Measurement'
|
||||
responses:
|
||||
200:
|
||||
description: measurement details
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: 'api.yaml#/components/schemas/Measurement'
|
||||
400:
|
||||
$ref: 'api.yaml#/components/responses/400'
|
||||
401:
|
||||
$ref: 'api.yaml#/components/responses/401'
|
||||
403:
|
||||
$ref: 'api.yaml#/components/responses/403'
|
||||
500:
|
||||
$ref: 'api.yaml#/components/responses/500'
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user