diff --git a/app/data/gasBillRepo.test.ts b/app/data/gasBillRepo.test.ts index ad31ba66..c75576de 100644 --- a/app/data/gasBillRepo.test.ts +++ b/app/data/gasBillRepo.test.ts @@ -18,14 +18,14 @@ describe("gasBillRepo", () => { const mockGasBill = 150; // Example gas bill amount (prisma.gasBills.findFirstOrThrow as jest.Mock).mockResolvedValueOnce({ - bill: mockGasBill, + kwhCostPence: mockGasBill, }); const result = await gasBillRepo.getGasBillByITL3(itl); expect(result).toBe(mockGasBill); expect(prisma.gasBills.findFirstOrThrow).toHaveBeenCalledWith({ - where: { itl: { startsWith: itl.substring(0, 3) } }, - select: { bill: true }, + where: { itl1: { startsWith: itl.substring(0, 3) } }, + select: { kwhCostPence: true }, }); }); diff --git a/app/data/gasBillRepo.ts b/app/data/gasBillRepo.ts index 08253d54..2805d1c3 100644 --- a/app/data/gasBillRepo.ts +++ b/app/data/gasBillRepo.ts @@ -2,14 +2,14 @@ import prisma from "./db"; const getGasBillByITL3 = async (itl: string): Promise => { try { - const { bill } = await prisma.gasBills.findFirstOrThrow({ + const { kwhCostPence } = await prisma.gasBills.findFirstOrThrow({ where: { - itl: { startsWith: itl.substring(0, 3) }, + itl1: { startsWith: itl.substring(0, 3) }, }, - select: { bill: true }, + select: { kwhCostPence: true }, }); - return bill as number; + return kwhCostPence; } catch (error) { throw Error(`Data error: Unable to find gas_bills_2020 for itl3 ${itl}`); } diff --git a/prisma/migrations/20241211152923_rename_gasbills_column/migration.sql b/prisma/migrations/20241211152923_rename_gasbills_column/migration.sql new file mode 100644 index 00000000..390c9e34 --- /dev/null +++ b/prisma/migrations/20241211152923_rename_gasbills_column/migration.sql @@ -0,0 +1,6 @@ +-- AlterTable +ALTER TABLE "gas_bills" RENAME COLUMN "bill" TO "kwh_cost_pence"; +ALTER TABLE "gas_bills" RENAME COLUMN "itl" TO "itl1"; +ALTER TABLE "gas_bills" RENAME COLUMN "Region" TO "region"; +ALTER TABLE "gas_bills" ALTER COLUMN "kwh_cost_pence" SET NOT NULL; +ALTER TABLE "gas_bills" ALTER COLUMN "itl1" SET NOT NULL; \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 86e4c558..3b8d4669 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -90,9 +90,9 @@ model SocialRent { model GasBills { id Int @id - region String @map("Region") @db.VarChar - itl String @db.VarChar - bill Float + region String @map("region") @db.VarChar + itl1 String @db.VarChar + kwhCostPence Float @map("kwh_cost_pence") @@map("gas_bills") }