From 279835a31941fc2f7b6ce520bceb4e8fb3da8d89 Mon Sep 17 00:00:00 2001 From: theimperious1 Date: Sat, 12 Oct 2024 21:45:00 -0400 Subject: [PATCH 1/3] fix: error in iDose bc of special char in uG --- src/global/commands/g.idose.ts | 4 ++++ .../20241013014029_add_micro_g_alias/migration.sql | 14 ++++++++++++++ src/prisma/tripbot/schema.prisma | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/prisma/tripbot/migrations/20241013014029_add_micro_g_alias/migration.sql diff --git a/src/global/commands/g.idose.ts b/src/global/commands/g.idose.ts index 406de0b57..05c18b57b 100644 --- a/src/global/commands/g.idose.ts +++ b/src/global/commands/g.idose.ts @@ -147,6 +147,10 @@ async function iDoseSet( update: {}, }); + if (units.toString() === 'µG') { + units = 'MICRO_G'; + } + await db.user_drug_doses.create({ data: { user_id: userData.id, diff --git a/src/prisma/tripbot/migrations/20241013014029_add_micro_g_alias/migration.sql b/src/prisma/tripbot/migrations/20241013014029_add_micro_g_alias/migration.sql new file mode 100644 index 000000000..4e28f02ea --- /dev/null +++ b/src/prisma/tripbot/migrations/20241013014029_add_micro_g_alias/migration.sql @@ -0,0 +1,14 @@ +/* + Warnings: + + - The values [µG] on the enum `drug_mass_unit` will be removed. If these variants are still used in the database, this will fail. + +*/ +-- AlterEnum +BEGIN; +CREATE TYPE "drug_mass_unit_new" AS ENUM ('MG', 'ML', 'uG', 'G', 'OZ', 'FLOZ'); +ALTER TABLE "user_drug_doses" ALTER COLUMN "units" TYPE "drug_mass_unit_new" USING ("units"::text::"drug_mass_unit_new"); +ALTER TYPE "drug_mass_unit" RENAME TO "drug_mass_unit_old"; +ALTER TYPE "drug_mass_unit_new" RENAME TO "drug_mass_unit"; +DROP TYPE "drug_mass_unit_old"; +COMMIT; diff --git a/src/prisma/tripbot/schema.prisma b/src/prisma/tripbot/schema.prisma index a815453dd..621ce5377 100644 --- a/src/prisma/tripbot/schema.prisma +++ b/src/prisma/tripbot/schema.prisma @@ -573,7 +573,7 @@ enum drug_category_type { enum drug_mass_unit { MG ML - MICRO_G @map("µG") + MICRO_G @map("uG") G OZ FLOZ From 34c01c50154ffd0b6398b014a43804738652c377 Mon Sep 17 00:00:00 2001 From: theimperious1 Date: Sat, 12 Oct 2024 23:19:35 -0400 Subject: [PATCH 2/3] lint --- src/global/commands/g.idose.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/global/commands/g.idose.ts b/src/global/commands/g.idose.ts index 05c18b57b..e16466e3a 100644 --- a/src/global/commands/g.idose.ts +++ b/src/global/commands/g.idose.ts @@ -150,7 +150,7 @@ async function iDoseSet( if (units.toString() === 'µG') { units = 'MICRO_G'; } - + await db.user_drug_doses.create({ data: { user_id: userData.id, From a9f2ba936b6aa8470cdfbbb95f5a4f9ba753aa84 Mon Sep 17 00:00:00 2001 From: theimperious1 Date: Sat, 12 Oct 2024 23:27:25 -0400 Subject: [PATCH 3/3] change function paramater reassignment to ternary bc lint --- src/global/commands/g.idose.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/global/commands/g.idose.ts b/src/global/commands/g.idose.ts index e16466e3a..31409efc3 100644 --- a/src/global/commands/g.idose.ts +++ b/src/global/commands/g.idose.ts @@ -1,4 +1,4 @@ -import { drug_mass_unit, drug_roa } from '@prisma/client'; +import { $Enums, drug_mass_unit, drug_roa } from '@prisma/client'; import { time, } from 'discord.js'; @@ -147,17 +147,13 @@ async function iDoseSet( update: {}, }); - if (units.toString() === 'µG') { - units = 'MICRO_G'; - } - await db.user_drug_doses.create({ data: { user_id: userData.id, drug_id: drugId, route: roa, dose: volume, - units, + units: units.toString() === 'µG' ? $Enums.drug_mass_unit.MICRO_G : units, created_at: date, }, });