Skip to content

Product templates use sections #317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions migrations/20190620_migrate_product_templates.sql
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 1 addition & 1 deletion src/routes/metadata/list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const forms = [
{
key: 'productKey 1',
config: {
questions: [{
sections: [{
id: 'appDefinition',
title: 'Sample Project',
required: true,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/productTemplates/upgrade.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('UPGRADE product template', () => {
]))
.then(() => {
const config = {
questions: [{
sections: [{
id: 'appDefinition',
title: 'Sample Project',
required: true,
Expand Down
4 changes: 2 additions & 2 deletions src/routes/projectUpgrade/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/routes/projectUpgrade/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('Project upgrade', () => {
alias2: [1, 2, 3],
},
template: {
questions: [
sections: [
{
subSections: [
{ fieldName: 'details.name' },
Expand Down