Skip to content

Commit

Permalink
fix prisma scheme (#113)
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriele Granello <[email protected]>
  • Loading branch information
gabrielegranello and Gabriele Granello authored Oct 11, 2024
1 parent 8f388fe commit ae62f43
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
41 changes: 20 additions & 21 deletions app/data/hpiRepo.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import prisma from "./db";

const getHPIByITL3 = async (itl3: string): Promise<number> => {
try {
const {
_avg: { hpi2020: averageHpi },
} = await prisma.hPI.aggregate({
where: {
itl3: {
endsWith: itl3,
},
},
_avg: {
hpi2020: true,
},
});
return averageHpi as number;
} catch (error) {
throw Error(`Data error: Unable to find hpi2020 for itl3 ${itl3}`);
}
try {
const {
_avg: { hpi2000: averageHpi },
} = await prisma.hPI.aggregate({
where: {
itl3: {
endsWith: itl3,
},
},
_avg: {
hpi2000: true,
},
});
return averageHpi as number;
} catch (error) {
throw Error(`Data error: Unable to find hpi2000 for itl3 ${itl3}`);
}
};

export const hpi2020Repo = {
getHPIByITL3,
};

export const hpi2000Repo = {
getHPIByITL3,
};
4 changes: 2 additions & 2 deletions app/services/hpiService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { hpi2020Repo } from "../data/hpiRepo";
import { hpi2000Repo } from "../data/hpiRepo";

const getByITL3 = async (itl3: string) => {
return await hpi2020Repo.getHPIByITL3(itl3);
return await hpi2000Repo.getHPIByITL3(itl3);
};

export const hpiService = {
Expand Down
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ model HPI {
region String? @db.VarChar(250)
itl3 String? @db.VarChar(250)
ladCode String? @map("ladcode") @db.VarChar(250)
hpi_2000 Float?
hpi2000 Float? @map("hpi_2000")
@@map("hpi")
}
Expand Down

0 comments on commit ae62f43

Please sign in to comment.