Skip to content

Commit

Permalink
fix: add notes
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Nov 19, 2023
1 parent 131f429 commit c0cc840
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 9 deletions.
5 changes: 4 additions & 1 deletion packages/backend/src/_common/model/usager/Usager.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export type Usager = AppEntity & {
etapeDemande: number;
rdv: UsagerRdv | null;
entretien: UsagerEntretien;
pinnedNote: Partial<UsagerNote> | null;
pinnedNote: Pick<
UsagerNote,
"message" | "usagerRef" | "createdAt" | "createdBy"
> | null;

// INFOS DOMICILIATION
typeDom: UsagerTypeDom;
Expand Down
13 changes: 13 additions & 0 deletions packages/backend/src/_common/tmp-toulouse/getDateFromXml.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { isNil } from "lodash";
import { isValid, parse, startOfDay } from "date-fns";
import striptags from "striptags";

export const getDateFromXml = (dateString: string | number): Date => {
const parsedDate = startOfDay(
Expand All @@ -9,3 +11,14 @@ export const getDateFromXml = (dateString: string | number): Date => {
}
return parsedDate;
};

export const getText = (str?: string): string => {
if (isNil(str)) {
return "";
}

return striptags(str.toString())
.replace(/[\\$~*<>{}]/gi, "")
.replace(/\s+/g, " ")
.trim();
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import {
StructureLight,
UsagerTypeDom,
} from "../_common/model";
import { myDataSource, usagerRepository, UsagerTable } from "../database";
import {
myDataSource,
usagerNotesRepository,
UsagerNotesTable,
usagerRepository,
UsagerTable,
} from "../database";

import { usagersCreator } from "../usagers/services";
import { domifaConfig } from "../config";
Expand All @@ -20,6 +26,7 @@ import {
TUsager,
PAYS,
getDateFromXml,
getText,
} from "../_common/tmp-toulouse";
import { tmpHistoriqueRepository } from "../database/services/interaction/historiqueRepository.service";

Expand Down Expand Up @@ -139,7 +146,7 @@ export class ManualMigration1692191990702 implements MigrationInterface {
: [],
dateNaissance: getDateFromXml(usagerToulouse.date_naissance),
customRef:
usagerToulouse?.Num_domici.toString() ??
usagerToulouse?.Num_domici?.toString() ??
usagerToulouse.IDDomicilie.toString(),
lastInteraction: {
dateInteraction: lastInteractionDate,
Expand All @@ -155,7 +162,7 @@ export class ManualMigration1692191990702 implements MigrationInterface {
dateDecision,
statut,
userName: "DomiFa",
userId: 1200,
userId: 1,
dateFin,
dateDebut,
typeDom,
Expand All @@ -164,9 +171,54 @@ export class ManualMigration1692191990702 implements MigrationInterface {
},
};

usagersCreator.setUsagerDefaultAttributes(partialUsager);
const usager = new UsagerTable(partialUsager);
usagersCreator.setUsagerDefaultAttributes(usager);
await usagerRepository.save(usager);

if (usagerToulouse?.procuration === 1) {
await usagerNotesRepository.save(
new UsagerNotesTable({
message: getText(usagerToulouse?.nom_procuration),
usagerRef: usager.ref,
usagerUUID: usager.uuid,
pinned: false,
structureId: TOULOUSE_STRUCTURE_ID,
createdBy: {
userId: 1,
userName: "DomiFa",
},
archived: false,
})
);
}

if (getText(usagerToulouse?.Remarques) !== "") {
const newNote = new UsagerNotesTable({
message: getText(usagerToulouse?.Remarques),
usagerRef: usager.ref,
usagerUUID: usager.uuid,
pinned: true,
structureId: TOULOUSE_STRUCTURE_ID,
createdBy: {
userId: 1,
userName: "DomiFa",
},
archived: false,
});
await usagerNotesRepository.save(newNote);

await usagerRepository.update(
{ uuid: usager.uuid },
{
pinnedNote: {
message: newNote.message,
usagerRef: newNote.usagerRef,
createdAt: newNote.createdAt,
createdBy: newNote.createdBy,
},
}
);
}
}

await queryRunner.commitTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ export class ManualMigration1697659880952 implements MigrationInterface {
usagerRef: usager.ref,
dateInteraction: getDateFromXml(interaction.date),
type: "visite",
userId: 1200,
userId: 1,
userName: "DomiFa",
structureId: TOULOUSE_STRUCTURE_ID,
event: "create",
interactionOutUUID: null,
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ export class UsagerTable
public numeroDistribution!: string | null;

@Column({ type: "jsonb", default: null, nullable: true })
public pinnedNote!: Partial<UsagerNote> | null;
public pinnedNote!: Pick<
UsagerNote,
"usagerRef" | "createdAt" | "createdBy" | "message"
> | null;

public constructor(entity?: Partial<UsagerTable>) {
super(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function findNextUsagerRef(structureId: number): Promise<number> {
return usager?.ref ? usager?.ref + 1 : 1;
}

function setUsagerDefaultAttributes(usager: Usager): void {
function setUsagerDefaultAttributes(usager: Partial<Usager>): void {
usager.options = {
transfert: {
actif: false,
Expand Down

0 comments on commit c0cc840

Please sign in to comment.