From b85e7313369ea9f354f509b28eb11dda5e24ce93 Mon Sep 17 00:00:00 2001 From: maxceem Date: Mon, 5 Oct 2020 17:06:31 +0300 Subject: [PATCH] fix: updating project with invalid templateId ref issue #582 --- src/models/projectTemplate.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/models/projectTemplate.js b/src/models/projectTemplate.js index 75c8fe48..604913af 100644 --- a/src/models/projectTemplate.js +++ b/src/models/projectTemplate.js @@ -43,6 +43,11 @@ module.exports = (sequelize, DataTypes) => { ProjectTemplate.getTemplate = templateId => ProjectTemplate.findByPk(templateId, { raw: true }) .then((template) => { + // if `template` is not found by `id` return `template` + if (!template) { + return template; // it suppose to be `null` or whatever `findByPk` returns in this case + } + const formRef = template.form; return formRef ? models.Form.findAll({ where: formRef, raw: true })