-
Notifications
You must be signed in to change notification settings - Fork 48
/
doDeleteAllBToMAssoc.js
50 lines (46 loc) · 1.42 KB
/
doDeleteAllBToMAssoc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* Copyright (c) 2016, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or
* https://opensource.org/licenses/BSD-3-Clause
*/
/**
* api/v1/helpers/verbs/doDeleteAllBToMAssoc.js
*/
'use strict';
const u = require('./utils');
const httpStatus = require('../../constants').httpStatus;
/**
* Deletes all the associations of the resource and sends back no content
* with a status of code 204.
*
* @param {IncomingMessage} req - The request object`
* @param {ServerResponse} res - The response object
* @param {Function} next - The next middleware function in the stack
* @param {Module} props - The module containing the properties of the resource
* whose association has to be deleted
* @param {String} assocName - The name of the association associated with the
* model
*
*/
function doDeleteAllBToMAssoc(req, res, next, // eslint-disable-line max-params
props, assocName) {
const params = req.swagger.params;
let modelInst;
u.findByKey(props, params)
.then((o) => {
modelInst = o;
return u.isWritable(req, o);
})
.then((ok) => {
if (ok) {
u.deleteAllAssociations(modelInst, [assocName]);
res.status(httpStatus.NO_CONTENT).json();
} else {
u.forbidden(next);
}
})
.catch((err) => u.handleError(next, err, props.modelName));
}
module.exports = doDeleteAllBToMAssoc;