UNPKG

1.27 kBJavaScriptView Raw
1const HttpStatus = require('http-status');
2const ObjectId = require('../../models/objectId');
3const services = require('../../services');
4const utils = require('../../../config/utils');
5
6module.exports = {
7 /**
8 * Add a new mutator by id
9 * @param req
10 * @param res
11 */
12 add: (req, res) =>
13 new ObjectId({namespace: req.params.namespace, id: req.params.id}).validate()
14 .then((objectId) => services.mutators.add(objectId, req.body))
15 .then(() => res.status(HttpStatus.OK).json())
16 .catch((e) => utils.processError(e, res)),
17
18 /**
19 * Delete a mutator by id
20 * @param req
21 * @param res
22 */
23 delete: (req, res) =>
24 new ObjectId({namespace: req.params.namespace, id: req.params.id}).validate()
25 .then((objectId) => services.mutators.remove(objectId))
26 .then(() => res.status(HttpStatus.NO_CONTENT).json())
27 .catch((e) => utils.processError(e, res)),
28
29 /**
30 * Returns list of all mutators in a namespace by id
31 */
32 getAllIdsByNamespace: (req, res) =>
33 new ObjectId({namespace: req.params.namespace, id: 'dummy'}).validate()
34 .then((objectId) => services.mutators.getIds(objectId.namespace))
35 .then((ids) => res.status(HttpStatus.OK).json({ids}))
36 .catch((e) => utils.processError(e, res))
37};
\No newline at end of file