From e91c4613b731830aff2eac90d738241dfad3e992 Mon Sep 17 00:00:00 2001 From: Yassine R Date: Fri, 8 Sep 2023 14:42:21 +0200 Subject: [PATCH] fix: suppression de migrations --- .../1684358283099-manual-migration.ts | 30 ------ .../1694090707867-manual-migration.ts | 101 ------------------ 2 files changed, 131 deletions(-) delete mode 100644 packages/backend/src/_migrations/1684358283099-manual-migration.ts delete mode 100644 packages/backend/src/_migrations/1694090707867-manual-migration.ts diff --git a/packages/backend/src/_migrations/1684358283099-manual-migration.ts b/packages/backend/src/_migrations/1684358283099-manual-migration.ts deleted file mode 100644 index de3057d871..0000000000 --- a/packages/backend/src/_migrations/1684358283099-manual-migration.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -import { usagerRepository, userUsagerRepository } from "../database"; - -export class ManualMigration1684358283099 implements MigrationInterface { - public async up(): Promise { - const message = "[MIGRATION] [BORDEAUX] "; - console.log(message + "Suppression des comptes usagers de Bordeaux"); - - await userUsagerRepository.delete({ - structureId: 201, - }); - - console.log(message + "Activation des sms pour les usagers de bordeaux"); - - await usagerRepository - .createQueryBuilder("usager") - .update({ - contactByPhone: true, - }) - .where( - `telephone->>'numero' != '' and decision->>'statut' = :statut and "structureId" = :structureId `, - { structureId: 201, statut: "VALIDE" } - ) - .execute(); - } - - // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function - public async down(_queryRunner: QueryRunner): Promise {} -} diff --git a/packages/backend/src/_migrations/1694090707867-manual-migration.ts b/packages/backend/src/_migrations/1694090707867-manual-migration.ts deleted file mode 100644 index cb87595e68..0000000000 --- a/packages/backend/src/_migrations/1694090707867-manual-migration.ts +++ /dev/null @@ -1,101 +0,0 @@ -import { Usager, UsagerOptions, UserStructureProfile } from "../_common/model"; -import { userUsagerCreator } from "../users/services"; -import { format } from "date-fns"; -import { getPhoneString } from "../util/phone"; -import { join } from "path"; -import { appendFile, ensureDir } from "fs-extra"; -import { MigrationInterface, QueryRunner } from "typeorm"; -import { domifaConfig } from "../config"; -import { userStructureRepository, usagerRepository } from "../database"; - -const serializeUserUsager = (newUserUsager: any) => { - const { - ref, - customRef, - nom, - prenom, - dateNaissance, - telephone, - login, - temporaryPassword, - } = newUserUsager; - - return `${ref}\t${customRef}\t${nom}\t${prenom}\t${dateNaissance}\t${telephone}\t${login}\t${temporaryPassword}`; -}; - -export class ManualMigration1694090707866 implements MigrationInterface { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - public async up(_queryRunner: QueryRunner): Promise { - const message = "[MIGRATION] [BORDEAUX] "; - await ensureDir(join(domifaConfig().upload.basePath, "tmp-bordeaux")); - - const fileName = join( - domifaConfig().upload.basePath, - "tmp-bordeaux", - "comptes-bordeaux" - ); - - console.log(message + "Activation des comptes usagers de bordeaux"); - - const user: UserStructureProfile = await userStructureRepository.findOneBy({ - role: "admin", - structureId: 201, - }); - - const usagers: Partial[] = await usagerRepository - .createQueryBuilder("usager") - .where( - `decision->>'statut' = :statut and "structureId" = :structureId and (options->>'portailUsagerEnabled')::boolean is false`, - { structureId: 201, statut: "VALIDE" } - ) - .select( - `"uuid", "structureId", "dateNaissance", "telephone", "nom", "prenom", "customRef", "ref", "options"` - ) - .execute(); - - console.log(message + usagers.length + " comptes usagers à créer"); - - let cpt = 0; - for (const usager of usagers) { - const { login, temporaryPassword } = - await userUsagerCreator.createUserWithTmpPassword( - { - usagerUUID: usager.uuid, - structureId: usager.structureId, - }, - { creator: user } - ); - - const newUserUsager = { - ref: usager.ref, - customRef: usager.customRef, - nom: usager.nom, - prenom: usager.prenom, - dateNaissance: format(new Date(usager.dateNaissance), "dd/MM/yyyy"), - telephone: getPhoneString(usager.telephone), - login, - temporaryPassword, - }; - - const options: UsagerOptions = { - ...usager.options, - portailUsagerEnabled: true, - }; - - await usagerRepository.update({ uuid: usager.uuid }, { options }); - await appendFile(fileName, serializeUserUsager(newUserUsager) + "\n"); - - cpt++; - if (cpt % 200 === 0) { - console.log(message + cpt + "/" + usagers.length + " comptes créés"); - } - } - - console.log(message + cpt + "/" + usagers.length + " comptes créés"); - } - - // eslint-disable-next-line @typescript-eslint/no-unused-vars - public async down(_queryRunner: QueryRunner): Promise { - // - } -}