fix(jobdanmark-search): emit the /scrape contract fields in search output (#340)

Adds additive normalization so jobdanmark search output carries the cross-portal contract fields: company from companyName, location as the city after the postal code in companyAddress (null-safe - a missing or null address yields null instead of crashing the search), and date/deadline converted from DD-MM-YYYY to YYYY-MM-DD with safe passthrough on unexpected formats. Native fields unchanged.

Co-authored-by: oscarbol09 <80536682+oscarbol09@users.noreply.github.com>
This commit is contained in:
Oscar Madera
2026-08-19 08:32:06 +02:00
committed by GitHub
parent 04186b9a37
commit 17bc698697
4 changed files with 89 additions and 4 deletions
@@ -2,7 +2,7 @@ import { defineCommand, option } from "@bunli/core"
import { z } from "zod"
import { apiPost, writeError, BASE_URL } from "../helpers.js"
interface ApiSearchItem {
export interface ApiSearchItem {
title: string
companyName: string
companyLogo: {
@@ -12,7 +12,7 @@ interface ApiSearchItem {
} | null
companyLogoSvgMarkup: string | null
overlayColor: string | null
companyAddress: string
companyAddress: string | null
jobTypes: string[]
boostJob: boolean
publishedDate: string
@@ -34,7 +34,12 @@ interface ApiSearchResponse {
totalPages: number
}
function normalizeItem(item: ApiSearchItem): Record<string, unknown> {
function toContractDate(value: string | null): string | null {
const match = value?.match(/^(\d{2})-(\d{2})-(\d{4})$/)
return match ? `${match[3]}-${match[2]}-${match[1]}` : (value ?? null)
}
export function normalizeItem(item: ApiSearchItem): Record<string, unknown> {
const relativeUrl = item.url
const fullUrl = relativeUrl.startsWith("http")
? relativeUrl
@@ -77,6 +82,10 @@ function normalizeItem(item: ApiSearchItem): Record<string, unknown> {
slug,
coverImage,
silhouetteLogo: item.silhouetteLogo,
company: item.companyName,
location: item.companyAddress?.match(/\d{4}\s+(.+)$/)?.[1] ?? null,
date: toContractDate(item.publishedDate),
deadline: toContractDate(item.applicationDeadline),
}
}