Unverified Commit 22691ff2 authored by Remi Mélisson's avatar Remi Mélisson Committed by GitHub
Browse files

fix(deps): use eslint, update dependencies (#87)

parent 9a1602ec
Pipeline #132475 passed with stages
in 49 seconds
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"@socialgouv/eslint-config-recommended",
"plugin:import/typescript"
]
}
\ No newline at end of file
......@@ -8,33 +8,40 @@
"dev": "nodemon --watch 'src/**' --ext 'ts' --ignore '__tests__' --exec 'ts-node src/index.ts'",
"build": "ncc build src/index.ts -o dist",
"start": "node dist/index.js",
"test": "jest"
"test": "jest",
"lint": "eslint src/**/*.ts"
},
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.12.18",
"@elastic/elasticsearch": "^7.12.0",
"@koa/cors": "^3.1.0",
"@socialgouv/kali-data": "^2.61.0",
"@socialgouv/kali-data": "^2.132.0",
"koa": "^2.13.1",
"koa-router": "^10.0.0"
},
"devDependencies": {
"@socialgouv/eslint-config-recommended": "^1.75.0",
"@types/jest": "^26.0.23",
"@types/koa": "^2.13.3",
"@types/koa-router": "^7.4.2",
"@types/koa__cors": "^3.0.2",
"@types/lodash.pick": "^4.4.6",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^4.26.1",
"@typescript-eslint/parser": "^4.26.1",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-prettier": "^3.4.1",
"@vercel/ncc": "^0.28.6",
"eslint": "^7.31.0",
"jest": "^26.6.3",
"nodemon": "^2.0.7",
"prettier": "^2.2.1",
"supertest": "^6.1.3",
"ts-jest": "^26.5.6",
"ts-node": "^9.1.1",
"tslint": "^6.1.3",
"typescript": "^4.1.5"
"ts-node": "^10.2.1",
"typescript": "^4.4.1"
},
"jest": {
"testTimeout": 10000,
......
import supertest from "supertest";
import * as http from "http";
import Koa from "koa";
import supertest from "supertest";
import { API_PREFIX, router } from "../routes";
export const app = new Koa();
const app = new Koa();
app.use(router.routes());
// .on("error", (err, ctx) => {
// console.error("server error", err, ctx);
......@@ -34,11 +35,12 @@ describe("Test search", () => {
expect(body.entreprises).toBeDefined();
expect(body.entreprises.length).toEqual(20);
expect(body.entreprises[0].siren).toEqual(michelinSiren);
// eslint-disable-next-line no-unused-vars
const { matchingEtablissement, ...partialBody } = body.entreprises[0];
expect(partialBody).toMatchSnapshot();
});
test("test with limit", async () => {
test("with limit", async () => {
const limit = 50;
const { body } = await searchCall("michelin", undefined, limit);
expect(body.entreprises.length).toEqual(limit);
......
const { Client } = require("@elastic/elasticsearch");
import { Client } from "@elastic/elasticsearch";
const ELASTICSEARCH_URL =
process.env.ELASTICSEARCH_URL || "http://localhost:9200";
const API_KEY = process.env.ELASTICSEARCH_API_KEY;
......@@ -9,8 +10,8 @@ export const ELASTICSEARCH_INDEX =
process.env.ELASTICSEARCH_INDEX || "recherche-entreprises";
const esClientConfig = {
node: ELASTICSEARCH_URL,
auth,
node: ELASTICSEARCH_URL,
};
export const elasticsearchClient = new Client(esClientConfig);
......@@ -8,7 +8,7 @@ const defaultLimit = 20;
const conventionsSet = Object.fromEntries(
kaliConventions.map((c) => {
const { num, etat, id, mtime, texte_de_base, url, title } = c;
return [num, { etat, id, mtime, texte_de_base, url, title }];
return [num, { etat, id, mtime, texte_de_base, title, url }];
})
);
......@@ -102,12 +102,12 @@ export const mapHit = ({
highlightLabel,
label,
matching,
simpleLabel,
siren,
matchingEtablissement: {
siret,
address,
siret,
},
simpleLabel,
siren,
};
};
......@@ -193,7 +193,7 @@ export const entrepriseSearchBody = ({
{ rank_feature },
// rank by siret with minimum boosting in order to ensure results appear in the same order
// useful to always have the same first etablissement when no address passed
{ rank_feature: { field: "siretRank", boost: 0.1 } },
{ rank_feature: { boost: 0.1, field: "siretRank" } },
],
},
},
......
import { elasticsearchClient, ELASTICSEARCH_INDEX } from "../elastic";
import { entrepriseSearchBody, mapHit } from "../elastic/queries";
import { ELASTICSEARCH_INDEX, elasticsearchClient } from "../elastic";
import type { SearchArgs } from "../elastic/queries";
import { entrepriseSearchBody, mapHit } from "../elastic/queries";
export const search = async ({
query,
......@@ -10,11 +10,11 @@ export const search = async ({
limit,
}: SearchArgs) => {
const body = entrepriseSearchBody({
query,
address,
addAllConventions,
onlyWithConvention,
address,
limit,
onlyWithConvention,
query,
});
const response = await elasticsearchClient.search({
......@@ -33,10 +33,10 @@ export const search = async ({
export const searchEntreprise = async (siren: string) => {
const body = entrepriseSearchBody({
query: siren,
addAllConventions: true,
onlyWithConvention: false,
limit: 1,
onlyWithConvention: false,
query: siren,
});
const response = await elasticsearchClient.search({
......@@ -55,10 +55,10 @@ export const searchEntreprise = async (siren: string) => {
export const searchEtablissement = async (siret: string) => {
const body = entrepriseSearchBody({
query: siret,
addAllConventions: false,
onlyWithConvention: false,
limit: 1,
onlyWithConvention: false,
query: siret,
});
const response = await elasticsearchClient.search({
......
import Router from "koa-router";
import { search, searchEntreprise, searchEtablissement } from "../lib";
import pkg from "../../package.json";
import { search, searchEntreprise, searchEtablissement } from "../lib";
export const router = new Router();
......@@ -16,11 +16,11 @@ router.get(`${API_PREFIX}/search`, async (ctx) => {
try {
const entreprises = await search({
query: query as string,
addAllConventions: true,
address: address as string,
limit: parseInt(limit as string),
onlyWithConvention: !!onlyWithConvention,
addAllConventions: true,
query: query as string,
});
ctx.body = { entreprises };
} catch (err) {
......@@ -94,8 +94,8 @@ router.get(`/healthz`, (ctx) => {
router.get(`/`, (ctx) => {
ctx.body = {
about: "https://github.com/SocialGouv/recherche-entreprises",
success: true,
version: pkg.version,
about: "https://github.com/SocialGouv/recherche-entreprises",
};
});
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment