Skip to content

Commit

Permalink
fix(toulouse): fin de l'import
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Oct 25, 2023
1 parent 6991c97 commit f8cd179
Show file tree
Hide file tree
Showing 26 changed files with 828 additions and 344 deletions.
2 changes: 1 addition & 1 deletion docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ volumes:

services:
postgres:
image: postgis/postgis:14-3.4
image: postgres:14.9-alpine3.18
container_name: domifa-postgres
volumes:
- postgres-data:/var/lib/postgresql/data
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@sentry/opentelemetry-node": "^7.72.0",
"@socialgouv/streaming-file-encryption": "^1.1.0",
"@types/source-map-support": "^0.5.4",
"@wmfs/xml2csv": "^1.32.0",
"axios": "^1.4.0",
"bcryptjs": "^2.4.3",
"class-transformer": "0.5.1",
Expand Down Expand Up @@ -103,6 +104,7 @@
"typeorm": "^0.3.17",
"uuid": "^9.0.1",
"xlsx": "^0.18.5",
"xml2csv": "^1.0.1",
"yup": "^0.32.9",
"yup-phone": "^1.3.2"
},
Expand Down
12 changes: 12 additions & 0 deletions packages/backend/src/_common/tmp-toulouse/MOTIF.const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const MOTIF = {
1: "AME",
2: "Demandeur d'asile",
3: "DEMANDE DE PIECE D'IIDENTITE OFFICIELLE",
4: "OUVERTURE DE DROITS",
5: "DEMARCHES ADMINISTRATIVES",
6: "ADRESSE POUR EMPLOYEUR",
7: "RENOUVELLEMENT DES DROITS",
8: "LOGEMENT",
9: "ACCES AUX DROITS",
10: "S.D.F.",
};
215 changes: 215 additions & 0 deletions packages/backend/src/_common/tmp-toulouse/PAYS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
export const PAYS = {
2: "Algérie",
3: "Togo",
5: "Arménie",
6: "Espagne",
7: "Pologne",
8: "Bulgarie",
9: "Mozambique",
10: "Cote d'Ivoire",
11: "Irak",
12: "Maroc",
13: "Syrie",
14: "Roumanie",
15: "Lituanie",
17: "Tunisie",
18: "Tchad",
19: "Russie",
21: "Sierra Leone",
22: "Ukraine",
23: "Rwanda",
24: "Angola",
25: "Italie",
28: "Tchétchénie",
29: "Madagascar",
30: "Moldavie",
35: "Azerbaidjan",
38: "Slovaquie",
39: "Portugal",
41: "Niger",
42: "Turquie",
43: "Somalie",
44: "Cameroun",
45: "Iran",
46: "Libye",
47: "Allemagne",
48: "Albanie",
49: "Soudan",
51: "Nigeria",
52: "Ethiopie",
55: "Finlande",
62: "Suisse",
63: "Laos",
65: "Sénégal",
68: "Biélorussie",
73: "Viêtnam",
74: "France",
76: "Belgique",
78: "Burkina Faso",
81: "Colombie",
83: "Bénin",
85: "Mauritanie",
88: "Estonie",
90: "Bosnie-Herzgovine",
92: "Mongolie",
94: "Djibouti",
96: "Israël",
97: "Hongrie",
98: "Thaïlande",
101: "Burundi",
104: "Jamaïque",
105: "Angleterre",
110: "Pakistan",
111: "Ghana",
113: "Brésil",
114: "Afghanistan",
116: "Gambie",
117: "Lettonie",
121: "Egypte",
122: "Slovénie",
137: "Argentine",
138: "Japon",
140: "Norvège",
142: "Comores",
147: "Mali",
158: "Liban",
160: "Cuba",
161: "Cap-Vert",
168: "Luxembourg",
169: "Inde",
170: "Canada",
171: "Chili",
173: "Mexique",
174: "Cambodge",
177: "Malaisie",
179: "Haïti",
180: "Palestine",
182: "Irlande",
186: "Chine",
188: "Bangladesh",
190: "Guatemala",
191: "Suriname",
192: "Vénézuéla",
193: "Croatie",
194: "République Tchèque",
195: "Corée du Nord",
197: "Philippines",
198: "Monténégro",
201: "Pays-Bas",
202: "Autriche",
206: "Andorre ",
207: "Equateur",
208: "Yémen",
209: "République dominicaine",
210: "Bolivie",
211: "Erythrée",
219: "Sri Lanka",
220: "Ouzbékistan",
222: "Zimbabwe",
224: "Grèce",
225: "Pérou",
226: "Etats-Unis",
227: "Géorgie",
228: "Guinée",
229: "Guinée Equatoriale",
232: "",
233: "Bélorussie",
235: "Koweït",
236: "Gabon",
238: "Costa Rica",
240: "Sahara occidental",
241: "Serbie",
242: "Birmanie",
243: "Ouganda",
244: "Indonesie",
245: "Nouvelle-Zélande",
248: "Emirats arabes unis",
253: "Tanzanie ",
254: "Danemark",
257: "Nicaragua",
260: "Suède",
261: "Sao Tomé-et-Principe",
262: "Royaume-Uni",
265: "Paraguay",
266: "Népal",
267: "Arabie Soudite",
268: "Honduras",
269: "Kenya",
273: "Guinée-Bissau",
274: "Guyane Britannique",
275: "Kosovo",
276: "Australie",
277: "Kazakhstan",
278: "Jordanie",
279: "Sainte-Lucie",
280: "Corée du sud",
281: "Zambie",
282: "Île Maurice",
283: "Abkhazie",
284: "Afrique du Sud",
285: "Antigua-et-Barbuda",
286: "Bahamas",
287: "Bahreïn",
288: "Barbade",
289: "Belize",
290: "Bhoutan",
291: "Botswana",
292: "Brunei",
293: "Chypre du Nord",
294: "Chypre du Sud",
295: "Dominique",
296: "Fidji",
297: "Grenade",
298: "Îles Cook",
299: "Îles Marshall",
300: "Irlande du Nord",
301: "Islande",
302: "Kirghizistan",
303: "Kiribati",
304: "Lesotho",
305: "Liechtenstein",
306: "Malawi",
307: "Maldives",
308: "Malte",
309: "Monaco",
310: "Namibie",
311: "Nauru",
312: "Niue",
313: "Oman",
314: "Ossétie du Sud",
315: "Palaos",
316: "Panama",
317: "Papouasie-Nouvelle-Guinée",
318: "République centrafricaine",
319: "République de Macédoine",
320: "Congo - Brazzaville",
321: "Congo - Kinshasa",
322: "Saint-Christophe-et-Niévès",
323: "Saint-Marin",
324: "Saint-Vincent-et-les-Grenadines",
325: "Salomon",
326: "Salvador",
327: "Samoa",
328: "Seychelles",
329: "Singapour",
330: "Soudan du Sud",
331: "Swaziland",
342: "Tadjikistan",
343: "Taïwan",
344: "Timor oriental",
345: "Tonga",
346: "Trinité-et-Tobago",
347: "Turkménistan",
348: "Tuvalu",
349: "Uruguay",
350: "Vanuatu",
351: "Vatican",
352: "Micronésie",
353: "Myanmar",
354: "Qatar",
355: "Somaliland",
356: "Tchécoslovaquie",
357: "Yougoslavie",
358: "Zaïre",
359: "Liberia",
};
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const TOULOUSE_STRUCTURE_ID = 1;
export const TOULOUSE_USER_ID = 1;
11 changes: 11 additions & 0 deletions packages/backend/src/_common/tmp-toulouse/getDateFromXml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { isValid, parse, startOfDay } from "date-fns";

