-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
326 additions
and
93 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
34 changes: 0 additions & 34 deletions
34
packages/backend/src/_migrations/1723547616571-create-structure-information-migration.ts
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
packages/backend/src/_migrations/1728487458329-manual-migration.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,39 @@ | ||
import { IsNull, MigrationInterface } from "typeorm"; | ||
import { openDataPlaceRepository } from "../database"; | ||
import { getStructureType } from "../open-data-places/functions"; | ||
import { appLogger } from "../util"; | ||
import { domifaConfig } from "../config"; | ||
|
||
export class UpdateStructureTypeMigration1728487458329 | ||
implements MigrationInterface | ||
{ | ||
name = "UpdateStructureTypeMigration1728487458329"; | ||
public async up(): Promise<void> { | ||
if ( | ||
domifaConfig().envId === "prod" || | ||
domifaConfig().envId === "preprod" || | ||
domifaConfig().envId === "local" | ||
) { | ||
appLogger.info("[MIGRATION] Update structureType for OpenData"); | ||
const places = await openDataPlaceRepository.find({ | ||
where: { | ||
domifaStructureId: IsNull(), | ||
}, | ||
select: ["nom", "uuid"], | ||
}); | ||
|
||
for (const place of places) { | ||
await openDataPlaceRepository.update( | ||
{ uuid: place.uuid }, | ||
{ | ||
structureType: getStructureType(place.nom), | ||
} | ||
); | ||
} | ||
} | ||
} | ||
|
||
public async down(): Promise<void> { | ||
// | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/backend/src/_migrations/1728487663488-manual-migration.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,25 @@ | ||
import { MigrationInterface } from "typeorm"; | ||
import { appLogsRepository } from "../database"; | ||
import { domifaConfig } from "../config"; | ||
|
||
export class DeleteUselessLogsMigration1728487663488 | ||
implements MigrationInterface | ||
{ | ||
name = "DeleteUselessLogsMigration1728487663488"; | ||
|
||
public async up(): Promise<void> { | ||
if ( | ||
domifaConfig().envId === "prod" || | ||
domifaConfig().envId === "preprod" || | ||
domifaConfig().envId === "local" | ||
) { | ||
await appLogsRepository.delete({ | ||
action: "USAGERS_DOCS_DOWNLOAD", | ||
}); | ||
} | ||
} | ||
|
||
public async down(): Promise<void> { | ||
// | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
packages/backend/src/open-data-places/functions/getStructureType.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,47 @@ | ||
import { StructureType } from "@domifa/common"; | ||
import slug from "slug"; | ||
import striptags from "striptags"; | ||
|
||
export const getStructureType = (input: string): StructureType | null => { | ||
if (!input) { | ||
return null; | ||
} | ||
const strippedInput = striptags(input).toLowerCase().trim(); | ||
|
||
const normalizedInput = slug(strippedInput, { | ||
mode: "rfc3986" as const, | ||
lower: true, | ||
replacement: " ", // Utiliser des espaces au lieu des tirets | ||
remove: /[^a-z0-9\s]/g, // Supprimer tous les caractères non alphanumériques sauf les espaces | ||
locale: "fr", | ||
trim: true, | ||
}); | ||
|
||
if (!normalizedInput) { | ||
return null; | ||
} | ||
|
||
if ( | ||
normalizedInput.includes("ccas") || | ||
normalizedInput.startsWith("commune") || | ||
normalizedInput.startsWith("centre communal") || | ||
normalizedInput.startsWith("centre communal daction sociale") || | ||
normalizedInput.includes("centre daction sociale") || | ||
normalizedInput.startsWith("mairie") || | ||
normalizedInput.startsWith("hotel de ville") | ||
) { | ||
return "ccas"; | ||
} | ||
|
||
if ( | ||
normalizedInput.startsWith("cias") || | ||
normalizedInput.startsWith("centre intercommunal") || | ||
normalizedInput.includes("communaute de communes") || | ||
normalizedInput.includes("centre intercommunal daction sociale") || | ||
normalizedInput.includes("intercommunal") | ||
) { | ||
return "cias"; | ||
} | ||
|
||
return "asso"; | ||
}; |
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,2 @@ | ||
// @index('./*.ts', f => `export * from '${f.path}'`) | ||
export * from "./getStructureType"; |
19 changes: 19 additions & 0 deletions
19
packages/backend/src/open-data-places/functions/tests/STRUCTURE_NAMES.const.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,19 @@ | ||
export const STRUCTURE_NAMES = { | ||
"4AJ Plateforme Logement Jeunes CLLAJ ARRAS": "asso", | ||
"A fratellanza": "asso", | ||
"Abri de la Providence": "asso", | ||
"ACCEPTESS-T": "asso", | ||
ACCES: "asso", | ||
"Accueil de Jour Association Eole": "asso", | ||
"Accueil de jour de Douai Croix rouge Française": "asso", | ||
"AHLIS 46": "asso", | ||
"AIDE A L'INSERTION DES DEMANDEURS D'ASILE": "asso", | ||
AVAF: "asso", | ||
"BOUTIQUE SOLIDARITÉ EMMAÜS DE BEAUVAIS": "asso", | ||
"Boutique Solidarité": "asso", | ||
Bruillot: "asso", | ||
"C.C.A.S de la commune de Martillac": "ccas", | ||
"C.C.A.S DE PAMIERS": "ccas", | ||
"CIAS de Domène": "cias", | ||
Vista: "asso", | ||
}; |
41 changes: 41 additions & 0 deletions
41
packages/backend/src/open-data-places/functions/tests/getStructureType.spec.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,41 @@ | ||
import { getStructureType } from "../getStructureType"; | ||
import { STRUCTURE_NAMES } from "./STRUCTURE_NAMES.const"; | ||
|
||
describe("checkOrganizationType", () => { | ||
it("should correctly identify organization types for all entries", () => { | ||
Object.entries(STRUCTURE_NAMES).forEach(([name, expectedType]) => { | ||
const result = getStructureType(name); | ||
expect(result).toBe(expectedType); | ||
}); | ||
}); | ||
|
||
it("should return an empty string for unrecognized inputs", () => { | ||
const unrecognizedInputs = [ | ||
"Random Organization", | ||
"Just a regular company", | ||
]; | ||
|
||
unrecognizedInputs.forEach((input) => { | ||
expect(getStructureType(input)).toBe("asso"); | ||
}); | ||
}); | ||
|
||
it("should handle edge cases correctly", () => { | ||
const edgeCases = { | ||
"": null, | ||
" ": null, | ||
CCAS: "ccas", | ||
cias: "cias", | ||
Association: "asso", | ||
"<script>CCAS</script>": "ccas", | ||
"C.C.A.S.": "ccas", | ||
"Centre Communal d'Action Sociale": "ccas", | ||
"MAIRIE-CCAS": "ccas", | ||
"Organisme-Association": "asso", | ||
}; | ||
|
||
Object.entries(edgeCases).forEach(([input, expected]) => { | ||
expect(getStructureType(input)).toBe(expected); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.