Skip to content

Commit

Permalink
chore(types): types db & mauvais appel du kdbClient dans les corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
FaXaq committed Nov 7, 2024
1 parent 66eba73 commit b7ef18b
Show file tree
Hide file tree
Showing 72 changed files with 41 additions and 197 deletions.
72 changes: 31 additions & 41 deletions server/src/db/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,51 @@ import { sleep } from "@/utils/asyncUtils";
import type { DB as DBSchema } from "./schema";

// gestion du typage des vues matérialisée inspirée de https://github.com/RobinBlomberg/kysely-codegen/issues/72
export interface FormationMaterializedView extends Omit<DBSchema, "formationNonMaterializedView"> {
formationView: {
[K in keyof DBSchema["formationNonMaterializedView"]]: NonNullable<DBSchema["formationNonMaterializedView"][K]>;
};
}
export interface FormationScolaireMaterializedView extends Omit<DBSchema, "formationNonMaterializedView"> {
formationScolaireView: {
[K in keyof DBSchema["formationNonMaterializedView"]]: NonNullable<DBSchema["formationNonMaterializedView"][K]>;
export interface DB
extends Omit<
DBSchema,
| "demandeIntentionNonMaterializedView"
| "latestDemandeIntentionNonMaterializedView"
| "latestIntentionNonMaterializedView"
| "latestDemandeNonMaterializedView"
| "formationNonMaterializedView"
> {
demandeIntentionView: {
[K in keyof DBSchema["demandeIntentionNonMaterializedView"]]: NonNullable<
DBSchema["demandeIntentionNonMaterializedView"][K]
>;
};
}

export interface FormationApprentissageMaterializedView extends Omit<DBSchema, "formationNonMaterializedView"> {
formationApprentissageView: {
[K in keyof DBSchema["formationNonMaterializedView"]]: NonNullable<DBSchema["formationNonMaterializedView"][K]>;
};
}
export interface LatestDemandeMaterializedView extends Omit<DBSchema, "latestDemandeNonMaterializedView"> {
latestDemandeView: {
[K in keyof DBSchema["latestDemandeNonMaterializedView"]]: NonNullable<
DBSchema["latestDemandeNonMaterializedView"][K]
latestDemandeIntentionView: {
[K in keyof DBSchema["latestDemandeIntentionNonMaterializedView"]]: NonNullable<
DBSchema["latestDemandeIntentionNonMaterializedView"][K]
>;
};
}

export interface LatestIntentionMaterializedView extends Omit<DBSchema, "latestIntentionNonMaterializedView"> {
latestIntentionView: {
[K in keyof DBSchema["latestIntentionNonMaterializedView"]]: NonNullable<
DBSchema["latestIntentionNonMaterializedView"][K]
>;
};
}
export interface LatestDemandeIntentionMaterializedView
extends Omit<DBSchema, "latestDemandeIntentionNonMaterializedView"> {
latestDemandeIntentionView: {
[K in keyof DBSchema["latestDemandeIntentionNonMaterializedView"]]: NonNullable<
DBSchema["latestDemandeIntentionNonMaterializedView"][K]

latestDemandeView: {
[K in keyof DBSchema["latestDemandeNonMaterializedView"]]: NonNullable<
DBSchema["latestDemandeNonMaterializedView"][K]
>;
};
}
export interface DemandeIntentionMaterializedView extends Omit<DBSchema, "demandeIntentionNonMaterializedView"> {
demandeIntentionView: {
[K in keyof DBSchema["demandeIntentionNonMaterializedView"]]: NonNullable<
DBSchema["demandeIntentionNonMaterializedView"][K]
>;

formationApprentissageView: {
[K in keyof DBSchema["formationNonMaterializedView"]]: NonNullable<DBSchema["formationNonMaterializedView"][K]>;
};
}

export type DB =
| FormationMaterializedView
| FormationScolaireMaterializedView
| FormationApprentissageMaterializedView
| LatestDemandeMaterializedView
| LatestIntentionMaterializedView
| LatestDemandeIntentionMaterializedView
| DemandeIntentionMaterializedView;
formationScolaireView: {
[K in keyof DBSchema["formationNonMaterializedView"]]: NonNullable<DBSchema["formationNonMaterializedView"][K]>;
};

formationView: {
[K in keyof DBSchema["formationNonMaterializedView"]]: NonNullable<DBSchema["formationNonMaterializedView"][K]>;
};
}

let kdb: Kysely<DB> | null = null;
let pool: pg.Pool | null = null;
Expand Down
9 changes: 3 additions & 6 deletions server/src/migrations/migration_1709130910845.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// @ts-nocheck

/* eslint-disable @typescript-eslint/no-explicit-any */
import type { Kysely } from "kysely";

import type { DB } from "@/db/db";

export const up = async (db: Kysely<unknown>) => {
export const up = async (db: Kysely<any>) => {
await db.schema.dropView("formationScolaireView").materialized().ifExists().execute();

await db.schema.dropView("formationApprentissageView").materialized().ifExists().execute();
Expand Down Expand Up @@ -190,7 +187,7 @@ export const up = async (db: Kysely<unknown>) => {
.execute();
};

export const down = async (db: Kysely<DB>) => {
export const down = async (db: Kysely<any>) => {
await db.schema.dropView("formationScolaireView").materialized().ifExists().execute();
await db.schema.dropView("formationApprentissageView").materialized().ifExists().execute();

Expand Down
8 changes: 3 additions & 5 deletions server/src/migrations/migration_1709134782543.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// @ts-nocheck
/* eslint-disable @typescript-eslint/no-explicit-any */

import type { Kysely } from "kysely";

import type { DB } from "@/db/db";

export const up = async (db: Kysely<DB>) => {
export const up = async (db: Kysely<any>) => {
await db.schema.dropView("formationScolaireView").materialized().ifExists().execute();

await db.schema.dropView("formationApprentissageView").materialized().ifExists().execute();
Expand Down Expand Up @@ -186,7 +184,7 @@ export const up = async (db: Kysely<DB>) => {
.execute();
};

export const down = async (db: Kysely<DB>) => {
export const down = async (db: Kysely<any>) => {
await db.schema.dropView("formationScolaireView").materialized().ifExists().execute();
await db.schema.dropView("formationApprentissageView").materialized().ifExists().execute();

Expand Down
9 changes: 3 additions & 6 deletions server/src/migrations/migration_1709632374350.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// @ts-nocheck

/* eslint-disable @typescript-eslint/no-explicit-any */
import type { Kysely } from "kysely";

import type { DB } from "@/db/db";

export const up = async (db: Kysely<DB>) => {
export const up = async (db: Kysely<any>) => {
await db.schema.dropView("formationScolaireView").materialized().ifExists().execute();

await db.schema.dropView("formationApprentissageView").materialized().ifExists().execute();
Expand Down Expand Up @@ -178,7 +175,7 @@ export const up = async (db: Kysely<DB>) => {
.execute();
};

export const down = async (db: Kysely<DB>) => {
export const down = async (db: Kysely<any>) => {
await db.schema.dropView("formationScolaireView").materialized().ifExists().execute();
await db.schema.dropView("formationApprentissageView").materialized().ifExists().execute();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import { sql } from "kysely";
import { CURRENT_IJ_MILLESIME, CURRENT_RENTREE } from "shared";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import type { ExpressionBuilder } from "kysely";
import { sql } from "kysely";
import { capitalize, values } from "lodash-es";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import { sql } from "kysely";
import { RaisonCorrectionEnum } from "shared/enum/raisonCorrectionEnum";

Expand Down Expand Up @@ -29,7 +27,7 @@ export const getStatsCorrectionsQuery = async ({
}: Filters) => {
const search_array = getNormalizedSearchArray(search);

const statsCorrections = await getKbdClient
const statsCorrections = await getKbdClient()
.selectFrom("correction")
.leftJoin("latestDemandeView as demande", "demande.numero", "correction.intentionNumero")
.leftJoin("dataFormation", "dataFormation.cfd", "demande.cfd")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-nocheck -- TODO
import { CURRENT_IJ_MILLESIME } from "shared";

import { getKbdClient } from "@/db/db";
Expand All @@ -18,9 +17,7 @@ const getStatsSortieBase = ({
}) => {
const statsSortie = getKbdClient()
.selectFrom("indicateurRegionSortie")
// @ts-expect-error
.innerJoin("formationScolaireView as formationView", "formationView.cfd", "indicateurRegionSortie.cfd")
// @ts-expect-error
.where((w) => {
if (!codeRegion) return w.val(true);
if (Array.isArray(codeRegion)) return w("indicateurRegionSortie.codeRegion", "in", codeRegion);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import type { z } from "zod";

import { getStatsSortieParRegionsQuery } from "@/modules/data/queries/getStatsSortie/getStatsSortie";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-nocheck -- TODO
import { sql } from "kysely";
import { CURRENT_IJ_MILLESIME, CURRENT_RENTREE } from "shared";
import { getMillesimePrecedent } from "shared/utils/getMillesime";
Expand Down Expand Up @@ -26,11 +25,8 @@ export const getFormationsDepartementBase = ({
orderBy,
}: Filters) =>
getKbdClient()
// @ts-expect-error
.selectFrom("formationScolaireView as formationView")
// @ts-expect-error
.leftJoin("formationEtablissement", "formationEtablissement.cfd", "formationView.cfd")
// @ts-expect-error
.leftJoin("niveauDiplome", "niveauDiplome.codeNiveauDiplome", "formationView.codeNiveauDiplome")
.leftJoin("dispositif", "formationEtablissement.codeDispositif", "dispositif.codeDispositif")
.leftJoin("indicateurEntree", (join) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-nocheck -- TODO
import Boom from "@hapi/boom";
import { sql } from "kysely";
import { CURRENT_IJ_MILLESIME, CURRENT_RENTREE } from "shared";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import { getStatsSortieParRegionsQuery } from "@/modules/data/queries/getStatsSortie/getStatsSortie";
import { getPositionQuadrant } from "@/modules/data/services/getPositionQuadrant";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import { getKbdClient } from "@/db/db";
import { cleanNull } from "@/utils/noNull";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import { CURRENT_IJ_MILLESIME } from "shared";

import type { Filters } from "@/modules/data/usecases/getDataForPanoramaRegion/getDataForPanoramaRegion.schema";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import { sql } from "kysely";
import { CURRENT_IJ_MILLESIME, CURRENT_RENTREE } from "shared";
import { getMillesimePrecedent } from "shared/utils/getMillesime";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import { getMillesimeFromRentreeScolaire } from "shared/utils/getMillesime";
import type { z } from "zod";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import { sql } from "kysely";
import { jsonBuildObject } from "kysely/helpers/postgres";
import type { MILLESIMES_IJ } from "shared";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import Boom from "@hapi/boom";
import { sql } from "kysely";
import { CURRENT_IJ_MILLESIME, CURRENT_RENTREE } from "shared";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import type { ExpressionBuilder } from "kysely";
import { sql } from "kysely";
import { CURRENT_RENTREE } from "shared";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import { sql } from "kysely";
import { jsonBuildObject } from "kysely/helpers/postgres";
import { CURRENT_IJ_MILLESIME, CURRENT_RENTREE } from "shared";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import type { ExpressionBuilder } from "kysely";
import { sql } from "kysely";
import { CURRENT_RENTREE } from "shared";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import { sql } from "kysely";
import { CURRENT_IJ_MILLESIME, CURRENT_RENTREE } from "shared";
import { PositionQuadrantEnum } from "shared/enum/positionQuadrantEnum";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import type { MILLESIMES_IJ } from "shared";
import type { z } from "zod";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import type { ExpressionBuilder } from "kysely";
import { sql } from "kysely";
import type { MILLESIMES_IJ } from "shared";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import { CURRENT_IJ_MILLESIME } from "shared";

import { getKbdClient } from "@/db/db";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import { getMillesimeFromCampagne } from "shared/time/millesimes";

import { getCurrentCampagneQuery } from "@/modules/data/queries/getCurrentCampagne/getCurrentCampagne.query";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import { sql } from "kysely";
import { NEXT_RENTREE } from "shared/time/NEXT_RENTREE";

Expand Down
2 changes: 0 additions & 2 deletions server/src/modules/data/usecases/getRegion/getRegion.query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import Boom from "@hapi/boom";
import { sql } from "kysely";
import { CURRENT_IJ_MILLESIME, CURRENT_RENTREE } from "shared";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import type { ExpressionBuilder } from "kysely";
import { sql } from "kysely";
import { CURRENT_RENTREE } from "shared";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import { sql } from "kysely";
import { jsonBuildObject } from "kysely/helpers/postgres";
import { DemandeTypeEnum } from "shared/enum/demandeTypeEnum";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import { sql } from "kysely";
import { CURRENT_RENTREE } from "shared";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import { sql } from "kysely";
import { CURRENT_RENTREE } from "shared";
import type { z } from "zod";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

// eslint-disable-next-line import/no-extraneous-dependencies, n/no-extraneous-import
import { inject } from "injecti";
import { uniqWith } from "lodash-es";
Expand Down
2 changes: 0 additions & 2 deletions server/src/modules/data/utils/notAnneeCommune.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import type { ExpressionBuilder } from "kysely";

import type { DB } from "@/db/db";
Expand Down
2 changes: 0 additions & 2 deletions server/src/modules/data/utils/notHistorique.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import type { ExpressionBuilder } from "kysely";
import { sql } from "kysely";

Expand Down
2 changes: 0 additions & 2 deletions server/src/modules/data/utils/onDemande.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import { expressionBuilder, sql } from "kysely";
import type { DemandeStatutType } from "shared/enum/demandeStatutEnum";
import { DemandeTypeEnum } from "shared/enum/demandeTypeEnum";
Expand Down
2 changes: 0 additions & 2 deletions server/src/modules/data/utils/openForRentreeScolaire.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import type { ExpressionBuilder } from "kysely";
import { sql } from "kysely";

Expand Down
2 changes: 0 additions & 2 deletions server/src/modules/data/utils/tauxPression.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import type { ExpressionBuilder, RawBuilder } from "kysely";
import { expressionBuilder, sql } from "kysely";
import { CURRENT_RENTREE } from "shared";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck -- TODO

import { getKbdClient } from "@/db/db";
import { cleanNull } from "@/utils/noNull";

Expand Down
Loading

0 comments on commit b7ef18b

Please sign in to comment.