Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let word = 'hour';
// display minutes if next sync in < 1 hr
if (hours < 1) {
let minutes = Math.round(hours * 60);
word = 'minute';
if (minutes === 0) {
minutes = 1;
}
hours = minutes;
}
if (hours !== 1) {
word = pluralize(word);
}
// display hours
return `${Math.round(hours)} ${word}`;
}),
export function getSpaceForCard(type, id) {
return getContext()
.owner.lookup('service:store')
.findRecord('space', `/${pluralize(type)}/${id}`);
}
export function osfToManyRelationship(
server: Server,
parentModelName: K,
relationshipName: string & RelationshipsFor,
options?: Partial,
) {
const opts: RelationshipOptions = Object.assign({
path: `/${pluralize(underscore(parentModelName))}/:parentID/relationships/${underscore(relationshipName)}`,
relatedModelName: relationshipName,
defaultSortKey: '-id',
}, options);
const mirageParentModelName = pluralize(camelize(parentModelName));
const actions = gatherRelationshipActions(opts);
if (actions.includes('related')) {
const relationshipRelatedPath = opts.path.replace('relationships/', '');
server.get(relationshipRelatedPath, function(schema, request) {
const data = schema[mirageParentModelName]
.find(request.params.parentID)[relationshipName]
.models
.filter((m: ModelInstance) => filter(m, request))
.map((model: ModelInstance) => this.serialize(model).data);
return process(schema, request, this, data, { defaultSortKey: opts.defaultSortKey });
});
routeForNew(type) {
type = pluralize(type);
return {
name: 'cardstack.new-content',
params: [['type', type]],
};
},
doc._document._included = hasManyRelationships.reduce((c, e, i) => {
c[pluralize(e.key)] = includes[i];
return c;
}, {});
return Promise.all([
let relation = this.get('relationships.' + related);
if (Array.isArray(relation.data)) {
for (let i = 0; i < relation.data.length; i++) {
if (relation.data[i].id === id) {
relation.data.splice(i, 1);
this._relationRemoved(related, id);
break;
}
}
let resources = this.get(related);
let idx = resources.mapBy('id').indexOf(id);
if (idx > -1) {
resources.removeAt(idx);
}
} else if (typeof relation === 'object') {
if (relation.data.type === pluralize(related) && relation.data.id === id) {
this._relationRemoved(related, id);
}
relation.data = null;
this.set(`${related}.content`, null);
}
},
async _getContentType(type) {
if (this._contentTypeCache[type]) {
return await this._contentTypeCache[type];
}
this._contentTypeCache[type] = this.get('store').findRecord('content-type', pluralize(type));
return await this._contentTypeCache[type];
},
pathForType(modelName: string): string {
const underscored: string = underscore(modelName);
return pluralize(underscored);
}
export function osfToManyRelationship(
server: Server,
parentModelName: K,
relationshipName: string & RelationshipsFor,
options?: Partial,
) {
const opts: RelationshipOptions = Object.assign({
path: `/${pluralize(underscore(parentModelName))}/:parentID/relationships/${underscore(relationshipName)}`,
relatedModelName: relationshipName,
defaultSortKey: '-id',
}, options);
const mirageParentModelName = pluralize(camelize(parentModelName));
const actions = gatherRelationshipActions(opts);
if (actions.includes('related')) {
const relationshipRelatedPath = opts.path.replace('relationships/', '');
server.get(relationshipRelatedPath, function(schema, request) {
const data = schema[mirageParentModelName]
.find(request.params.parentID)[relationshipName]
.models
.filter((m: ModelInstance) => filter(m, request))
.map((model: ModelInstance) => this.serialize(model).data);
return process(schema, request, this, data, { defaultSortKey: opts.defaultSortKey });
});
}
if (actions.includes('add')) {
server.post(opts.path, (schema: Schema, request: Request) => {
keyForRelationship(attr, relationshipType) {
const key = `${singularize(attr)
.camelize()
.capitalize()}ID`;
return relationshipType === 'hasMany' ? pluralize(key) : key;
},