Skip to content

Commit

Permalink
Merge pull request #110 from aymericdo/some_refacto
Browse files Browse the repository at this point in the history
some refacto
  • Loading branch information
aymericdo authored Apr 24, 2024
2 parents b94a6df + 11b1a20 commit 2db43d4
Show file tree
Hide file tree
Showing 35 changed files with 317 additions and 278 deletions.
5 changes: 3 additions & 2 deletions src/db/bordeaux-address.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ const schema = new Schema({
})

schema.index(
{ nom_voie: 'text', numero: 'text' },
{ nom_commune: 'text', nom_voie: 'text', numero: 'text' },
{
weights: {
nom_commune: 10,
nom_voie: 10,
numero: 1,
},
Expand All @@ -33,7 +34,7 @@ schema.index(
)

schema.index(
{ nom_voie: 1, numero: 1 },
{ nom_commune: 1, nom_voie: 1, numero: 1 },
{
collation: {
locale: 'fr',
Expand Down
5 changes: 3 additions & 2 deletions src/db/est_ensemble-address.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ const schema = new Schema({
})

schema.index(
{ nom_voie: 'text', numero: 'text' },
{ nom_commune: 'text', nom_voie: 'text', numero: 'text' },
{
weights: {
nom_commune: 10,
nom_voie: 10,
numero: 1,
},
Expand All @@ -40,7 +41,7 @@ schema.index(
)

schema.index(
{ nom_voie: 1, numero: 1 },
{ nom_commune: 1, nom_voie: 1, numero: 1 },
{
collation: {
locale: 'fr',
Expand Down
5 changes: 3 additions & 2 deletions src/db/lille-address.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@ const schema = new Schema({
})

schema.index(
{ nom_voie: 'text', numero: 'text' },
{ nom_commune: 'text', nom_voie: 'text', numero: 'text' },
{
weights: {
nom_commune: 10,
nom_voie: 10,
numero: 1,
},
default_language: 'french',
}
)
schema.index(
{ nom_voie: 1, numero: 1 },
{ nom_commune: 1, nom_voie: 1, numero: 1 },
{
collation: {
locale: 'fr',
Expand Down
5 changes: 3 additions & 2 deletions src/db/lyon-address.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ const schema = new Schema({
})

schema.index(
{ nom_voie: 'text', numero: 'text' },
{ nom_commune: 'text', nom_voie: 'text', numero: 'text' },
{
weights: {
nom_commune: 10,
nom_voie: 10,
numero: 1,
},
default_language: 'french',
}
)
schema.index(
{ nom_voie: 1, numero: 1 },
{ nom_commune: 1, nom_voie: 1, numero: 1 },
{
collation: {
locale: 'fr',
Expand Down
5 changes: 3 additions & 2 deletions src/db/montpellier-address.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ const schema = new Schema({
})

schema.index(
{ nom_voie: 'text', numero: 'text' },
{ nom_commune: 'text', nom_voie: 'text', numero: 'text' },
{
weights: {
nom_commune: 10,
nom_voie: 10,
numero: 1,
},
Expand All @@ -40,7 +41,7 @@ schema.index(
)

schema.index(
{ nom_voie: 1, numero: 1 },
{ nom_commune: 1, nom_voie: 1, numero: 1 },
{
collation: {
locale: 'fr',
Expand Down
5 changes: 3 additions & 2 deletions src/db/plaine_commune-address.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ const schema = new Schema({
})

schema.index(
{ nom_voie: 'text', numero: 'text' },
{ nom_commune: 'text', nom_voie: 'text', numero: 'text' },
{
weights: {
nom_commune: 10,
nom_voie: 10,
numero: 1,
},
Expand All @@ -40,7 +41,7 @@ schema.index(
)

schema.index(
{ nom_voie: 1, numero: 1 },
{ nom_commune: 1, nom_voie: 1, numero: 1 },
{
collation: {
locale: 'fr',
Expand Down
17 changes: 7 additions & 10 deletions src/db/rent.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function getChloroplethMapData(
}
}

return await Rent.find(filter, { isLegal: 1, district: 1 }).lean()
return await Rent.find(filter, { isLegal: 1, district: 1 })
}

export async function getPriceDiffData(
Expand Down Expand Up @@ -227,7 +227,7 @@ export async function getLegalPerClassicRenterData(
return (await Rent.find(filter, {
isLegal: 1,
renter: 1,
}).lean()) as unknown as { isLegal: boolean; renter: string }[]
})) as unknown as { isLegal: boolean; renter: string }[]
}

export async function getLegalPerRenterData(
Expand Down Expand Up @@ -307,7 +307,7 @@ export async function getLegalPerWebsiteData(
return (await Rent.find(filter, {
isLegal: 1,
website: 1,
}).lean()) as unknown as {
})) as unknown as {
isLegal: boolean
website: string
}[]
Expand Down Expand Up @@ -427,18 +427,15 @@ export async function getRelevantAdsData(
}
).lean()) as unknown as RelevantAdsData[]

return ads.map((ad) => {
return await Promise.all(ads.map(async (ad) => {
let blurry = false

if (!ad.longitude || !ad.latitude) {
const mainCity = cityList[ad.city].mainCity

const polygon = new DistrictsList(mainCity as AvailableMainCities).currentPolygon(ad.district)
const feature = await new DistrictsList(mainCity as AvailableMainCities).currentFeature(ad.district)

const point = randomPositionInPolygon({
type: 'Feature',
geometry: polygon,
})
const point = randomPositionInPolygon(feature)

ad.longitude = point[0]
ad.latitude = point[1]
Expand All @@ -455,7 +452,7 @@ export async function getRelevantAdsData(
blurry,
exceeding,
}
})
}))
}

export async function getRelevantAdsDataTotalCount(filterParam: {
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/json-item-bordeaux.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { DISPLAY_ZONE_FIELD } from '@services/districts/districts-list'

export interface BordeauxEncadrementItem {
zone: number;
maison: boolean;
Expand All @@ -15,6 +17,7 @@ export interface BordeauxDistrictItem {
com_code: number
zonage: string
commune: string
[DISPLAY_ZONE_FIELD]: string
}
geometry: {
type: 'Polygon'
Expand Down
16 changes: 16 additions & 0 deletions src/services/address/address-factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Ad } from '@interfaces/ad'
import { AddressService, DefaultAddressService } from '@services/address/default-address-service'
import { ParisAddressService } from '@services/address/paris-address-service'

export class AddressServiceFactory {
getDiggerStrategy(city: string, postalCode: string, ad: Ad): AddressService {
switch (city) {
case 'paris': {
return new ParisAddressService(city, postalCode, ad)
}
default: {
return new DefaultAddressService(city, postalCode, ad)
}
}
}
}
Loading

0 comments on commit 2db43d4

Please sign in to comment.