Compare commits

...

1 commit
0.1 ... main

Author SHA1 Message Date
00a474d60b
edit json structure to match expected data 2025-08-28 15:07:56 +02:00
2 changed files with 55 additions and 90 deletions

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View file

@ -16,10 +16,10 @@ export default defineHook(({ action }, { env }) => {
photos {
photo {
id
filename_disk
}
}
property_code_type
property_type
geoFeatures
property_rooms
property_surface
@ -33,6 +33,9 @@ export default defineHook(({ action }, { env }) => {
property_depenses_max
property_depenses_est
property_dpe_date_price
property_PMR
property_furnished
property_floor
}
}
`
@ -52,63 +55,63 @@ export default defineHook(({ action }, { env }) => {
const transformMapData = (maps: any[]): {} => {
const annonces: any[] = maps.map((map) => ({
annonce: {
// ANNONCE
reference: map.id,
titre: map.property_name ?? undefined,
texte: map?.description ?? "Pas encore de description.",
date_saisie: formatDate(map.date_created),
photos:
map?.photos?.map((img: any) => ({
photo: `${env.PUBLIC_URL}/assets/${img.photo.id}`,
})) ?? null,
// ANNONCE
reference: map.id,
titre: map.property_name ?? undefined,
texte: map?.description ?? "Pas encore de description.",
date_saisie: formatDate(map.date_created),
photos: map?.photos?.map(
(img: any) => `${env.PUBLIC_URL}/assets/${img.photo.filename_disk}`
),
// BIEN
code_type: map.property_code_type ?? undefined,
libelle_type: map.property_type ?? undefined,
code_postal: map.geoFeatures.properties.postcode,
ville: map.geoFeatures.properties.city,
nb_pieces_logement: map.property_rooms ?? undefined,
surface: map.property_surface ?? undefined,
adresse: map.geoFeatures.properties.name ?? undefined,
// BIEN
code_type: map.property_code_type ?? undefined,
code_postal: map.geoFeatures.properties.postcode,
ville: map.geoFeatures.properties.city,
nb_pieces_logement: map.property_rooms ?? undefined,
surface: map.property_surface ?? undefined,
adresse: map.geoFeatures.properties.name ?? undefined,
meuble: map.property_furnished,
acces_handicapes: map.property_PMR,
etage: map.property_floor ?? undefined,
charges_copropriete: map.property_utilities ?? undefined,
// PRESTATION
type: map.property_sell,
frais_agence: map.property_fees ?? undefined,
// si vente
prix: map.property_sell !== "L" ? map.property_price : undefined,
// si location
loyer_mensuel:
map.property_sell === "L" ? map.property_price : undefined,
// PRESTATION
type: map.property_sell,
frais_agence: map.property_fees ?? undefined,
// si vente
prix: map.property_sell !== "L" ? map.property_price : undefined,
// si location
loyer_mensuel:
map.property_sell === "L" ? map.property_price : undefined,
// DPE
dpe_valeur_conso: map.property_dpe_conso,
dpe_valeur_ges: map.property_dpe_ges,
dpe_date_realisation: formatDate(map.property_dpe_date),
montant_depenses_energies_min: map.property_depenses_min,
montant_depenses_energies_max: map.property_depenses_max,
montant_depenses_energies_estime: map.property_depenses_est,
date_indice_prix_energies: formatDate(map.property_dpe_date_price),
// DPE
dpe_valeur_conso: map.property_dpe_conso,
dpe_valeur_ges: map.property_dpe_ges,
dpe_date_realisation: formatDate(map.property_dpe_date),
montant_depenses_energies_min: map.property_depenses_min,
montant_depenses_energies_max: map.property_depenses_max,
montant_depenses_energies_estime: map.property_depenses_est,
date_indice_prix_energies: formatDate(map.property_dpe_date_price),
// Complex nested objects
// settings: {
// zoom: map?.settings?.zoom ?? 10,
// theme: map?.settings?.theme ?? "default",
// markers: map?.settings?.markers?.enabled ?? false,
// },
// Complex nested objects
// settings: {
// zoom: map?.settings?.zoom ?? 10,
// theme: map?.settings?.theme ?? "default",
// markers: map?.settings?.markers?.enabled ?? false,
// },
// Conditional assignment using optional chaining
// ...(map?.location && {
// latitude: map.location?.lat,
// longitude: map.location?.lng,
// }),
// Conditional assignment using optional chaining
// ...(map?.location && {
// latitude: map.location?.lat,
// longitude: map.location?.lng,
// }),
// Keep some original structure if it exists
// ...(map?.metadata && { originalMetadata: map.metadata }),
},
// Keep some original structure if it exists
// ...(map?.metadata && { originalMetadata: map.metadata }),
}))
return { client: [...annonces] }
return annonces
}
// apply key remapping
@ -123,45 +126,7 @@ export default defineHook(({ action }, { env }) => {
await writeFile(filePath, jsonData, "utf8")
}
// // Updates the maps JSON file by fetching all maps and writing to file
// const updateMapsFile = async (): Promise<void> => {
// try {
// const schema = await getSchema()
// const itemsService = new ItemsService(COLLECTION_NAME, {
// schema,
// accountability: null, // Use null for full access in hooks
// })
// // get all items in collection
// const allMaps = await itemsService.readByQuery({})
// console.log(allMaps)
// // Transform the data before serializing
// const transformedMaps = Array.isArray(allMaps)
// ? transformMapData(allMaps)
// : []
// // format items to JSON
// const jsonData = JSON.stringify(transformedMaps, null, 2)
// console.log(
// `Updating maps file with ${
// Array.isArray(allMaps) ? allMaps.length : 0
// } items`
// )
// const filePath = join(OUTPUT_DIR, OUTPUT_FILENAME)
// // write JSON to file (already exists)
// await writeFile(filePath, jsonData, "utf8")
// console.log(`Maps file successfully updated at: ${filePath}`)
// } catch (error) {
// console.error("Error updating maps file:", error)
// throw error
// }
// }
// Register hook for all CRUD operations on maps
// Register hook for operations on maps
const mapsActions = [
`${env.COLLECTION}.items.create`,
`${env.COLLECTION}.items.update`,