Changeset View
Changeset View
Standalone View
Standalone View
lib/subject/subject-types/collection-subject.js
Show First 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | |||||
CollectionSubject.prototype.__create_resource = function( | CollectionSubject.prototype.__create_resource = function( | ||||
datastore, | datastore, | ||||
collection, | collection, | ||||
context, | context, | ||||
body | body | ||||
) { | ) { | ||||
return collection | return collection | ||||
.check_if_action_is_allowed(context, "create", { body: body }) | .check_if_action_is_allowed(context, "create", body) | ||||
.then(function() { | .then(function() { | ||||
return collection.validate_field_values(context, true, body); | return collection.validate_field_values(context, true, body); | ||||
}) | }) | ||||
.then(function() { | .then(function() { | ||||
return collection.encode_field_values(context, body); | return collection.encode_field_values(context, body); | ||||
}) | }) | ||||
.then(function(encoded_body) { | .then(function(encoded_body) { | ||||
const newID = shortid(); | const newID = shortid(); | ||||
const resource_data = { | const resource_data = { | ||||
sealious_id: newID, | _metadata: { | ||||
collection: collection.name, | collection: collection.name, | ||||
body: encoded_body, | |||||
created_context: context, | created_context: context, | ||||
last_modified_context: context, | last_modified_context: context, | ||||
}, | |||||
sealious_id: newID, | |||||
...encoded_body, | |||||
}; | }; | ||||
return datastore.insert(collection.name, resource_data, {}); | return datastore.insert(collection.name, resource_data, {}); | ||||
}) | }) | ||||
.then(function(database_entry) { | .then(function(database_entry) { | ||||
return collection.get_resource_representation( | return collection.get_resource_representation( | ||||
context, | context, | ||||
database_entry | database_entry | ||||
); | ); | ||||
▲ Show 20 Lines • Show All 178 Lines • Show Last 20 Lines |