Merge pull request #956 from strapi/fix/upload

Fix uploaded file on create
This commit is contained in:
Jim LAURIE 2018-04-18 10:31:59 +02:00 committed by GitHub
commit 52f3da7266
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 8 deletions

View File

@ -59,7 +59,7 @@ module.exports = {
});
// Then, request plugin upload.
if (strapi.plugins.upload && !_.isEmpty(values.files)) {
if (strapi.plugins.upload && Object.keys(files).length > 0) {
// Upload new files and attach them to this entity.
await strapi.plugins.upload.services.upload.uploadToEntity({
id: entry.id || entry._id,

View File

@ -387,16 +387,29 @@ module.exports = {
[model.primaryKey]: 'String'
};
const globalId = model.globalId;
const _schema = _.cloneDeep(_.get(strapi.plugins, `graphql.config._schema.graphql`, {}));
if (!acc.resolver[globalId]) {
acc.resolver[globalId] = {};
}
// Add timestamps attributes.
if (_.get(model, 'options.timestamps') === true) {
Object.assign(initialState, {
created_at: 'String',
updated_at: 'String'
});
}
const globalId = model.globalId;
const _schema = _.cloneDeep(_.get(strapi.plugins, `graphql.config._schema.graphql`, {}));
Object.assign(acc.resolver[globalId], {
created_at: (obj, options, context) => {
return obj.createdAt || obj.created_at;
},
updated_at: (obj, options, context) => {
return obj.updatedAt || obj.updated_at;
}
});
}
// Retrieve user customisation.
const { type = {}, resolver = {} } = _schema;
@ -471,10 +484,6 @@ module.exports = {
// Build associations queries.
(model.associations || []).forEach(association => {
if (!acc.resolver[globalId]) {
acc.resolver[globalId] = {};
}
switch (association.nature) {
case 'manyMorphToOne':
case 'manyMorphToMany':