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"
|
import { formatDate } from "./utils"
|
||||||
|
|
||||||
export default defineHook(({ action }, { env }) => {
|
export default defineHook(({ action }, { env }) => {
|
||||||
|
console.log("!!! extension loaded with collection:", env.COLLECTION)
|
||||||
|
|
||||||
const mapsGraphQLQuery = `
|
const mapsGraphQLQuery = `
|
||||||
query getMaps {
|
query getMaps {
|
||||||
maps {
|
maps {
|
||||||
|
@ -53,7 +55,7 @@ export default defineHook(({ action }, { env }) => {
|
||||||
annonce: {
|
annonce: {
|
||||||
// ANNONCE
|
// ANNONCE
|
||||||
reference: map.id,
|
reference: map.id,
|
||||||
titre: map.property_name,
|
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:
|
photos:
|
||||||
|
@ -66,13 +68,13 @@ export default defineHook(({ action }, { env }) => {
|
||||||
libelle_type: map.property_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,
|
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,
|
||||||
|
|
||||||
// PRESTATION
|
// PRESTATION
|
||||||
type: map.property_sell,
|
type: map.property_sell,
|
||||||
frais_agence: map.property_fees,
|
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
|
||||||
|
@ -86,30 +88,23 @@ export default defineHook(({ action }, { env }) => {
|
||||||
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: map.property_dpe_date_price,
|
date_indice_prix_energies: formatDate(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,
|
|
||||||
|
|
||||||
// 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 }),
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue