mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
added lpi as additional dataset for ordnance survey to retrieve full results
This commit is contained in:
parent
86d919d7df
commit
eeb036712f
2 changed files with 16 additions and 6 deletions
|
|
@ -24,9 +24,9 @@ async function fetchOsPlacesPage(
|
|||
retries: number,
|
||||
delay: number
|
||||
): Promise<{ status: number; data?: OSPlacesResponse; error?: string }> {
|
||||
const url = `${OS_API_URL}?postcode=${encodeURIComponent(
|
||||
const url = `https://api.os.uk/search/places/v1/postcode?postcode=${encodeURIComponent(
|
||||
postcode
|
||||
)}&key=${OS_API_KEY}&maxresults=${maxResults}&offset=${offset}`;
|
||||
)}&dataset=DPA,LPI&maxresults=100&offset=${offset}&key=${process.env.OS_API_KEY}`;
|
||||
|
||||
try {
|
||||
const res = await fetch(url, { method: "GET" });
|
||||
|
|
|
|||
|
|
@ -53,10 +53,20 @@ export async function GET(
|
|||
const addresses = mapOsPlacesToFlat(result.results);
|
||||
const total = result.data.header?.totalresults ?? addresses.length;
|
||||
|
||||
await db.insert(postcodeSearch).values({
|
||||
postcode: postcode,
|
||||
resultData: result.data,
|
||||
});
|
||||
// We shouldn't really run into conflicts here, but just in case, we allow for an update
|
||||
await db
|
||||
.insert(postcodeSearch)
|
||||
.values({
|
||||
postcode,
|
||||
resultData: result.data,
|
||||
})
|
||||
.onConflictDoUpdate({
|
||||
target: postcodeSearch.postcode,
|
||||
set: {
|
||||
resultData: result.data,
|
||||
createdAt: new Date(), // update timestamp
|
||||
},
|
||||
});
|
||||
|
||||
// Step 4: return results
|
||||
return NextResponse.json({
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue