Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function updateOneRecord(req, res, base, recursive) {
// Look up the model
let Model = actionUtil.parseModel(req);
if (!Model.mapping) {
return fallback(req, res);
}
// Locate and validate the required `id` parameter.
let pk = actionUtil.requirePk(req);
// Default the value blacklist to just "id", so that models that have an
// "id" field that is _not_ the primary key don't have the id field
// updated mistakenly. See https://github.com/balderdashy/sails/issues/3625
req.options.values = req.options.values || {};
req.options.values.blacklist = req.options.values.blacklist || ['id'];
// Create `values` object (monolithic combination of all parameters)
// But omit the blacklisted params (like JSONP callback param, etc.)
exports.getCollection = function(request, extraCriteria, next) {
// Determine model name and used default criteria object
var model = actionUtil.parseModel(request);
var criteria = actionUtil.parseCriteria(request);
// Merge extra criteria to main criteria object
if (extraCriteria) {
criteria = _.merge(criteria, extraCriteria);
}
// Fetch data from database
model
.find(criteria)
.exec(function found(error, items) {
next(error, items);
});
};
module.exports = (req, res) => {
_.set(req.options, 'criteria.blacklist', ['fields', 'populate', 'limit', 'skip', 'page', 'sort']);
const fields = req.param('fields') ? req.param('fields').replace(/ /g, '').split(',') : [];
const populate = req.param('populate') ? req.param('populate').replace(/ /g, '').split(',') : [];
const Model = actionUtil.parseModel(req);
const pk = actionUtil.requirePk(req);
const query = Model.find(pk, fields.length > 0 ? {select: fields} : null);
const findQuery = _.reduce(_.intersection(populate, takeAliases(Model.associations)), populateAliases, query);
findQuery
.then(record => record[0] ? res.ok(record[0]) : res.notFound())
.catch(res.negotiate);
};
module.exports = (req, res) => {
const Model = actionUtil.parseModel(req);
const values = actionUtil.parseValues(req);
Model
.create(_.omit(values, 'id'))
.then(res.created)
.catch(res.negotiate);
};
module.exports = (req, res) => {
_.set(req.options, 'criteria.blacklist', ['fields', 'populate', 'limit', 'skip', 'page', 'sort']);
const fields = req.param('fields') ? req.param('fields').replace(/ /g, '').split(',') : [];
const populate = req.param('populate') ? req.param('populate').replace(/ /g, '').split(',') : [];
const Model = actionUtil.parseModel(req);
const where = actionUtil.parseCriteria(req);
const limit = actionUtil.parseLimit(req);
const skip = req.param('page') * limit || actionUtil.parseSkip(req);
const sort = actionUtil.parseSort(req);
const query = Model.find(null, fields.length > 0 ? {select: fields} : null).where(where).limit(limit).skip(skip).sort(sort);
const findQuery = _.reduce(_.intersection(populate, takeAlias(Model.associations)), populateAlias, query);
findQuery
.then(records => [records, {
root: {
criteria: where,
limit: limit,
start: skip,
end: skip + limit,
page: Math.floor(skip / limit)
}
req.getRepository = (Entity) => {
if (!Entity) {
Entity = actionUtil.parseModel(req).Entity;
}
return getManager().getRepository(Entity);
};
schema: function(request, response) {
var model = actionUtil.parseModel(request);
var data = {
attributes: model.schema,
associations: model.associations
};
response.json(200, data);
}
};
const defaultCountBlueprint = (req, res) => {
const Model = actionUtil.parseModel(req);
const countQuery = Model.count();
countQuery.then(count => res.ok({count}));
};
count: function count(request, response) {
var Model = actionUtil.parseModel(request);
Model
.count(actionUtil.parseCriteria(request))
.exec(function found(error, count) {
if (error) {
response.negotiate(error);
} else {
response.ok({count: count});
}
})
;
}
};
module.exports = (req, res) => {
const Model = actionUtil.parseModel(req);
res.ok();
};