Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var Resource = exports.Resource = function( base, controller ){
var controller_slug = inflection.underscore(inflection.pluralize(controller))
this.routes = []
// set up the actual routes for the resource
this.routes.push(
this.collection_route =
base.get('/'+controller_slug+'(.:format)', 'GET').to(controller+'.index')
, base.post('/'+controller_slug+'(.:format)', 'POST').to(controller+'.create')
, base.get('/'+controller_slug+'/add(.:format)', 'GET').to(controller+'.add')
, this.member_route =
base.get('/'+controller_slug+'/:id(.:format)', 'GET').to(controller+'.show')
, base.get('/'+controller_slug+'/:id/edit(.:format)', 'GET').to(controller+'.edit')
, base.put('/'+controller_slug+'/:id(.:format)', 'PUT').to(controller+'.update')
, base.del('/'+controller_slug+'/:id(.:format)', 'DELETE').to(controller+'.destroy')
)
this.collection_route.collection = true
function getColumnDetails(column) {
logger.debug('column details are calculated for: %s', column.name());
var result = filterAttributes({
source : 'generator',
accessorName : getSpecificConfig(column.table().name(), 'generate.columnAccessorCamelCase') ? inflection.camelize(inflection.underscore(column.name()), true) : column.name(),
name : column.name(),
primaryKey : column.isPrimaryKey(),
autoIncrement : column.isAutoIncrement() && getSpecificConfig(column.table().name(), 'generate.columnAutoIncrement') ? true : undefined,
allowNull : column.allowNull(),
defaultValue : getSpecificConfig(column.table().name(), 'generate.columnDefault') && column.default() !== null ? clearDefaultValue(column.default()) : undefined,
unique : column.unique(),
comment : getSpecificConfig(column.table().name(), 'generate.columnDescription') ? column.description() : undefined,
references : column.foreignKeyConstraint() ? getModelNameFor(column.foreignKeyConstraint().referencesTable()) : undefined,
referencesKey : column.foreignKeyConstraint() ? column.foreignKeyConstraint().foreignKey(0).name() : undefined,
onUpdate : column.onUpdate(),
onDelete : column.onDelete()
});
result.type = sequelizeType(column, getSpecificConfig(column.table().name(), 'generate.dataTypeVariable')); // To prevent type having quotes.
//result.type = column.sequelizeType(getSpecificConfig(column.table().name(), 'generate.dataTypeVariable')); // To prevent type having quotes.
return result;
inputName() {
if (this.props.name) {
return `${this.props.name}[]`
} else if (this.props.model) {
return `${this.props.model.modelClassData().paramKey}[${inflection.underscore(this.props.attribute)}]`
}
}
selectColumns(originalSelect) {
const newSelect = {}
for(const originalModelName in originalSelect) {
const newModelName = inflection.dasherize(inflection.underscore(originalModelName))
const newValues = []
const originalValues = originalSelect[originalModelName]
for(const originalAttributeName of originalValues) {
const newAttributeName = inflection.underscore(originalAttributeName)
newValues.push(newAttributeName)
}
newSelect[newModelName] = newValues
}
return this._clone({selectColumns: newSelect})
}
function underscore(str) {
return inflection.underscore(str);
}
exports.underscore = underscore;
inputName() {
if (this.props.name) {
return this.props.name
} else if (this.props.model) {
return `${this.props.model.modelClassData().paramKey}[${inflection.underscore(this.props.attribute)}]`
}
}
function underscore(str) {
return inflection.underscore(str);
}
exports.underscore = underscore;
params() {
let params = {}
if (this.queryArgs.params) params = this._merge(params, this.queryArgs.params)
if (this.queryArgs.abilities) params.abilities = this.queryArgs.abilities
if (this.queryArgs.accessibleBy) params.accessible_by = inflection.underscore(this.queryArgs.accessibleBy)
if (this.queryArgs.count) params.count = this.queryArgs.count
if (this.queryArgs.distinct) params.distinct = this.queryArgs.distinct
if (this.queryArgs.groupBy) params.group_by = this.queryArgs.groupBy
if (this.queryArgs.ransack) params.q = this.queryArgs.ransack
if (this.queryArgs.limit) params.limit = this.queryArgs.limit
if (this.queryArgs.preload) params.preload = this.queryArgs.preload
if (this.queryArgs.page) params.page = this.queryArgs.page
if (this.queryArgs.per) params.per = this.queryArgs.per
if (this.queryArgs.select) params.select = this.queryArgs.select
if (this.queryArgs.selectColumns) params.select_columns = this.queryArgs.selectColumns
return params
}