Changeset View
Changeset View
Standalone View
Standalone View
lib/app/base-chips/field-types/file-reference.js
module.exports = function(app) { | module.exports = function(app) { | ||||
return { | return { | ||||
name: "file_reference", | name: "file_reference", | ||||
is_proper_value: function(context, params, value) { | is_proper_value(context, params, value) { | ||||
return app.Datastore.find("files", { id: value }).then(function( | return app.Datastore.find("files", { id: value }).then(results => { | ||||
results | if (results.length) { | ||||
) { | |||||
if (results.length === 0) { | |||||
return Promise.reject("Bad file id: " + value); | |||||
} else { | |||||
return Promise.resolve(); | return Promise.resolve(); | ||||
} | } | ||||
return Promise.reject(`Bad file id: ${value}`); | |||||
}); | }); | ||||
}, | }, | ||||
format: function(context, params, file_id, format) { | format(context, params, file_id, format) { | ||||
if (format === "internal") { | if (format === "internal") { | ||||
return app.Datastore.find("files", { id: file_id }).then( | return app.Datastore.find("files", { id: file_id }).then( | ||||
a => a[0] | a => a[0] | ||||
); | ); | ||||
} else { | |||||
return file_id; | |||||
} | } | ||||
return file_id; | |||||
}, | }, | ||||
}; | }; | ||||
}; | }; |