Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
aymericdo committed Jan 12, 2024
2 parents f6b200d + 14a0ba9 commit b845949
Show file tree
Hide file tree
Showing 22 changed files with 125 additions and 143 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FROM node:18
FROM node:20

WORKDIR /usr/src/app

COPY package*.json ./
RUN npm install

COPY . .
RUN npm run build

CMD [ "node", "index.js" ]
CMD [ "node", "build/src/index.js" ]
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"engines": {
"node": "18.x",
"node": "20.x",
"npm": "9.x"
},
"scripts": {
Expand All @@ -14,7 +14,7 @@
"test": "jest --forceExit --detectOpenHandles --no-cache",
"test:watch": "jest --forceExit --detectOpenHandles --no-cache --watchAll",
"dev": "ts-node-dev --transpile-only ./src/index.ts",
"prod": "tsc && node ./build/src/index.js",
"prod": "node ./build/src/index.js",
"debug": "tsc && node --inspect ./build/src/index.js",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix"
Expand Down Expand Up @@ -77,4 +77,4 @@
"ts-node-dev": "^2.0.0",
"typescript": "^5.1.6"
}
}
}
2 changes: 1 addition & 1 deletion src/api/version.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const router = express.Router()

router.get('/', getIsExtensionUpToDate)
function getIsExtensionUpToDate(req: Request, res: Response) {
const currentVersion = '6.0.8'
const currentVersion = '6.1.1'
const version = req.query.version
res.json(currentVersion > version)
}
Expand Down
2 changes: 1 addition & 1 deletion src/cronjobs/cronjobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { schedule } from 'node-cron'
const TIMEZONE = 'Europe/Paris'
export class CronJobsService {
watch() {
// https://crontab.guru/#0_8_*_*_1
// https://crontab.guru/#0_8_*_*_1 :)
schedule(
'0 8 * * 5',
async () => {
Expand Down
14 changes: 7 additions & 7 deletions src/db/rent.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,13 @@ function buildFilter(filterParam: {
}
}

if (filterParam.roomRange?.length) {
filter['roomCount'] = {
$gte: filterParam.roomRange[0],
$lte: filterParam.roomRange[1],
}
}

if (filterParam.exceedingRange?.length) {
filter['$expr'] = {
$and: [
Expand All @@ -601,13 +608,6 @@ function buildFilter(filterParam: {
}
}

if (filterParam.roomRange?.length) {
filter['roomCount'] = {
$gte: filterParam.roomRange[0],
$lte: filterParam.roomRange[1],
}
}

return filter
}

Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ Sentry.init({

app.use(
express.json({
limit: '1mb',
limit: '5mb',
type: ['application/json', 'text/plain'],
})
)

app.use(
express.urlencoded({
limit: '1mb',
limit: '5mb',
extended: true,
parameterLimit: 50000,
})
Expand Down
16 changes: 8 additions & 8 deletions src/interfaces/json-item-bordeaux.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export interface BordeauxEncadrementItem {
zone: number
maison: boolean
meuble: boolean
nombre_de_piece: string
annee_de_construction: string
prix_min: string
prix_med: string
prix_max: string
zone: number;
maison: boolean;
meuble: boolean;
nombre_de_piece: string;
annee_de_construction: string;
prix_min: string;
prix_med: string;
prix_max: string;
}
4 changes: 4 additions & 0 deletions src/interfaces/json-item-paris.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ export interface ParisAddressItem {
c_ar: number
}
}

export interface ParisAddressItemDB extends ParisAddressItem {
score: number;
}
4 changes: 4 additions & 0 deletions src/interfaces/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export interface DefaultAddressItem {
}
}

export interface DefaultAddressItemDB extends DefaultAddressItem {
score: number;
}

export interface DefaultDistrictItem {
type: 'Feature'
properties: {
Expand Down
17 changes: 9 additions & 8 deletions src/services/address/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
PlaineCommuneAddress,
} from '@db/db'
import { Ad } from '@interfaces/ad'
import { AddressItem, Coordinate } from '@interfaces/shared'
import { ParisAddressItemDB } from '@interfaces/json-item-paris'
import { AddressItem, Coordinate, DefaultAddressItemDB } from '@interfaces/shared'
import { AvailableCities, cityList } from '@services/address/city'
import * as cleanup from '@services/helpers/cleanup'
import { regexString } from '@services/helpers/regex'
Expand Down Expand Up @@ -124,7 +125,7 @@ export class DefaultAddressStrategy implements AddressStrategy {
}

const addressDb = dbMapping[cityList[city].mainCity]
const result = (await addressDb
const result: DefaultAddressItemDB[] = (await addressDb
.find(
{
$text: { $search: query },
Expand All @@ -133,10 +134,10 @@ export class DefaultAddressStrategy implements AddressStrategy {
)
.sort({ score: { $meta: 'textScore' } })
.limit(10)
.lean()) as any
.lean()) as DefaultAddressItemDB[]

return result
? result.map((r) => ({
? result.map((r: DefaultAddressItemDB) => ({
item: {
address: `${r.numero} ${r.nom_voie}`,
postalCode: r.code_postal.toString(),
Expand All @@ -146,7 +147,7 @@ export class DefaultAddressStrategy implements AddressStrategy {
},
},
score: r.score,
streetNumber: cleanup.streetNumber(query),
streetNumber: cleanup.streetNumber(query)?.toString(),
}))
: []
}
Expand Down Expand Up @@ -204,10 +205,10 @@ export class ParisAddressStrategy extends DefaultAddressStrategy {
)
.sort({ score: { $meta: 'textScore' } })
.limit(10)
.lean()) as any
.lean()) as ParisAddressItemDB[]

return result
? result.map((r) => ({
? result.map((r: ParisAddressItemDB) => ({
item: {
address: r.fields.l_adr,
postalCode: ParisAddressStrategy.postalCodeFormat(r.fields.c_ar.toString()),
Expand All @@ -217,7 +218,7 @@ export class ParisAddressStrategy extends DefaultAddressStrategy {
},
},
score: r.score,
streetNumber: cleanup.streetNumber(query),
streetNumber: cleanup.streetNumber(query)?.toString(),
}))
: []
}
Expand Down
13 changes: 5 additions & 8 deletions src/services/helpers/year-built.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,11 @@ export class YearBuiltService {
},
},
},
(err, batie) => {
if (err) {
console.error(err)
}

return batie
}
)
).then((batie) => {
return batie
}).catch((err) => {
console.error(err)
})
}

static getYearBuiltFromBuilding(building) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/shop/relevant-ads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function getRelevantAds(req: Request, res: Response) {
const surfaceRange: number[] = surfaceValue?.split(',')?.map((v) => +v)
const priceRange: number[] = priceValue?.split(',')?.map((v) => +v)
const exceedingRange: number[] = exceedingValue?.split(',')?.map((v) => +v)
const roomRange: number[] = roomValue?.split(',')?.map((v) => +v)
const roomRange: number[] = roomValue && roomValue !== '1,6' && roomValue?.split(',')?.map((v) => +v)
const hasFurniture: boolean = furnishedValue === 'furnished' ? true : furnishedValue === 'nonFurnished' ? false : null

if (!isLegalValue || !['true', 'false'].includes(isLegalValue)) {
Expand Down
11 changes: 6 additions & 5 deletions src/services/websites/bienici/__tests__/bienici.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fs from 'fs'
import { disconnect } from 'mongoose'
import path from 'path'
import { BienIci } from '../bienici'
import { Response } from 'express'

describe('bienici', () => {
afterAll(async () => {
Expand All @@ -22,10 +23,10 @@ describe('bienici', () => {
url: 'https://www.bienici.com/annonce/location/paris-11e/appartement/2pieces/guy-hoquet-immo-facile-4938963?q=%2Frecherche%2Flocation%2Fparis-11e-75011',
}

const mockResponse: any = {
const mockResponse: Response = {
json: jest.fn(),
status: jest.fn(),
}
} as unknown as Response

const bienici = new BienIci(mockResponse, { body })

Expand Down Expand Up @@ -71,10 +72,10 @@ describe('bienici', () => {
url: 'https://www.bienici.com/annonce/location/paris-11e/appartement/2pieces/guy-hoquet-immo-facile-4938963?q=%2Frecherche%2Flocation%2Fparis-11e-75011',
}

const mockResponse: any = {
const mockResponse: Response = {
json: jest.fn(),
status: jest.fn(),
}
} as unknown as Response

const bienici = new BienIci(mockResponse, { body })

Expand Down Expand Up @@ -104,7 +105,7 @@ describe('bienici', () => {
promoPercentage: { order: 8, value: null },
},
isLegal: true,
moreInfo: 'https://encadrement-loyers.lille.fr/',
moreInfo: 'https://www.lille.fr/Vivre-a-Lille/Mon-logement/L-encadrement-des-loyers',
})
})
})
Expand Down
Loading

0 comments on commit b845949

Please sign in to comment.