From f7b41dbc01d9dc064d69815fbcebdfce2e6daa95 Mon Sep 17 00:00:00 2001 From: Aurelsicoko Date: Tue, 17 Apr 2018 17:50:23 +0200 Subject: [PATCH 1/2] Fix uploaded file on create --- .../strapi-plugin-content-manager/services/ContentManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/strapi-plugin-content-manager/services/ContentManager.js b/packages/strapi-plugin-content-manager/services/ContentManager.js index a0d1f55fdf..b18f3d6392 100644 --- a/packages/strapi-plugin-content-manager/services/ContentManager.js +++ b/packages/strapi-plugin-content-manager/services/ContentManager.js @@ -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, From f01b7befd156c862bb8843b72523ba6aceffe59e Mon Sep 17 00:00:00 2001 From: Aurelsicoko Date: Tue, 17 Apr 2018 18:16:31 +0200 Subject: [PATCH 2/2] Display createdAt and updatedAt date with GraphQL --- .../strapi-plugin-graphql/services/GraphQL.js | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/strapi-plugin-graphql/services/GraphQL.js b/packages/strapi-plugin-graphql/services/GraphQL.js index 8208492969..814ae72311 100644 --- a/packages/strapi-plugin-graphql/services/GraphQL.js +++ b/packages/strapi-plugin-graphql/services/GraphQL.js @@ -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':