added /samples/count
This commit is contained in:
parent
4dad680edf
commit
49f7a475b7
@ -71,6 +71,25 @@
|
|||||||
500:
|
500:
|
||||||
$ref: 'api.yaml#/components/responses/500'
|
$ref: 'api.yaml#/components/responses/500'
|
||||||
|
|
||||||
|
/samples/count:
|
||||||
|
get:
|
||||||
|
summary: total number of samples
|
||||||
|
description: 'Auth: all, levels: read, write, maintain, dev, admin'
|
||||||
|
tags:
|
||||||
|
- /sample
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: sample count
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
properties:
|
||||||
|
count:
|
||||||
|
type: number
|
||||||
|
example: 864
|
||||||
|
500:
|
||||||
|
$ref: 'api.yaml#/components/responses/500'
|
||||||
|
|
||||||
/sample/{id}:
|
/sample/{id}:
|
||||||
parameters:
|
parameters:
|
||||||
- $ref: 'api.yaml#/components/parameters/Id'
|
- $ref: 'api.yaml#/components/parameters/Id'
|
||||||
|
@ -318,6 +318,42 @@ describe('/sample', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('GET /samples/count', () => {
|
||||||
|
it('returns the correct number of samples', done => {
|
||||||
|
TestHelper.request(server, done, {
|
||||||
|
method: 'get',
|
||||||
|
url: '/samples/count',
|
||||||
|
auth: {basic: 'admin'},
|
||||||
|
httpStatus: 200
|
||||||
|
}).end((err, res) => {
|
||||||
|
if (err) return done(err);
|
||||||
|
const json = require('../test/db.json');
|
||||||
|
should(res.body.count).be.eql(json.collections.samples.length);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('works with an API key', done => {
|
||||||
|
TestHelper.request(server, done, {
|
||||||
|
method: 'get',
|
||||||
|
url: '/samples/count',
|
||||||
|
auth: {key: 'janedoe'},
|
||||||
|
httpStatus: 200
|
||||||
|
}).end((err, res) => {
|
||||||
|
if (err) return done(err);
|
||||||
|
const json = require('../test/db.json');
|
||||||
|
should(res.body.count).be.eql(json.collections.samples.length);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('rejects unauthorized requests', done => {
|
||||||
|
TestHelper.request(server, done, {
|
||||||
|
method: 'get',
|
||||||
|
url: '/samples/count',
|
||||||
|
httpStatus: 401
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('GET /sample/{id}', () => {
|
describe('GET /sample/{id}', () => {
|
||||||
it('returns the right sample', done => {
|
it('returns the right sample', done => {
|
||||||
TestHelper.request(server, done, {
|
TestHelper.request(server, done, {
|
||||||
|
@ -62,7 +62,6 @@ router.get('/samples', (req, res, next) => {
|
|||||||
if (filters['to-page'] && filters['to-page'] < 0) {
|
if (filters['to-page'] && filters['to-page'] < 0) {
|
||||||
data.reverse();
|
data.reverse();
|
||||||
}
|
}
|
||||||
console.log(data);
|
|
||||||
res.json(_.compact(data.map(e => SampleValidate.output(e)))); // validate all and filter null values from validation errors
|
res.json(_.compact(data.map(e => SampleValidate.output(e)))); // validate all and filter null values from validation errors
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@ -76,6 +75,15 @@ router.get('/samples/:state(new|deleted)', (req, res, next) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/samples/count', (req, res, next) => {
|
||||||
|
if (!req.auth(res, ['read', 'write', 'maintain', 'dev', 'admin'], 'all')) return;
|
||||||
|
|
||||||
|
SampleModel.estimatedDocumentCount((err, data) => {
|
||||||
|
if (err) return next(err);
|
||||||
|
res.json({count: data});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
router.get('/sample/' + IdValidate.parameter(), (req, res, next) => {
|
router.get('/sample/' + IdValidate.parameter(), (req, res, next) => {
|
||||||
if (!req.auth(res, ['read', 'write', 'maintain', 'dev', 'admin'], 'all')) return;
|
if (!req.auth(res, ['read', 'write', 'maintain', 'dev', 'admin'], 'all')) return;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user