Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
schema.eachPath(function (path, schemaType) {
if (schemaType.schema) { // propagate plugin initialization for sub-documents schemas
schemaType.schema.plugin(mongooseIntl, pluginOptions);
return;
}
if (!schemaType.options.intl) {
return;
}
if (!(schemaType instanceof mongoose.Schema.Types.String)) {
throw new mongoose.Error('Mongoose-intl plugin can be used with String type only');
}
var pathArray = path.split('.'),
key = pathArray.pop(),
prefix = pathArray.join('.');
if (prefix) prefix += '.';
// removing real path, it will be changed to virtual later
schema.remove(path);
// schema.remove removes path from paths object only, but doesn't update tree
// sounds like a bug, removing item from the tree manually
var tree = pathArray.reduce(function (mem, part) {
return mem[part];
}, schema.tree);
LineString.prototype.cast = function(linestring) {
if (!linestring.type) {
throw new mongoose.Error('LineString must have a type');
}
// type must be LineString
if (linestring.type !== 'LineString') {
throw new mongoose.Error(linestring.type + ' is not a valid GeoJSON type');
}
// must have at least two Points
if (linestring.coordinates.length < 2) {
throw new mongoose.Error('LineString type must have at least two Points');
}
// check for crs
if (linestring.crs) {
crs = linestring.crs;
validateCrs(crs);
}
validateLineString(linestring.coordinates);
return linestring;
Point.prototype.cast = function(point) {
if (!point.type) {
throw new mongoose.Error('Point', point.type, 'point.type');
}
// type must be Point
if (point.type !== 'Point') {
throw new mongoose.Error(point.type + ' is not a valid GeoJSON type');
}
// check for crs
if (point.crs) {
crs = point.crs;
validateCrs(crs);
} else {
crs = undefined;
}
validatePoint(point.coordinates);
return point;
};
function validatePolygon(coordinates) {
for (var i = 0; i < coordinates.length; i++) {
// The LinearRing elements must have at least four Points
if (coordinates[i].length < 4) {
throw new mongoose.Error('Each Polygon LinearRing must have at least four elements');
}
// the LinearRing objects must have identical start and end values
if (!arraysEqual(coordinates[i][0], coordinates[i][coordinates[i].length-1])) {
throw new mongoose.Error('Each Polygon LinearRing must have an identical first and last point');
}
// otherwise the LinearRings must correspond to a LineString
validateLineString(coordinates[i]);
}
}
function validateFeature(feature) {
if (!feature.type) {
throw new mongoose.Error('Feature must have a type');
}
// type must be Feature
if (feature.type !== 'Feature') {
throw new mongoose.Error(feature.type + ' is not a valid GeoJSON type');
}
if (!feature.geometry) {
throw new mongoose.Error('Feature must have a geometry');
}
// check for crs
if (feature.crs) {
crs = feature.crs;
validateCrs(crs);
}
validateGeometry(feature.geometry);
}
FeatureCollection.prototype.cast = function(featurecollection) {
if (!featurecollection.type) {
throw new mongoose.Error('FeatureCollection must have a type');
}
// type must be Polygon
if (featurecollection.type !== 'FeatureCollection') {
throw new mongoose.Error(featurecollection.type + ' is not a valid GeoJSON type');
}
if (!featurecollection.features) {
throw new mongoose.Error('FeatureCollections must have a features object');
}
// check for crs
if (featurecollection.crs) {
crs = featurecollection.crs;
validateCrs(crs);
}
validateFeatureCollection(featurecollection);
return featurecollection;
};
export const getFavouritedSongs = async userId => {
try {
const favouritedSongs = await userModels.getFavouritedSongs(userId);
return favouritedSongs;
} catch (error) {
throw new Error("Can't get favourited songs");
}
};
return;
}
if (!crs.type) {
throw new mongoose.Error('Crs must have a type');
}
if (crs.type !== 'name' && crs.type !== 'link') {
throw new mongoose.Error('Crs must be either a name or link');
}
if (!crs.properties) {
throw new mongoose.Error('Crs must contain a properties object');
}
if (crs.type === 'name' && !crs.properties.name) {
throw new mongoose.Error('Crs specified by name must have a name property');
}
if (crs.type === 'link' && !crs.properties.href || crs.type === 'link' && !crs.properties.type) {
throw new mongoose.Error('Crs specified by link must have a name and href property');
}
}
validateMultiPoint(geometry.coordinates);
break;
case 'LineString':
validateLineString(geometry.coordinates);
break;
case 'MultiLineString':
validateMultiLineString(geometry.coordinates);
break;
case 'Polygon':
validatePolygon(geometry.coordinates);
break;
case 'MultiPolygon':
validateMultiPolygon(geometry.coordinates);
break;
default:
throw new mongoose.Error('Geometry must have a valid type');
}
}
function validateCrs(crs) {
if (typeof crs !== 'object' && crs !== null) {
throw new mongoose.Error('Crs must be an object or null');
}
if (crs === null) {
return;
}
if (!crs.type) {
throw new mongoose.Error('Crs must have a type');
}
if (crs.type !== 'name' && crs.type !== 'link') {
throw new mongoose.Error('Crs must be either a name or link');
}
if (!crs.properties) {
throw new mongoose.Error('Crs must contain a properties object');
}
if (crs.type === 'name' && !crs.properties.name) {
throw new mongoose.Error('Crs specified by name must have a name property');
}