Skip to content

Commit

Permalink
Use knex for all application access of interaction steps.
Browse files Browse the repository at this point in the history
  • Loading branch information
bchrobot committed Jun 25, 2019
1 parent 197f508 commit ab8a9a7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
28 changes: 18 additions & 10 deletions src/server/api/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,31 @@ export const resolvers = {
text: async interactionStep => interactionStep.question,
answerOptions: async interactionStep =>
r
.table("interaction_step")
.filter({ parent_interaction_id: interactionStep.id })
.filter({ is_deleted: false })
.knex("interaction_step")
.select("*")
.where({
parent_interaction_id: interactionStep.id,
is_deleted: false
})
.orderBy("answer_option")
.map({
value: r.row("answer_option"),
action: r.row("answer_actions"),
interaction_step_id: r.row("id"),
parent_interaction_step: r.row("parent_interaction_id")
}),
.then(answerOptions =>
answerOptions.map(answerOption => ({
value: answerOption.answer_option,
action: answerOption.answer_actions,
interaction_step_id: answerOption.id,
parent_interaction_step: answerOption.parent_interaction_id
}))
),
interactionStep: async interactionStep => interactionStep
},
AnswerOption: {
value: answer => answer.value,
interactionStepId: answer => answer.interaction_step_id,
nextInteractionStep: async answer =>
r.table("interaction_step").get(answer.interaction_step_id),
r
.knex("interaction_step")
.first("*")
.where({ id: answer.interaction_step_id }),
responders: async answer =>
r
.table("question_response")
Expand Down
9 changes: 6 additions & 3 deletions src/server/models/cacheable_queries/campaign.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ const dbCustomFields = async id => {

const dbInteractionSteps = async id => {
return r
.table("interaction_step")
.getAll(id, { index: "campaign_id" })
.filter({ is_deleted: false });
.knex("interaction_step")
.select("*")
.where({
campaign_id: id,
is_deleted: false
});
};

const clear = async id => {
Expand Down
5 changes: 3 additions & 2 deletions src/workers/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,9 @@ export async function exportCampaign(job) {
const allQuestions = {};
const questionCount = {};
const interactionSteps = await r
.table("interaction_step")
.getAll(id, { index: "campaign_id" });
.knex("interaction_step")
.select("*")
.where({ campaign_id: id });

interactionSteps.forEach(step => {
if (!step.question || step.question.trim() === "") {
Expand Down

0 comments on commit ab8a9a7

Please sign in to comment.