<commit_before>exports.definition = function(modelName) {
	var Model = sails.models[modelName];
	return {
		// Call findAll, unless this is a basic request, then render the index view
		index: function(req, res) {
			if(req.isAjax || req.isSocket) {
				if(req.param('id')) this.find(req, res);
				else this.findAll(req, res);
			} else res.view();
		},

		// Fetch a single model from testtable
		find: function(req, res) {
			if(!req.param('id')) return res.send(404);
			Model.find(req.param('id')).done(function(err, model) {
				if(err) return res.send(err, 500);
				else if(!model) return res.send(404);
				else return res.json(model);
			});
		},

		// Fetch paginated list of models from testtable
		findAll: function(req, res) {
			// Normalize WHERE parameter
			var where = applyFilter(req.param("sails_filter"), req.param('where') || req.param('search'));

			// If WHERE is a string, try to interpret it as JSON
			if (_.isString(where)) {
				where = sails.parseJSON(where);
			}

			// If other params are specified, assume they represent attributes to be searched on in the model
			var params;
			if (!where) {
				params = _.extend(req.query || {}, req.params || {}, req.body || {});
				params = applyFilter(req.param("sails_filter"),params);

				// Remove undefined params
				params = sails.util.objReject(params, function (param) {
					return _.isUndefined(param);
				});

				where = params;
			}

			// Build options object
			var options = {
				limit: req.param('limit') || undefined,
				skip: req.param('skip') || req.param('offset') || undefined,
				sort: req.param('sort') || req.param('order') || undefined,
				where: where || undefined
			};

			// Respond to queries
			var finding = Model.findAll(options);

			finding.done(function afterFound(err, models) {
				if(err) return res.send(err, 500);
				if(!models) return res.send(404);

				// Subscribe to the models that were returned
				Model.subscribe(req, models);

				return res.json(models);
			});
		},

		// Store a new model
		create: function(req, res) {
			// Create monolithic parameter object
			var params = _.extend(req.query || {}, req.params || {}, req.body || {});
			params = applyFilter(req.param("sails_filter"),params);

			Model.create(params).done(function(err, model) {
				if(err) return res.send(err, 500);

				// Broadcast success message<commit_msg>Patch fixes limit, sort, and skip for api scaffolds.<commit_after>exports.definition = function(modelName) {
	var Model = sails.models[modelName];
	return {
		// Call findAll, unless this is a basic request, then render the index view
		index: function(req, res) {
			if(req.isAjax || req.isSocket) {
				if(req.param('id')) this.find(req, res);
				else this.findAll(req, res);
			} else res.view();
		},

		// Fetch a single model from testtable
		find: function(req, res) {
			if(!req.param('id')) return res.send(404);
			Model.find(req.param('id')).done(function(err, model) {
				if(err) return res.send(err, 500);
				else if(!model) return res.send(404);
				else return res.json(model);
			});
		},

		// Fetch paginated list of models from testtable
		findAll: function(req, res) {
			// Normalize WHERE parameter
			var where = applyFilter(req.param("sails_filter"), req.param('where') || req.param('search'));

			// If WHERE is a string, try to interpret it as JSON
			if (_.isString(where)) {
				where = sails.parseJSON(where);
			}

			// If other params are specified, assume they represent attributes to be searched on in the model
			var params;
			if (!where) {
				params = _.extend(req.query || {}, req.params || {}, req.body || {});
				params = applyFilter(req.param("sails_filter"),params);

				// Remove undefined params
				// as well as limit, skip, and sort
				params = sails.util.objReject(params, function (param, key) {
					return _.isUndefined(param) ||
						key === 'limit' || key === 'skip' || key === 'sort';
				});

				where = params;
			}


			// Build options object
			var options = {
				limit: req.param('limit') || undefined,
				skip: req.param('skip') || req.param('offset') || undefined,
				sort: req.param('sort') || req.param('order') || undefined,
				where: where || undefined
			};


			// Respond to queries
			var finding = Model.findAll(options);

			finding.done(function afterFound(err, models) {
				if(err) return res.send(err, 500);
				if(!models) return res.send(404);

				// Subscribe to the models that were returned
				Model.subscribe(req, models);

				return res.json(models);
			});
		},

		// Store a new model
		create: function(req, res) {
			// Create monolithic parameter object
			var params = _.extend(req.query || {}, req.params || {}, req.body || {});
			params = applyFilter(req.param("sails_filter"),params);

			Model.create(params).done(function(err, model) {
				if(err) return res.send(err, 500);

				// Broadcast success message
{'fraction_non_alphanumeric': 0.15628192032686414, 'fraction_numerical': 0.007354443309499489, 'mean_word_length': 3.2610966057441253, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7029429', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1502, 'n_words': 421}