fix json structure
This commit is contained in:
parent
8694a2c7eb
commit
51b6397f42
2 changed files with 17 additions and 22 deletions
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
37
src/index.ts
37
src/index.ts
|
@ -4,6 +4,8 @@ import { join } from "path"
|
|||
import { formatDate } from "./utils"
|
||||
|
||||
export default defineHook(({ action }, { env }) => {
|
||||
console.log("!!! extension loaded with collection:", env.COLLECTION)
|
||||
|
||||
const mapsGraphQLQuery = `
|
||||
query getMaps {
|
||||
maps {
|
||||
|
@ -53,7 +55,7 @@ export default defineHook(({ action }, { env }) => {
|
|||
annonce: {
|
||||
// ANNONCE
|
||||
reference: map.id,
|
||||
titre: map.property_name,
|
||||
titre: map.property_name ?? undefined,
|
||||
texte: map?.description ?? "Pas encore de description.",
|
||||
date_saisie: formatDate(map.date_created),
|
||||
photos:
|
||||
|
@ -66,13 +68,13 @@ export default defineHook(({ action }, { env }) => {
|
|||
libelle_type: map.property_type ?? undefined,
|
||||
code_postal: map.geoFeatures.properties.postcode,
|
||||
ville: map.geoFeatures.properties.city,
|
||||
nb_pieces_logement: map.property_rooms,
|
||||
nb_pieces_logement: map.property_rooms ?? undefined,
|
||||
surface: map.property_surface ?? undefined,
|
||||
adresse: map.geoFeatures.properties.name ?? undefined,
|
||||
|
||||
// PRESTATION
|
||||
type: map.property_sell,
|
||||
frais_agence: map.property_fees,
|
||||
frais_agence: map.property_fees ?? undefined,
|
||||
// si vente
|
||||
prix: map.property_sell !== "L" ? map.property_price : undefined,
|
||||
// si location
|
||||
|
@ -86,30 +88,23 @@ export default defineHook(({ action }, { env }) => {
|
|||
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: map.property_dpe_date_price,
|
||||
|
||||
// Array handling with optional chaining
|
||||
categories:
|
||||
map?.categories?.map((cat: any) => cat?.name) ?? undefined,
|
||||
|
||||
// Date handling
|
||||
updatedAt: map?.date_updated,
|
||||
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,
|
||||
},
|
||||
// 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,
|
||||
}),
|
||||
// ...(map?.location && {
|
||||
// latitude: map.location?.lat,
|
||||
// longitude: map.location?.lng,
|
||||
// }),
|
||||
|
||||
// Keep some original structure if it exists
|
||||
...(map?.metadata && { originalMetadata: map.metadata }),
|
||||
// ...(map?.metadata && { originalMetadata: map.metadata }),
|
||||
},
|
||||
}))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue