Compare commits

..

No commits in common. "main" and "0.1" have entirely different histories.
main ... 0.1

2 changed files with 90 additions and 55 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 { 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,9 +33,6 @@ 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
} }
} }
` `
@ -55,63 +52,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: {
reference: map.id, // ANNONCE
titre: map.property_name ?? undefined, reference: map.id,
texte: map?.description ?? "Pas encore de description.", titre: map.property_name ?? undefined,
date_saisie: formatDate(map.date_created), texte: map?.description ?? "Pas encore de description.",
photos: map?.photos?.map( date_saisie: formatDate(map.date_created),
(img: any) => `${env.PUBLIC_URL}/assets/${img.photo.filename_disk}` photos:
), 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,
code_postal: map.geoFeatures.properties.postcode, libelle_type: map.property_type ?? undefined,
ville: map.geoFeatures.properties.city, code_postal: map.geoFeatures.properties.postcode,
nb_pieces_logement: map.property_rooms ?? undefined, ville: map.geoFeatures.properties.city,
surface: map.property_surface ?? undefined, nb_pieces_logement: map.property_rooms ?? undefined,
adresse: map.geoFeatures.properties.name ?? undefined, surface: map.property_surface ?? undefined,
meuble: map.property_furnished, adresse: map.geoFeatures.properties.name ?? undefined,
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 annonces return { client: [...annonces] }
} }
// apply key remapping // apply key remapping
@ -126,7 +123,45 @@ export default defineHook(({ action }, { env }) => {
await writeFile(filePath, jsonData, "utf8") await writeFile(filePath, jsonData, "utf8")
} }
// Register hook for operations on maps // // 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
const mapsActions = [ const mapsActions = [
`${env.COLLECTION}.items.create`, `${env.COLLECTION}.items.create`,
`${env.COLLECTION}.items.update`, `${env.COLLECTION}.items.update`,