edit json structure to match expected data
This commit is contained in:
parent
fe5f45817d
commit
00a474d60b
2 changed files with 55 additions and 90 deletions
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
143
src/index.ts
143
src/index.ts
|
@ -16,10 +16,10 @@ export default defineHook(({ action }, { env }) => {
|
||||||
photos {
|
photos {
|
||||||
photo {
|
photo {
|
||||||
id
|
id
|
||||||
|
filename_disk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
property_code_type
|
property_code_type
|
||||||
property_type
|
|
||||||
geoFeatures
|
geoFeatures
|
||||||
property_rooms
|
property_rooms
|
||||||
property_surface
|
property_surface
|
||||||
|
@ -33,6 +33,9 @@ export default defineHook(({ action }, { env }) => {
|
||||||
property_depenses_max
|
property_depenses_max
|
||||||
property_depenses_est
|
property_depenses_est
|
||||||
property_dpe_date_price
|
property_dpe_date_price
|
||||||
|
property_PMR
|
||||||
|
property_furnished
|
||||||
|
property_floor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
@ -52,63 +55,63 @@ export default defineHook(({ action }, { env }) => {
|
||||||
|
|
||||||
const transformMapData = (maps: any[]): {} => {
|
const transformMapData = (maps: any[]): {} => {
|
||||||
const annonces: any[] = maps.map((map) => ({
|
const annonces: any[] = maps.map((map) => ({
|
||||||
annonce: {
|
// ANNONCE
|
||||||
// ANNONCE
|
reference: map.id,
|
||||||
reference: map.id,
|
titre: map.property_name ?? undefined,
|
||||||
titre: map.property_name ?? undefined,
|
texte: map?.description ?? "Pas encore de description.",
|
||||||
texte: map?.description ?? "Pas encore de description.",
|
date_saisie: formatDate(map.date_created),
|
||||||
date_saisie: formatDate(map.date_created),
|
photos: map?.photos?.map(
|
||||||
photos:
|
(img: any) => `${env.PUBLIC_URL}/assets/${img.photo.filename_disk}`
|
||||||
map?.photos?.map((img: any) => ({
|
),
|
||||||
photo: `${env.PUBLIC_URL}/assets/${img.photo.id}`,
|
|
||||||
})) ?? null,
|
|
||||||
|
|
||||||
// BIEN
|
// BIEN
|
||||||
code_type: map.property_code_type ?? undefined,
|
code_type: map.property_code_type ?? undefined,
|
||||||
libelle_type: map.property_type ?? undefined,
|
code_postal: map.geoFeatures.properties.postcode,
|
||||||
code_postal: map.geoFeatures.properties.postcode,
|
ville: map.geoFeatures.properties.city,
|
||||||
ville: map.geoFeatures.properties.city,
|
nb_pieces_logement: map.property_rooms ?? undefined,
|
||||||
nb_pieces_logement: map.property_rooms ?? undefined,
|
surface: map.property_surface ?? undefined,
|
||||||
surface: map.property_surface ?? undefined,
|
adresse: map.geoFeatures.properties.name ?? 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
|
// PRESTATION
|
||||||
type: map.property_sell,
|
type: map.property_sell,
|
||||||
frais_agence: map.property_fees ?? undefined,
|
frais_agence: map.property_fees ?? undefined,
|
||||||
// si vente
|
// si vente
|
||||||
prix: map.property_sell !== "L" ? map.property_price : undefined,
|
prix: map.property_sell !== "L" ? map.property_price : undefined,
|
||||||
// si location
|
// si location
|
||||||
loyer_mensuel:
|
loyer_mensuel:
|
||||||
map.property_sell === "L" ? map.property_price : undefined,
|
map.property_sell === "L" ? map.property_price : undefined,
|
||||||
|
|
||||||
// DPE
|
// DPE
|
||||||
dpe_valeur_conso: map.property_dpe_conso,
|
dpe_valeur_conso: map.property_dpe_conso,
|
||||||
dpe_valeur_ges: map.property_dpe_ges,
|
dpe_valeur_ges: map.property_dpe_ges,
|
||||||
dpe_date_realisation: formatDate(map.property_dpe_date),
|
dpe_date_realisation: formatDate(map.property_dpe_date),
|
||||||
montant_depenses_energies_min: map.property_depenses_min,
|
montant_depenses_energies_min: map.property_depenses_min,
|
||||||
montant_depenses_energies_max: map.property_depenses_max,
|
montant_depenses_energies_max: map.property_depenses_max,
|
||||||
montant_depenses_energies_estime: map.property_depenses_est,
|
montant_depenses_energies_estime: map.property_depenses_est,
|
||||||
date_indice_prix_energies: formatDate(map.property_dpe_date_price),
|
date_indice_prix_energies: formatDate(map.property_dpe_date_price),
|
||||||
|
|
||||||
// Complex nested objects
|
// Complex nested objects
|
||||||
// settings: {
|
// settings: {
|
||||||
// zoom: map?.settings?.zoom ?? 10,
|
// zoom: map?.settings?.zoom ?? 10,
|
||||||
// theme: map?.settings?.theme ?? "default",
|
// theme: map?.settings?.theme ?? "default",
|
||||||
// markers: map?.settings?.markers?.enabled ?? false,
|
// markers: map?.settings?.markers?.enabled ?? false,
|
||||||
// },
|
// },
|
||||||
|
|
||||||
// Conditional assignment using optional chaining
|
// Conditional assignment using optional chaining
|
||||||
// ...(map?.location && {
|
// ...(map?.location && {
|
||||||
// latitude: map.location?.lat,
|
// latitude: map.location?.lat,
|
||||||
// longitude: map.location?.lng,
|
// longitude: map.location?.lng,
|
||||||
// }),
|
// }),
|
||||||
|
|
||||||
// Keep some original structure if it exists
|
// Keep some original structure if it exists
|
||||||
// ...(map?.metadata && { originalMetadata: map.metadata }),
|
// ...(map?.metadata && { originalMetadata: map.metadata }),
|
||||||
},
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return { client: [...annonces] }
|
return annonces
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply key remapping
|
// apply key remapping
|
||||||
|
@ -123,45 +126,7 @@ export default defineHook(({ action }, { env }) => {
|
||||||
await writeFile(filePath, jsonData, "utf8")
|
await writeFile(filePath, jsonData, "utf8")
|
||||||
}
|
}
|
||||||
|
|
||||||
// // Updates the maps JSON file by fetching all maps and writing to file
|
// Register hook for operations on maps
|
||||||
// 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
|
|
||||||
const mapsActions = [
|
const mapsActions = [
|
||||||
`${env.COLLECTION}.items.create`,
|
`${env.COLLECTION}.items.create`,
|
||||||
`${env.COLLECTION}.items.update`,
|
`${env.COLLECTION}.items.update`,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue