Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
newParentNewChildren() {
let user = this.schema[pluralize(this.ownModel)].new();
let newHomeAddress = user[`new${singularize(capitalize(this.ownKey))}`]();
return [user, [newHomeAddress]];
}
savedParentMixedChildren() {
let insertedUser = this.db[pluralize(this.ownModel)].insert({ name: 'Link' });
let insertedHomeAddress = this.db[pluralize(this.otherModel)].insert({ name: '123 Hyrule Way', [`${camelize(this.otherKey)}Id`]: insertedUser.id });
let user = this.schema[pluralize(this.ownModel)].find(insertedUser.id);
let savedHomeAddress = this.schema[pluralize(this.otherModel)].find(insertedHomeAddress.id);
let newHomeAddress = user[`new${singularize(capitalize(this.ownKey))}`]();
return [user, [savedHomeAddress, newHomeAddress]];
}
newParentNoChildren() {
let user = this.schema[pluralize(this.ownModel)].new();
return [user, []];
}
newParentSavedChildren() {
let insertedHomeAddress = this.db[pluralize(this.otherModel)].insert({ name: '123 Hyrule Way' });
let savedHomeAddress = this.schema[pluralize(this.otherModel)].find(insertedHomeAddress.id);
let newUser = this.schema[pluralize(this.ownModel)].new({ [this.ownKey]: [savedHomeAddress] });
return [newUser, [savedHomeAddress]];
}
newParentMixedChildren() {
let insertedHomeAddress = this.db[pluralize(this.otherModel)].insert({ name: '123 Hyrule Way' });
let savedHomeAddress = this.schema[pluralize(this.otherModel)].find(insertedHomeAddress.id);
let newHomeAddress = this.schema[pluralize(this.otherModel)].new();
let newUser = this.schema[pluralize(this.ownModel)].new({ [this.ownKey]: [savedHomeAddress, newHomeAddress] });
return [newUser, [savedHomeAddress, newHomeAddress]];
}
newParentSavedChildren() {
let insertedHomeAddress = this.db[pluralize(this.otherModel)].insert({ name: '123 Hyrule Way' });
let savedHomeAddress = this.schema[pluralize(this.otherModel)].find(insertedHomeAddress.id);
let newUser = this.schema[pluralize(this.ownModel)].new({ [this.ownKey]: [savedHomeAddress] });
return [newUser, [savedHomeAddress]];
}
handleStringShorthand(string, dbOrSchema, request) {
let type = string;
let collection = pluralize(string);
let attrs = this._getAttrsForRequest(request);
if (dbOrSchema instanceof Db) {
let db = dbOrSchema;
if (!db[collection]) {
console.error("Mirage: The route handler for " + request.url + " is trying to insert data into the " + collection + " collection, but that collection doesn't exist. To create it, create an empty fixture file or factory.");
}
let model = db[collection].insert(attrs);
let response = {};
response[type] = model;
return response;
} else {
function lookUpRelatedRecords(db, fieldName, isList, record, type) {
let relatedTable = isList ? fieldName : pluralize(fieldName);
let relatedRecords = filterRelatedByRecord(db[relatedTable], record, type);
return isList ? relatedRecords : relatedRecords[0];
}
const mockFn = (db, varsMap, fieldsMap = {}) => (root, vars, _, meta = {}) => {
let isList = getIsList(meta);
let type = getTypeFromMeta(meta, isList);
let { _fields: fields } = type;
let typeName = camelize(type.name);
let records = db[pluralize(typeName)];
records = filterRecordsByVars(records, vars, varsMap[type]);
records = getRelatedRecords(records, typeName, fields, fieldsMap[type], db);
records = filterRecordsByMappedField(records, meta.fieldName, fieldsMap);
return isList ? records : records[0];
};