Skip to content

Commit

Permalink
only update completion time if null, double booking confirmed to work…
Browse files Browse the repository at this point in the history
… after testing
  • Loading branch information
Fattimo committed Apr 23, 2021
1 parent d2c1474 commit d00c0e2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion MassMessage/Scripts/sendMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export const sendCompletedMessage = async function (
} else {
await client.messages.create({ body: quiz.body, from: config.numbers.sms, to: id })
}
user.currMessage = quiz
user.currMessage = quiz._id
user.save()
}

export const sendInactiveMessage = async function (id: string): Promise<void> {
Expand Down
8 changes: 4 additions & 4 deletions MassMessage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const timerTrigger: AzureFunction = async function (context: Context, myTimer: a

const completed = await messageCompletedUsers(curDate)
const inactive = await messageInactiveUsers(curDate)
context.log(completed)
context.log(inactive)
inactive.forEach(async (user) => {
if (completed.has(user.userId)) return
sendInactiveMessage(user.userId)
Expand Down Expand Up @@ -62,7 +64,7 @@ const messageInactiveUsers = async function (date: Date) {
const messageCompletedUsers = async function (date: Date) {
//set to two months ago
const twoMonths = new Date(date)
twoMonths.setMonth(twoMonths.getMonth() - 2)
twoMonths.setDate(twoMonths.getDate() - 56)

const nextDay = new Date(twoMonths)
nextDay.setDate(nextDay.getDate() + 1)
Expand All @@ -81,13 +83,11 @@ const messageCompletedUsers = async function (date: Date) {
allUsers.forEach((user) => {
let module = -1
let found = false
let daysIncrement = 1
for (let i = 0; i < user.moduleCompletionTime.length; i++) {
const time = user.moduleCompletionTime[i]
if (time >= twoMonths && time < nextDay) {
if (found) {
time.setDate(time.getDate() + daysIncrement)
daysIncrement += 1
time.setDate(time.getDate() + 1)
user.moduleCompletionTime.set(i, time)
} else {
module = i
Expand Down
4 changes: 3 additions & 1 deletion ReceiveMessage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ const httpTrigger: AzureFunction = async function (context: Context, req: HttpRe
if (response.messageType == 'final-message') {
const moduleNumber = parseInt(response.module)
if (!isNaN(moduleNumber) && moduleNumber > 0) {
curUserState.moduleCompletionTime.set(moduleNumber - 1, currTime)
if (curUserState.moduleCompletionTime[moduleNumber - 1] == null) {
curUserState.moduleCompletionTime.set(moduleNumber - 1, currTime)
}
}
}
if (curUserState) {
Expand Down

0 comments on commit d00c0e2

Please sign in to comment.