Archived
2

restore measurements

This commit is contained in:
VLE2FE 2020-05-28 15:03:49 +02:00
parent 52039317e0
commit d924ee5a8c
3 changed files with 91 additions and 2 deletions

View File

@ -77,6 +77,29 @@
500:
$ref: 'api.yaml#/components/responses/500'
/measurement/restore/{id}:
parameters:
- $ref: 'api.yaml#/components/parameters/Id'
put:
summary: restore measurement
description: 'Auth: basic, levels: maintain, admin'
x-doc: status is set to 0
tags:
- /measurement
security:
- BasicAuth: []
responses:
200:
$ref: 'api.yaml#/components/responses/Ok'
401:
$ref: 'api.yaml#/components/responses/401'
403:
$ref: 'api.yaml#/components/responses/403'
404:
$ref: 'api.yaml#/components/responses/404'
500:
$ref: 'api.yaml#/components/responses/500'
/measurement/new:
post:
summary: add measurement

View File

@ -3,8 +3,6 @@ import MeasurementModel from '../models/measurement';
import TestHelper from "../test/helper";
import globals from '../globals';
// TODO: restore measurements for m/a
describe('/measurement', () => {
let server;
@ -367,6 +365,61 @@ describe('/measurement', () => {
});
});
describe('PUT /measurement/restore/{id}', () => {
it('sets the status', done => {
TestHelper.request(server, done, {
method: 'put',
url: '/measurement/restore/800000000000000000000004',
auth: {basic: 'admin'},
httpStatus: 200,
req: {}
}).end((err, res) => {
if (err) return done (err);
should(res.body).be.eql({status: 'OK'});
MeasurementModel.findById('800000000000000000000004').lean().exec((err, data: any) => {
if (err) return done(err);
should(data).have.property('status',globals.status.new);
done();
});
});
});
it('rejects an API key', done => {
TestHelper.request(server, done, {
method: 'put',
url: '/measurement/restore/800000000000000000000004',
auth: {key: 'admin'},
httpStatus: 401,
req: {}
});
});
it('rejects a write user', done => {
TestHelper.request(server, done, {
method: 'put',
url: '/measurement/restore/800000000000000000000004',
auth: {basic: 'janedoe'},
httpStatus: 403,
req: {}
});
});
it('returns 404 for an unknown sample', done => {
TestHelper.request(server, done, {
method: 'put',
url: '/measurement/restore/000000000000000000000004',
auth: {basic: 'admin'},
httpStatus: 404,
req: {}
});
});
it('rejects unauthorized requests', done => {
TestHelper.request(server, done, {
method: 'put',
url: '/measurement/restore/800000000000000000000004',
httpStatus: 401,
req: {}
});
});
});
describe('POST /measurement/new', () => {
it('returns the right measurement', done => {
TestHelper.request(server, done, {

View File

@ -78,6 +78,19 @@ router.delete('/measurement/' + IdValidate.parameter(), (req, res, next) => {
});
});
router.put('/measurement/restore/' + IdValidate.parameter(), (req, res, next) => {
if (!req.auth(res, ['maintain', 'admin'], 'basic')) return;
MeasurementModel.findByIdAndUpdate(req.params.id, {status: globals.status.new}).lean().exec((err, data) => {
if (err) return next(err);
if (!data) {
return res.status(404).json({status: 'Not found'});
}
res.json({status: 'OK'});
});
});
router.post('/measurement/new', async (req, res, next) => {
if (!req.auth(res, ['write', 'maintain', 'dev', 'admin'], 'basic')) return;