export const getDateFromXml = (dateString: string | number): Date => {
const parsedDate = startOfDay(
parse(dateString.toString(), "yyyyMMdd", new Date())
);
if (!isValid(parsedDate)) {
throw new Error("CANNOT ADD DATE " + dateString);
}
return parsedDate;
};
5 changes: 5 additions & 0 deletions packages/backend/src/_common/tmp-toulouse/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @index('./*', f => `export * from '${f.path}'`)
export * from "./getDateFromXml";
export * from "./PAYS";
export * from "./TOULOUSE_STRUCTURE_ID.const";
export * from "./TUsager.interface";
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class AutoMigration1692191990700 implements MigrationInterface {
name = "AutoMigration1692191990700";

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "TmpHistorique" ("uuid" uuid NOT NULL DEFAULT uuid_generate_v4(), "id_domicilie" integer, "date" text, "type" character varying, CONSTRAINT "PK_523a02c717798d1433428afd730" PRIMARY KEY ("uuid"))`
);
await queryRunner.query(
`CREATE INDEX "IDX_9e9c1ff1cb8c52d25db6bf797f" ON "TmpHistorique" ("id_domicilie") `
);
await queryRunner.query(
`CREATE INDEX "IDX_3acc64a514fefafef16717cb93" ON "TmpHistorique" ("type") `
);
await queryRunner.query(
`CREATE TABLE "TmpCourriers" ("uuid" uuid NOT NULL DEFAULT uuid_generate_v4(), "IDDomicilie" integer, "date" integer, "Date_recup" integer, "motif" integer, CONSTRAINT "PK_8520f03ab40677e4503ae9fdf0a" PRIMARY KEY ("uuid"))`
);
await queryRunner.query(
`CREATE INDEX "IDX_9b82e742c9c3762d05a73b6a40" ON "TmpCourriers" ("IDDomicilie") `
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "TmpHistorique"`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,20 @@ export class ManualMigration1692191990701 implements MigrationInterface {
const outputFile =
domifaConfig().upload.basePath + "/toulouse/usagers.json";

readFile(inputFile, "utf8", (err, xmlData) => {
if (err) {
console.error(
`Erreur lors de la lecture du fichier XML : ${err.message}`
);
return;
}
const xmlData = await readFile(inputFile, "utf8");

const options = {
attributeNamePrefix: "_",
attrNodeName: "attr",
textNodeName: "#text",
ignoreAttributes: false,
parseAttributeValue: true,
};
const options = {
attributeNamePrefix: "_",
attrNodeName: "attr",
textNodeName: "#text",
ignoreAttributes: false,
parseAttributeValue: true,
};

const parser = new XMLParser(options);
const jsonData = parser.parse(xmlData);
const parser = new XMLParser(options);
const jsonData = parser.parse(xmlData);

// Écriture du fichier JSON
writeFile(
outputFile,
JSON.stringify(jsonData, null, 2),
"utf8",
(writeErr) => {
if (writeErr) {
console.error(
`Erreur lors de l'écriture du fichier JSON : ${writeErr.message}`
);
return;
}
console.log(
"Conversion réussie ! Fichier sauvegardé à l'emplacement :" +
outputFile
);
}
);
});
await writeFile(outputFile, JSON.stringify(jsonData, null, 2), "utf8");
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand Down
Loading

0 comments on commit f8cd179

Please sign in to comment.