Skip to content

Commit

Permalink
For testing build
Browse files Browse the repository at this point in the history
  • Loading branch information
datajohnson committed Mar 4, 2024
1 parent 17daa94 commit 3e5dfac
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/api/src/routes/admin-participant-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ adminParticipantRouter.delete("/:TOKEN", async (req: Request, res: Response) =>

await db("SRVT.PARTICIPANT").where({ TOKEN }).delete();
await db("SRVT.PARTICIPANT_DATA").where({ TOKEN }).delete();
// delete demographic also

res.json({ data: {} });
});

function makeToken() {
const chars = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890";
const randomArray = Array.from({ length: 24 }, (v, k) => chars[Math.floor(Math.random() * chars.length)]);
const randomArray = Array.from({ length: 61 }, (v, k) => chars[Math.floor(Math.random() * chars.length)]);

const randomString = randomArray.join("");
return randomString;
Expand Down
23 changes: 23 additions & 0 deletions src/api/src/routes/admin-survey-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,31 @@ adminSurveyRouter.post("/:SID/send-email", async (req: Request, res: Response) =

for (let p of participants) {
await emailer.sendEmail(p.EMAIL, p.TOKEN, subject, body);

await recordSentDate(p);
}

res.json({ data: `Sent ${participants.length} emails` });
});

adminSurveyRouter.post("/:SID/resend/:TOKEN", async (req: Request, res: Response) => {
let { SID, TOKEN } = req.params;
let { subject, body } = req.body;

//let survey = await db("SRVT.SURVEY").where({ SID }).first();

let query = await db("SRVT.PARTICIPANT")
.join("SRVT.PARTICIPANT_DATA", "PARTICIPANT.TOKEN", "PARTICIPANT_DATA.TOKEN")
.where({ "PARTICIPANT.TOKEN": TOKEN })
.whereNull("RESPONSE_DATE")
.whereNotNull("EMAIL")
.select("EMAIL", "PARTICIPANT.TOKEN");

let emailer = new EmailService();

for (let p of query) {
await emailer.sendEmail(p.EMAIL, p.TOKEN, subject, body);
}

return res.json({ data: `Sent ${query.length} emails` });
});
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default {
participantTypeOptions() {
return [
{ title: `Recipients who haven't been sent yet - ${this.sendCount.length} recipients`, value: "SEND" },
{ title: `Recipients who needa reminder - ${this.resendCount.length} recipients`, value: "RESEND" },
{ title: `Recipients who need a reminder - ${this.resendCount.length} recipients`, value: "RESEND" },
];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineStore } from "pinia";

import { useNotificationStore } from "@/store/NotificationStore";
import { useApiStore } from "@/store/ApiStore";
import { PARTICIPANT_URL } from "@/urls";
import { ADMIN_SURVEY_URL, PARTICIPANT_URL } from "@/urls";

let m = useNotificationStore();
let api = useApiStore();
Expand Down Expand Up @@ -107,6 +107,15 @@ export const useParticipantsStore = defineStore("participants", {
})
.catch();
},

async manualSend(surveyId: number, id: number) {
await api
.secureCall("post", `${ADMIN_SURVEY_URL}/${surveyId}/resend/${id}`)
.then(async (resp) => {
m.notify({ variant: "success", text: "Email sent" });
})
.catch();
},
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,34 @@
<v-data-table :search="search" :headers="headers" :items="participants">
<template v-slot:item.actions="{ item }">
<div v-if="item.EMAIL">
<v-btn icon="mdi-delete" variant="tonal" color="warning" size="x-small" @click="deleteClick(item.TOKEN)"></v-btn>
<v-btn
icon="mdi-delete"
variant="tonal"
color="warning"
size="x-small"
@click="deleteClick(item.TOKEN)"></v-btn>
</div>
</template>
<template v-slot:item.email="{ item }">
<div v-if="item.EMAIL">
<v-btn
icon="mdi-email"
variant="tonal"
color="warning"
size="x-small"
@click="emailClick(item.TOKEN)"></v-btn>
</div>
</template>

<template v-slot:item.SENT_DATE="{item}">
<template v-slot:item.SENT_DATE="{ item }">
{{ formatDate(item.SENT_DATE) }}
</template>
<template v-slot:item.RESENT_DATE="{item}">
<template v-slot:item.RESENT_DATE="{ item }">
{{ formatDate(item.RESENT_DATE) }}
</template>
<template v-slot:item.RESPONSE_DATE="{item}">
<template v-slot:item.RESPONSE_DATE="{ item }">
{{ formatDate(item.RESPONSE_DATE) }}
</template>

</v-data-table>

<v-dialog v-model="visible" persistent max-width="700">
Expand All @@ -73,6 +87,12 @@
<v-btn icon @click="closeEditor" color="white"><v-icon>mdi-close</v-icon></v-btn>
</v-toolbar>
<v-card-text>
<v-text-field label="Token prefix" />
<v-file-input
variant="outlined"
density="comfortable"
accept="text/csv"
label="Choose a CSV to import"></v-file-input>
<v-textarea
v-model="batch.participants"
variant="outlined"
Expand Down Expand Up @@ -109,6 +129,7 @@ export default {
{ title: "Sent Date", key: "SENT_DATE" },
{ title: "Resent Date", key: "RESENT_DATE" },
{ title: "Response Date", key: "RESPONSE_DATE" },
{ title: "", key: "email", width: "60px" },
],
search: "",
parseMessage: "",
Expand Down Expand Up @@ -145,7 +166,14 @@ export default {
this.unselect();
},
methods: {
...mapActions(useParticipantsStore, ["parse", "create", "getParticipants", "deleteParticipant", "unselect"]),
...mapActions(useParticipantsStore, [
"parse",
"create",
"getParticipants",
"deleteParticipant",
"unselect",
"manualSend",
]),
...mapActions(useAdminSurveyStore, ["loadSurveys"]),
async loadItems() {
Expand All @@ -167,6 +195,9 @@ export default {
async deleteClick(participantId: any) {
await this.deleteParticipant(this.batch.survey, participantId);
},
async emailClick(participantId: any) {
await this.manualSend(this.batch.survey, participantId);
},
formatDate(input: any) {
if (input) return moment(input).format("YYYY-MM-DD @ hh:mm a");
return "";
Expand Down

0 comments on commit 3e5dfac

Please sign in to comment.