diff --git a/lib/helpers/montaineSaving.js b/lib/helpers/montaineSaving.js index 380a82191..1b61d59ab 100644 --- a/lib/helpers/montaineSaving.js +++ b/lib/helpers/montaineSaving.js @@ -27,3 +27,15 @@ exports.saving = (json, date) => { } throw new AppError('Saving failed', { code: 'HELPERS_ERROR' }); }; + +exports.getKeyForMerge = (json) => { + let result; + if (Array.isArray(json)) { + result = Object.keys(json[0]); + result = _.remove(result, (k) => k.charAt(0) === '@'); + } if (typeof example === 'object' && typeof data === 'object') { + result = Object.keys(json); + result = _.remove(result, (k) => k.charAt(0) === '@'); + } + return result; +}; diff --git a/modules/apis/services/apis.service.js b/modules/apis/services/apis.service.js index 582dc68cd..36afcce67 100644 --- a/modules/apis/services/apis.service.js +++ b/modules/apis/services/apis.service.js @@ -114,7 +114,7 @@ exports.load = async (api) => { // prepare for save if (result.result) { result.result = montaineSaving.saving(result.result, start); - await ApisRepository.import(_.camelCase(api.title), result.result, ['@id', '@date']); + await ApisRepository.import(_.camelCase(api.title), result.result, montaineSaving.getKeyForMerge(result.result)); } const history = await HistoryRepository.create(montaineRequest.setScrapHistory(result.request, api, start));