-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backend/referentiels): ajout de l'import de referentiel
- Loading branch information
Showing
19 changed files
with
675 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as Zod from 'zod'; | ||
|
||
export const getPropertyPaths = (schema: Zod.ZodType): string[] => { | ||
// Adjusted: Signature now uses Zod.ZodType to eliminate null& undefined check | ||
// check if schema is nullable or optional | ||
if (schema instanceof Zod.ZodNullable || schema instanceof Zod.ZodOptional) { | ||
return getPropertyPaths(schema.unwrap()); | ||
} | ||
// check if schema is an array | ||
if (schema instanceof Zod.ZodArray) { | ||
return getPropertyPaths(schema.element); | ||
} | ||
// check if schema is an object | ||
if (schema instanceof Zod.ZodObject) { | ||
// get key/value pairs from schema | ||
const entries = Object.entries<Zod.ZodType>(schema.shape); // Adjusted: Uses Zod.ZodType as generic to remove instanceof check. Since .shape returns ZodRawShape which has Zod.ZodType as type for each key. | ||
// loop through key/value pairs | ||
return entries.flatMap(([key, value]) => { | ||
// get nested keys | ||
const nested = getPropertyPaths(value).map( | ||
(subKey) => `${key}.${subKey}` | ||
); | ||
// return nested keys | ||
return nested.length ? nested : key; | ||
}); | ||
} | ||
// return empty array | ||
return []; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
backend/src/referentiels/models/referentiel-changelog.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { z } from 'zod'; | ||
|
||
export const referentielChangelogSchema = z.object({ | ||
version: z.string().describe('Version du referentiel, ex: 1.0.0'), | ||
date: z.string().describe('Date de publication de la version'), | ||
description: z.string().describe('Description des changements de la version'), | ||
}); | ||
|
||
export type ReferentielChangelogType = z.infer< | ||
typeof referentielChangelogSchema | ||
>; |
31 changes: 31 additions & 0 deletions
31
backend/src/referentiels/models/referentiel-definition.table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { InferSelectModel, sql } from 'drizzle-orm'; | ||
import { pgTable, timestamp, varchar } from 'drizzle-orm/pg-core'; | ||
import { createInsertSchema, createSelectSchema } from 'drizzle-zod'; | ||
import { actionTypeEnum } from './action-type.enum'; | ||
|
||
export const referentielDefinitionTable = pgTable('referentiel_definition', { | ||
id: varchar('id', { length: 30 }).primaryKey().notNull(), | ||
nom: varchar('nom', { length: 300 }).notNull(), | ||
version: varchar('version', { length: 16 }).notNull().default('1.0.0'), | ||
hierarchie: actionTypeEnum('hierarchie').array().notNull(), | ||
created_at: timestamp('created_at', { withTimezone: true, mode: 'string' }) | ||
.default(sql`CURRENT_TIMESTAMP`) | ||
.notNull(), | ||
modified_at: timestamp('modified_at', { withTimezone: true, mode: 'string' }) | ||
.default(sql`CURRENT_TIMESTAMP`) | ||
.notNull(), | ||
}); | ||
|
||
export type ReferentielDefinitionType = InferSelectModel< | ||
typeof referentielDefinitionTable | ||
>; | ||
export type CreateRefentielDefinitionType = InferSelectModel< | ||
typeof referentielDefinitionTable | ||
>; | ||
|
||
export const referentielDefinitionSchema = createSelectSchema( | ||
referentielDefinitionTable | ||
); | ||
export const createReferentielDefinitionSchema = createInsertSchema( | ||
referentielDefinitionTable | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
export enum ReferentielType { | ||
ECI = 'eci', | ||
CAE = 'cae', | ||
TE = 'te', | ||
TE_TEST = 'te-test', | ||
} | ||
// WARNING: not using Object.values to use it with pgTable | ||
export const referentielList = [ | ||
ReferentielType.CAE, | ||
ReferentielType.ECI, | ||
ReferentielType.TE, | ||
ReferentielType.TE_TEST, | ||
] as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.