Skip to content

Commit

Permalink
update TS and ramda 😱
Browse files Browse the repository at this point in the history
  • Loading branch information
enguerranws committed Sep 24, 2024
1 parent b51444e commit a9bed0b
Show file tree
Hide file tree
Showing 27 changed files with 544 additions and 548 deletions.
8 changes: 4 additions & 4 deletions back/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"pino-pretty": "^7.5.4",
"prom-client": "^14.0.1",
"querystring": "^0.2.1",
"ramda": "^0.28.0",
"ramda": "^0.30.1",
"shared": "workspace:*",
"shared-routes": "^0.8.17",
"ts-node": "^10.9.1",
Expand All @@ -97,12 +97,12 @@
"@types/jest": "^29.5.2",
"@types/jsonwebtoken": "^9.0.2",
"@types/multer": "^1.4.7",
"@types/node": "^18.13.0",
"@types/node": "^20.15.0",
"@types/pg": "^8.10.2",
"@types/pg-format": "^1.0.2",
"@types/pino": "^7.0.4",
"@types/pino-http": "^5.8.1",
"@types/ramda": "^0.28.20",
"@types/ramda": "^0.30.2",
"@types/request": "^2.48.8",
"@types/supertest": "^2.0.12",
"@types/uuid": "^8.3.4",
Expand All @@ -115,6 +115,6 @@
"supertest": "^6.2.2",
"ts-node-dev": "^2.0.0",
"ts-prune": "^0.10.3",
"typescript": "^5.3.2"
"typescript": "^5.6.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class InMemoryConventionQueries implements ConventionQueries {
id: ConventionId,
): Promise<ConventionReadDto | undefined> {
const convention = this.conventionRepository.conventions.find(
propEq("id", id),
propEq(id, "id"),
);
if (!convention) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe("PgOutboxQueries for crawling purposes", () => {
expectToEqual(eventsToRerun, [eventFailedToRerun]);
});

it("finds all events that have failed and should be reprocessed, event if some publication was OK before", async () => {
it("finds all events that have failed and should be reprocessed, even if some publication was OK before", async () => {
await storeInOutbox([
neverPublished1,
withFailureButEventuallySuccessfulEvent,
Expand Down
3 changes: 2 additions & 1 deletion back/src/domains/core/events/adapters/PgOutboxQueries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { groupBy, map, prop, values } from "ramda";
import { groupBy, isNil, map, prop, reject, values } from "ramda";
import { pipeWithValue } from "shared";
import { KyselyDb } from "../../../../config/pg/kysely/kyselyUtils";
import { DomainEvent } from "../events";
Expand Down Expand Up @@ -68,5 +68,6 @@ const convertRowsToDomainEvents = (rows: StoredEventRow[]): DomainEvent[] =>
rows,
groupBy(prop("id")),
values,
reject(isNil),
map(storedEventRowsToDomainEvent),
);
7 changes: 3 additions & 4 deletions back/src/domains/core/events/adapters/PgOutboxRepository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { differenceWith } from "ramda";
import { DateString, propEq, replaceArrayElement } from "shared";
import { differenceWith, propEq } from "ramda";
import { DateString, replaceArrayElement } from "shared";
import { KyselyDb } from "../../../../config/pg/kysely/kyselyUtils";
import { counterEventsSavedBeforePublish } from "../../../../utils/counters";
import { createLogger } from "../../../../utils/logger";
Expand Down Expand Up @@ -188,12 +188,11 @@ export const storedEventRowsToDomainEvent = (
const publishedAt: DateString = row.published_at.toISOString();

const existingPublicationIndex = acc.publications.findIndex(
propEq("publishedAt", publishedAt),
propEq(publishedAt, "publishedAt"),
);

const existingPublication: EventPublication | undefined =
acc.publications[existingPublicationIndex];

if (!existingPublication) {
const failures: EventFailure[] = row.subscription_id
? [
Expand Down
34 changes: 25 additions & 9 deletions back/src/domains/core/sirene/adapters/InseeSiretGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { Logger } from "pino";
import {
NafDto,
NumberEmployeesRange,
OmitFromExistingKeys,
SiretDto,
SiretEstablishmentDto,
castError,
errors,
filterNotFalsy,
propEq,
queryParamsAsString,
} from "shared";
import { AxiosConfig } from "../../../../config/bootstrap/appConfig";
Expand Down Expand Up @@ -203,6 +203,19 @@ export class InseeSiretGateway implements SiretGateway {
}
}

type InseePeriodeEtablissment = Partial<{
dateFin: string | null;
dateDebut: string | null;
etatAdministratifEtablissement: "A" | "F";
}>;

type InseePeriodeEtablissmentWithDateFin = OmitFromExistingKeys<
InseePeriodeEtablissment,
"dateFin"
> & {
dateFin: string | null;
};

export type InseeApiRawEstablishment = {
siret: string;
uniteLegale: Partial<{
Expand All @@ -221,13 +234,7 @@ export type InseeApiRawEstablishment = {
codePostalEtablissement?: string;
libelleCommuneEtablissement?: string;
}>;
periodesEtablissement: Array<
Partial<{
dateFin: string | null;
dateDebut: string | null;
etatAdministratifEtablissement: "A" | "F";
}>
>;
periodesEtablissement: Array<InseePeriodeEtablissment>;
};

type SirenGatewayAnswer = {
Expand Down Expand Up @@ -285,11 +292,20 @@ const getFormattedAddress = ({
.filter(filterNotFalsy)
.join(" ");

const hasDateFin = (
periode: InseePeriodeEtablissment,
): periode is InseePeriodeEtablissmentWithDateFin =>
periode.dateFin !== undefined;

const getIsActive = ({
uniteLegale,
periodesEtablissement,
}: InseeApiRawEstablishment) => {
const lastPeriod = periodesEtablissement.find(propEq("dateFin", null));
const periodesEtablissementWithDateFin =
periodesEtablissement.filter(hasDateFin);
const lastPeriod = periodesEtablissementWithDateFin.find(
({ dateFin }) => dateFin === null,
);
if (!lastPeriod) return false;

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FormEstablishmentDto, SiretDto, errors, propEq } from "shared";
import { propEq } from "ramda";
import { FormEstablishmentDto, SiretDto, errors } from "shared";
import { FormEstablishmentRepository } from "../ports/FormEstablishmentRepository";

export class InMemoryFormEstablishmentRepository
Expand Down Expand Up @@ -29,7 +30,7 @@ export class InMemoryFormEstablishmentRepository
public async getBySiret(
siretToGet: SiretDto,
): Promise<FormEstablishmentDto | undefined> {
return this.#formEstablishments.find(propEq("siret", siretToGet));
return this.#formEstablishments.find(propEq(siretToGet, "siret"));
}

// for testing purpose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ const isSiretIsNotInNotSearchableResults =
(searchImmersionQueryResults: SearchImmersionResult[]) =>
<T extends { siret: SiretDto }>({ siret }: T) =>
!searchImmersionQueryResults
.filter(propEq("isSearchable", false))
.filter(propEq(false, "isSearchable"))
.map(prop("siret"))
.includes(siret);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export class BrevoEstablishmentMarketingGateway
};

return this.#createContact(body).then((response) => {
if (existingContact ? 204 : 201) return;
const successHttpCode = existingContact ? 204 : 201;
if (successHttpCode) return;
throw new Error(
`Bad response with status '${
response.status
Expand Down
2 changes: 1 addition & 1 deletion back/src/scripts/triggerEstablishmentLeadReminders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const reminderReport = ({
establishmentsReminded,
errors,
}: SendEstablishmentLeadReminderOutput) => {
const failures = keys(errors);
const failures = errors ? keys(errors) : [];
const numberOfFailures = failures.length;

return [
Expand Down
2 changes: 1 addition & 1 deletion back/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es6",
"target": "ES2018",
"lib": ["esNext", "ES2015"],
"module": "CommonJS",
"resolveJsonModule": true,
Expand Down
8 changes: 4 additions & 4 deletions front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"@sentry/browser": "^7.56.0",
"@sentry/vite-plugin": "^2.3.0",
"@types/jest": "^29.5.2",
"@types/node": "^18.13.0",
"@types/node": "^20.15.0",
"@types/papaparse": "^5.3.7",
"@types/ramda": "^0.28.20",
"@types/ramda": "^0.30.2",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.10",
"@types/react-lines-ellipsis": "^0.15.1",
Expand All @@ -59,7 +59,7 @@
"openapi-types": "^12.1.3",
"papaparse": "^5.3.2",
"postcss": "^8.4.31",
"ramda": "^0.28.0",
"ramda": "^0.30.1",
"react": "^18.0.0",
"react-design-system": "workspace:*",
"react-dom": "^18.0.0",
Expand All @@ -78,7 +78,7 @@
"ts-pattern": "^5.0.0",
"tss-react": "^4.5.2",
"type-route": "^1.0.0",
"typescript": "^5.3.2",
"typescript": "^5.6.2",
"uuid": "^8.3.2",
"vite": "^5.3.5",
"vite-plugin-pwa": "^0.17.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,6 @@ const isAllowedTransition = (
actingRoles.some((actingRole) =>
transitionConfig.validRoles.includes(actingRole),
) &&
(!transitionConfig.refine?.(convention).isError ?? true)
!transitionConfig.refine?.(convention).isError
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,19 @@ export const AddEstablishmentsByBatch = () => {
}}
/>
<table className={cx(fr.cx("fr-mt-2w"), classes.table)}>
<thead>
<tr>
{keys(candidateEstablishments[0].formEstablishment).map(
(key) => (
<th scope="col" key={key}>
{key}
</th>
),
)}
</tr>
</thead>
{candidateEstablishments[0].formEstablishment && (
<thead>
<tr>
{keys(candidateEstablishments[0].formEstablishment).map(
(key) => (
<th scope="col" key={key}>
{key}
</th>
),
)}
</tr>
</thead>
)}
<tbody>
{candidateEstablishments.map((establishment, index) => (
<>
Expand Down
4 changes: 2 additions & 2 deletions front/src/app/components/agency/AgencyAdminAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { fr } from "@codegouvfr/react-dsfr";
import InfoRoundedIcon from "@mui/icons-material/InfoRounded";
import { Tooltip } from "@mui/material";
import Autocomplete from "@mui/material/Autocomplete";
import { prop } from "ramda";
import { prop, propEq } from "ramda";
import React from "react";
import { useDispatch } from "react-redux";
import { AgencyId, AgencyOption, domElementIds, propEq } from "shared";
import { AgencyId, AgencyOption, domElementIds } from "shared";
import { useAppSelector } from "src/app/hooks/reduxHooks";
import { agencyAdminSelectors } from "src/core-logic/domain/admin/agenciesAdmin/agencyAdmin.selectors";
import { agencyAdminSlice } from "src/core-logic/domain/admin/agenciesAdmin/agencyAdmin.slice";
Expand Down
4 changes: 2 additions & 2 deletions libs/html-templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"devDependencies": {
"@types/jest": "^29.5.2",
"@types/node": "^18.13.0",
"typescript": "^5.3.2"
"@types/node": "^20.15.0",
"typescript": "^5.6.2"
}
}
2 changes: 1 addition & 1 deletion libs/react-design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@
"storybook": "^7.0.0",
"tss-react": "^4.5.2",
"type-route": "^1.0.0",
"typescript": "^5.3.2"
"typescript": "^5.6.2"
}
}
6 changes: 3 additions & 3 deletions libs/scss-mapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@types/jest": "^29.5.2",
"@types/node": "^18.13.0",
"@types/ramda": "^0.28.20",
"@types/node": "^20.15.0",
"@types/ramda": "^0.30.2",
"babel-jest": "^29.5.0",
"jest": "^29.5.0",
"jest-environment-node-single-context": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.3.2"
"typescript": "^5.6.2"
},
"jest": {
"testEnvironment": "jest-environment-node-single-context"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"lint-staged": "^13.0.3",
"prettier": "^2.6.0",
"turbo": "1.4.6",
"typescript": "^5.3.2"
"typescript": "^5.6.2"
},
"engines": {
"node": "^20.15.0"
Expand Down
2 changes: 1 addition & 1 deletion playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@faker-js/faker": "^8.3.1",
"@playwright/test": "^1.45.3",
"@types/jest": "^29.5.2",
"@types/node": "^18.19.3",
"@types/node": "^20.15.0",
"dotenv": "^16.0.0",
"shared": "workspace:*"
},
Expand Down
2 changes: 1 addition & 1 deletion playwright/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "ES6",
"target": "ES2018",
"lib": ["DOM", "DOM.Iterable", "ESNext", "ES2015"],
"allowJs": false,
"skipLibCheck": false,
Expand Down
Loading

0 comments on commit a9bed0b

Please sign in to comment.