From 9ebb19e030276871f751d62d41c48668fdc1b47e Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Fri, 21 Jun 2019 18:20:39 +0800 Subject: [PATCH] winning submission from challenge 30093923 - Topcoder Connect - Product template update --- migrations/20190620_migrate_product_templates.sql | 11 +++++++++++ src/routes/metadata/list.spec.js | 2 +- src/routes/productTemplates/upgrade.spec.js | 2 +- src/routes/projectUpgrade/create.js | 4 ++-- src/routes/projectUpgrade/create.spec.js | 2 +- 5 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 migrations/20190620_migrate_product_templates.sql diff --git a/migrations/20190620_migrate_product_templates.sql b/migrations/20190620_migrate_product_templates.sql new file mode 100644 index 00000000..fdd6631a --- /dev/null +++ b/migrations/20190620_migrate_product_templates.sql @@ -0,0 +1,11 @@ +-- +-- UPDATE EXISTING TABLES: +-- template: +-- remove `sections` if exists and change `questions` to `sections` + +-- +-- product_templates + +UPDATE product_templates +SET template = (template::jsonb #- '{questions}' #- '{sections}') || jsonb_build_object('sections', template::jsonb ->'questions') +WHERE template::jsonb ? 'questions'; diff --git a/src/routes/metadata/list.spec.js b/src/routes/metadata/list.spec.js index 6bbf9cb8..6b1b4565 100644 --- a/src/routes/metadata/list.spec.js +++ b/src/routes/metadata/list.spec.js @@ -111,7 +111,7 @@ const forms = [ { key: 'productKey 1', config: { - questions: [{ + sections: [{ id: 'appDefinition', title: 'Sample Project', required: true, diff --git a/src/routes/productTemplates/upgrade.spec.js b/src/routes/productTemplates/upgrade.spec.js index 0cdfa5d4..8fc41e5f 100644 --- a/src/routes/productTemplates/upgrade.spec.js +++ b/src/routes/productTemplates/upgrade.spec.js @@ -85,7 +85,7 @@ describe('UPGRADE product template', () => { ])) .then(() => { const config = { - questions: [{ + sections: [{ id: 'appDefinition', title: 'Sample Project', required: true, diff --git a/src/routes/projectUpgrade/create.js b/src/routes/projectUpgrade/create.js index 729f9117..9dbf318e 100644 --- a/src/routes/projectUpgrade/create.js +++ b/src/routes/projectUpgrade/create.js @@ -44,9 +44,9 @@ async function findCompletedProjectEndDate(projectId, transaction) { */ function applyTemplate(template, source, destination) { if (!template || typeof template !== 'object') { return; } - if (!template.questions || !template.questions.length) { return; } + if (!template.sections || !template.sections.length) { return; } // questions field is actually array of sections - const templateQuestions = template.questions; + const templateQuestions = template.sections; // loop through for every section templateQuestions.forEach((section) => { // find subsections diff --git a/src/routes/projectUpgrade/create.spec.js b/src/routes/projectUpgrade/create.spec.js index 9ab136e0..84ba5e5d 100644 --- a/src/routes/projectUpgrade/create.spec.js +++ b/src/routes/projectUpgrade/create.spec.js @@ -107,7 +107,7 @@ describe('Project upgrade', () => { alias2: [1, 2, 3], }, template: { - questions: [ + sections: [ { subSections: [ { fieldName: 'details.name' },