From 1c24d2ab1213591f220472272cd5a7eb77b2f32c Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Fri, 13 Dec 2019 12:57:17 +0800 Subject: [PATCH] fix: temporary fix to index TaaS project with skills --- src/events/projects/index.js | 12 ++++++++++++ src/routes/admin/project-index-create.js | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/src/events/projects/index.js b/src/events/projects/index.js index 5bd0e150..976bbbdf 100644 --- a/src/events/projects/index.js +++ b/src/events/projects/index.js @@ -41,6 +41,10 @@ const indexProject = Promise.coroutine(function* (logger, msg) { // eslint-disab // removes non required fields from phase objects data.phases = data.phases.map(phase => _.omit(phase, ['deletedAt', 'deletedBy'])); } + // TEMPORARY FIX: should fix ES mapping instead and reindex all the projects instead + if (typeof _.get(data, 'details.taasDefinition.team.skills') !== 'string') { + _.set(data, 'details.taasDefinition.team.skills', ''); + } // add the record to the index const result = yield eClient.index({ index: ES_PROJECT_INDEX, @@ -91,6 +95,10 @@ const projectUpdatedHandler = Promise.coroutine(function* (logger, msg, channel) // first get the existing document and than merge the updated changes and save the new document const doc = yield eClient.get({ index: ES_PROJECT_INDEX, type: ES_PROJECT_TYPE, id: data.original.id }); const merged = _.merge(doc._source, data.updated); // eslint-disable-line no-underscore-dangle + // TEMPORARY FIX: should fix ES mapping instead and reindex all the projects instead + if (typeof _.get(merged, 'details.taasDefinition.team.skills') !== 'string') { + _.set(merged, 'details.taasDefinition.team.skills', ''); + } // update the merged document yield eClient.update({ index: ES_PROJECT_INDEX, @@ -173,6 +181,10 @@ async function projectUpdatedKafkaHandler(app, topic, payload) { try { const doc = await eClient.get({ index: ES_PROJECT_INDEX, type: ES_PROJECT_TYPE, id: previousValue.id }); const merged = _.merge(doc._source, project.get({ plain: true })); // eslint-disable-line no-underscore-dangle + // TEMPORARY FIX: should fix ES mapping instead and reindex all the projects instead + if (typeof _.get(merged, 'details.taasDefinition.team.skills') !== 'string') { + _.set(merged, 'details.taasDefinition.team.skills', ''); + } // update the merged document await eClient.update({ index: ES_PROJECT_INDEX, diff --git a/src/routes/admin/project-index-create.js b/src/routes/admin/project-index-create.js index a6f8dfb8f9..1d405aa0 100644 --- a/src/routes/admin/project-index-create.js +++ b/src/routes/admin/project-index-create.js @@ -97,6 +97,10 @@ module.exports = [ projectResponses.map((p) => { if (p) { body.push({ index: { _index: indexName, _type: docType, _id: p.id } }); + // TEMPORARY FIX: should fix ES mapping instead and reindex all the projects instead + if (typeof _.get(p, 'details.taasDefinition.team.skills') !== 'string') { + _.set(p, 'details.taasDefinition.team.skills', ''); + } body.push(p); } // dummy return