From 0436b0cbfd41cf15aa239515673210d547035b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Sat, 3 Aug 2024 12:21:35 +0100 Subject: [PATCH] chore: Tidy up import, export and names --- app/data/gdhiRepo.ts | 6 +++++- app/data/{itlLookupRepo.ts => itlRepo.ts} | 6 +++++- app/services/calculationService.ts | 8 ++++---- app/services/gdhiService.ts | 10 +++++++--- app/services/itlLookupService.ts | 5 ----- app/services/itlService.ts | 9 +++++++++ 6 files changed, 30 insertions(+), 14 deletions(-) rename app/data/{itlLookupRepo.ts => itlRepo.ts} (84%) delete mode 100644 app/services/itlLookupService.ts create mode 100644 app/services/itlService.ts diff --git a/app/data/gdhiRepo.ts b/app/data/gdhiRepo.ts index 0c649f0d..69ed3b82 100644 --- a/app/data/gdhiRepo.ts +++ b/app/data/gdhiRepo.ts @@ -1,6 +1,6 @@ import prisma from "./db"; -export const getGDHI2020ByITL3 = async ( +const getGDHI2020ByITL3 = async ( itl3: string ): Promise => { try { @@ -20,3 +20,7 @@ export const getGDHI2020ByITL3 = async ( throw Error(`Data error: Unable to find gdhi2020 for itl3 ${itl3}`); } }; + +export const gdhiRepo = { + getGDHI2020ByITL3, +} diff --git a/app/data/itlLookupRepo.ts b/app/data/itlRepo.ts similarity index 84% rename from app/data/itlLookupRepo.ts rename to app/data/itlRepo.ts index d72e518e..8bc92b4d 100644 --- a/app/data/itlLookupRepo.ts +++ b/app/data/itlRepo.ts @@ -1,6 +1,6 @@ import prisma from "./db"; -export const getItl3ByPostcodeDistrict = async ( +const getItl3ByPostcodeDistrict = async ( postcodeDistrict: string ): Promise => { try { @@ -22,3 +22,7 @@ export const getItl3ByPostcodeDistrict = async ( throw new Error(`Data error: Unable get get itl3 for postcode district ${postcodeDistrict}`); } }; + +export const itlRepo = { + getItl3ByPostcodeDistrict, +} diff --git a/app/services/calculationService.ts b/app/services/calculationService.ts index 2e47df85..50d30de8 100644 --- a/app/services/calculationService.ts +++ b/app/services/calculationService.ts @@ -1,6 +1,6 @@ import { PrismaClient } from "@prisma/client"; -import * as itl3Service from "../services/itlLookupService"; -import * as ghdiService from "../services/gdhiService"; +import { itlService } from "./itlService"; +import { gdhiService } from "./gdhiService"; import { Calculation } from "../schemas/calculationSchema"; const prisma = new PrismaClient(); @@ -112,8 +112,8 @@ export const getHouseholdData = async ( // TODO: Make columns non-nullable if (!buildPrice) throw Error("Missing buildPrice"); - const itl3 = await itl3Service.getByPostcodeDistrict(postcodeDistrict); - const gdhi = await ghdiService.getByITL3(itl3); + const itl3 = await itlService.getByPostcodeDistrict(postcodeDistrict); + const gdhi = await gdhiService.getByITL3(itl3); const { _avg: { monthlyMeanRent: averageRentMonthly }, diff --git a/app/services/gdhiService.ts b/app/services/gdhiService.ts index dccbb16a..3dbb7529 100644 --- a/app/services/gdhiService.ts +++ b/app/services/gdhiService.ts @@ -1,5 +1,9 @@ -import * as repo from './../data/gdhiRepo'; +import { gdhiRepo } from "../data/gdhiRepo"; -export const getByITL3 = async (itl3: string) => { - return await repo.getGDHI2020ByITL3(itl3); +const getByITL3 = async (itl3: string) => { + return await gdhiRepo.getGDHI2020ByITL3(itl3); +}; + +export const gdhiService = { + getByITL3, }; diff --git a/app/services/itlLookupService.ts b/app/services/itlLookupService.ts deleted file mode 100644 index a04a2f10..00000000 --- a/app/services/itlLookupService.ts +++ /dev/null @@ -1,5 +0,0 @@ -import * as repo from "../data/itlLookupRepo"; - -export const getByPostcodeDistrict = async (postcodeDistrict: string) => { - return await repo.getItl3ByPostcodeDistrict(postcodeDistrict); -} diff --git a/app/services/itlService.ts b/app/services/itlService.ts new file mode 100644 index 00000000..358af0f9 --- /dev/null +++ b/app/services/itlService.ts @@ -0,0 +1,9 @@ +import { itlRepo } from "../data/itlRepo"; + +const getByPostcodeDistrict = async (postcodeDistrict: string) => { + return await itlRepo.getItl3ByPostcodeDistrict(postcodeDistrict); +} + +export const itlService = { + getByPostcodeDistrict, +}