From 26da3386b8f5561d3491c23becd70cc78889b07c Mon Sep 17 00:00:00 2001 From: Michelle Date: Mon, 29 Jan 2024 13:50:02 -0600 Subject: [PATCH 1/3] Fix error response to check for duplicate tutors --- src/commands/officer-commands/appoint-tutor.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/officer-commands/appoint-tutor.ts b/src/commands/officer-commands/appoint-tutor.ts index e4ee70f..cc11a27 100644 --- a/src/commands/officer-commands/appoint-tutor.ts +++ b/src/commands/officer-commands/appoint-tutor.ts @@ -8,7 +8,7 @@ import { Command } from "../../interfaces/Command"; import { createEmbed } from "../../utils/embeded"; import { commandLog, sendError } from "../../utils/logs"; import { - getContactId, + getContactId, getRole, getTutor, insertTutor, @@ -63,7 +63,7 @@ export const appointTutor: Command = { const tutorResponse = await getTutor({ contact_id }); - if (!tutorResponse.error) { + if (tutorResponse.error) { sendError( errorTitle, `${appointedUser} is already a tutor!`, From 85f0c7b3bdbe7b5a801d4644d7662092a75e981b Mon Sep 17 00:00:00 2001 From: Michelle Date: Mon, 29 Jan 2024 15:01:13 -0600 Subject: [PATCH 2/3] Revert tutorResponse error in appoint-tutor.ts and correct the mostRecentTutor to grab the most recent tutor time instead of the oldest tutor time --- src/commands/officer-commands/appoint-tutor.ts | 2 +- src/utils/supabase.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commands/officer-commands/appoint-tutor.ts b/src/commands/officer-commands/appoint-tutor.ts index cc11a27..69777ff 100644 --- a/src/commands/officer-commands/appoint-tutor.ts +++ b/src/commands/officer-commands/appoint-tutor.ts @@ -63,7 +63,7 @@ export const appointTutor: Command = { const tutorResponse = await getTutor({ contact_id }); - if (tutorResponse.error) { + if (!tutorResponse.error) { sendError( errorTitle, `${appointedUser} is already a tutor!`, diff --git a/src/utils/supabase.ts b/src/utils/supabase.ts index 392648f..6ada7f6 100644 --- a/src/utils/supabase.ts +++ b/src/utils/supabase.ts @@ -887,7 +887,7 @@ export const getTutor = async ( return tutorResponse; } - const mostRecentTutor = tutorResponse.data[0]; + const mostRecentTutor = tutorResponse.data[tutorResponse.data.length - 1]; const now = new Date(); const tutorStart = new Date(mostRecentTutor.start_date); @@ -896,7 +896,7 @@ export const getTutor = async ( if (now > tutorStart && now < tutorEnd) { return { ...tutorResponse, - data: tutorResponse.data[0], + data: mostRecentTutor, }; } From 75fbc107de611fba20ac449a2cf0772385c64a24 Mon Sep 17 00:00:00 2001 From: Michelle Date: Mon, 29 Jan 2024 15:43:38 -0600 Subject: [PATCH 3/3] Fix spacing --- src/commands/officer-commands/appoint-tutor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/officer-commands/appoint-tutor.ts b/src/commands/officer-commands/appoint-tutor.ts index 69777ff..e4ee70f 100644 --- a/src/commands/officer-commands/appoint-tutor.ts +++ b/src/commands/officer-commands/appoint-tutor.ts @@ -8,7 +8,7 @@ import { Command } from "../../interfaces/Command"; import { createEmbed } from "../../utils/embeded"; import { commandLog, sendError } from "../../utils/logs"; import { - getContactId, + getContactId, getRole, getTutor, insertTutor,