Skip to content
New issue

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

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

Already on GitHub? # to your account

Modify the SMS API to upsert a Reminder document when a Courtbot VT user subscribes to receiving a court notification. #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
22 changes: 20 additions & 2 deletions pages/api/sms/[instance]/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,19 @@ const handleText = async (req:NextApiRequest, res:NextApiResponse, input:string,
// let's check for a yes
if (response.toLowerCase() === 'yes') {
let c = cases[0];
await ReminderDao.create({
await ReminderDao.updateOne({
uid: c.uid,
number: c.number,
phone,
},
{
uid: c.uid,
number: c.number,
phone,
active: true
},
{
upsert: true
});

logger.info(`${phone} (${instance})[${state}]: reminder set`, { metadata: {
Expand Down Expand Up @@ -179,10 +188,19 @@ const handleText = async (req:NextApiRequest, res:NextApiResponse, input:string,
// if a number was given lets check to see if it maps to a case index
if (response === parseInt(response).toString() && index >= 0 && index < cases.length) {
let c = cases[index];
await ReminderDao.create({
await ReminderDao.updateOne({
uid: c.uid,
number: c.number,
phone,
},
{
uid: c.uid,
number: c.number,
phone,
active: true
},
{
upsert: true
});

logger.info(`${phone} (${instance})[${state}]: reminder set`, { metadata: {
Expand Down