diff --git a/src/api/src/routes/admin-survey-router.ts b/src/api/src/routes/admin-survey-router.ts index a85d63d..547a54e 100644 --- a/src/api/src/routes/admin-survey-router.ts +++ b/src/api/src/routes/admin-survey-router.ts @@ -21,16 +21,23 @@ adminSurveyRouter.get("/", async (req: Request, res: Response) => { list = await db("SURVEY").withSchema(DB_SCHEMA).whereIn("SID", surveys); } else list = await db("SURVEY").withSchema(DB_SCHEMA); - for (let item of list) { - item.questions = await db("QUESTION").withSchema(DB_SCHEMA).where({ SID: item.SID }).orderBy("ORD"); - item.choices = await db("JSON_DEF").withSchema(DB_SCHEMA).where({ SID: item.SID }).orderBy("TITLE"); - item.responses = await db("PARTICIPANT") - .withSchema(DB_SCHEMA) - .innerJoin("PARTICIPANT_DATA", "PARTICIPANT.TOKEN", "PARTICIPANT_DATA.TOKEN") - .where({ SID: item.SID }) - .whereNotNull("RESPONSE_DATE"); + let allQuestions = await db("QUESTION").withSchema(DB_SCHEMA).orderBy("SID", "ORD"); + let allChoices = await db("JSON_DEF").withSchema(DB_SCHEMA).orderBy("SID", "TITLE"); + let allResponses = await db("PARTICIPANT") + .withSchema(DB_SCHEMA) + .innerJoin("PARTICIPANT_DATA", "PARTICIPANT.TOKEN", "PARTICIPANT_DATA.TOKEN") + .whereNotNull("RESPONSE_DATE"); + let allConditions = await db("Q_CONDITION_TBL").withSchema(DB_SCHEMA); + for (let item of list) { + item.questions = allQuestions.filter((q) => q.SID == item.SID); + item.choices = allChoices.filter((c) => c.SID == item.SID); + item.responses = allResponses.filter((r) => r.SID == item.SID); item.choices.map((c: any) => (c.choices = JSON.parse(c.SELECTION_JSON))); + + for (let q of item.questions) { + q.conditions = allConditions.filter((c) => c.QID == q.QID); + } } res.json({ data: list }); @@ -144,6 +151,20 @@ adminSurveyRouter.put("/:SID/question/:QID/order", async (req: Request, res: Res res.json({ data: "success" }); }); +adminSurveyRouter.put("/:SID/question/:QID/conditions", async (req: Request, res: Response) => { + let { QID } = req.params; + let { conditions } = req.body; + + await db("Q_CONDITION_TBL").withSchema(DB_SCHEMA).where({ QID }).delete(); + + for (let cond of conditions) { + delete cond.COND_ID; + await db("Q_CONDITION_TBL").withSchema(DB_SCHEMA).insert(cond); + } + + res.json({ data: "success" }); +}); + adminSurveyRouter.put("/:SID/question/:QID", async (req: Request, res: Response) => { let { SID, QID } = req.params; let { ASK, OPTIONAL, ORD, TYPE, RANGE, GROUP_ID, JSON_ID, SELECT_LIMIT, choices, choiceTitle } = req.body; diff --git a/src/api/src/routes/survey-router.ts b/src/api/src/routes/survey-router.ts index 1cc9024..57608d1 100644 --- a/src/api/src/routes/survey-router.ts +++ b/src/api/src/routes/survey-router.ts @@ -37,6 +37,7 @@ surveyRouter.get( } for (let q of questions) { + q.conditions = await db("Q_CONDITION_TBL").withSchema(DB_SCHEMA).where({ QID: q.QID }); if (q.JSON_ID) { q.choices = choices.find((c) => c.JSON_ID == q.JSON_ID)?.choices; } @@ -68,6 +69,7 @@ surveyRouter.get( let questions = await db("QUESTION").withSchema(DB_SCHEMA).where({ SID: token }).orderBy("ORD"); for (let q of questions) { + q.conditions = await db("Q_CONDITION_TBL").withSchema(DB_SCHEMA).where({ QID: q.QID }); if (q.JSON_ID) { q.choices = choices.find((c) => c.JSON_ID == q.JSON_ID)?.choices; } diff --git a/src/web/src/components/QuestionRenderer.vue b/src/web/src/components/QuestionRenderer.vue index 2708f5b..95925ad 100644 --- a/src/web/src/components/QuestionRenderer.vue +++ b/src/web/src/components/QuestionRenderer.vue @@ -99,10 +99,10 @@
{{ survey.survey.PAGE_INTRO }}
@@ -30,7 +31,11 @@