Skip to content

Commit

Permalink
fix(procuration): fix delete procurations
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Dec 6, 2023
1 parent cee9576 commit b1e78eb
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ fileignoreconfig:
checksum: f0d4b3cd2e6e2d9b1e0271c34d64adacf87a5f1e7a505402a20869962543608d
- filename: packages/backend/src/_migrations/1699910877010-auto-migration.ts
checksum: bd05dd6b68f7fe2ca36ab1180a0449878cf78f4e048d2e5979b3dbe5fba1db53
- filename: packages/backend/src/_migrations/1701870413794-auto-migration.ts
checksum: 281adc67c437b0c3ea874865872dafb0b6a4b23be044694caa6f0d210bbba0f9
- filename: packages/backend/src/_migrations/_init-db/1603812391580-pr-env-create-database.ts
checksum: 5e9ab65fc62b00a2a2092ccbcf0e2c9fdecefe418452b15b579425774cc1e1e2
- filename: packages/backend/src/_portail-admin/portail-admin-login/portail-admin-login.controller.spec.ts
Expand Down
30 changes: 30 additions & 0 deletions packages/backend/src/_migrations/1701870413794-auto-migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import { domifaConfig } from "../config";

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

public async up(queryRunner: QueryRunner): Promise<void> {
if (
domifaConfig().envId === "preprod" ||
domifaConfig().envId === "prod" ||
domifaConfig().envId === "local"
) {
await queryRunner.query(
`ALTER TABLE "usager" ALTER COLUMN "lastInteraction" DROP DEFAULT`
);
await queryRunner.query(
`ALTER TABLE "usager" ALTER COLUMN "options" DROP DEFAULT`
);
await queryRunner.query(
`CREATE INDEX "IDX_b3d70227bb45dd8060e256ee33" ON "interactions" ("procuration") `
);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DROP INDEX "public"."IDX_b3d70227bb45dd8060e256ee33"`
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class InteractionsTable
@JoinColumn({ name: "usagerUUID", referencedColumnName: "uuid" })
usagerUUID: string;

@Index()
@Column({ type: "boolean", nullable: true })
procuration: boolean | null;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsNull } from "typeorm";
import { In, IsNull } from "typeorm";
import { getDateForMonthInterval } from "../../../stats/services";
import { FranceRegion } from "../../../util/territoires";
import { Usager, UserStructureAuthenticated } from "../../../_common/model";
Expand All @@ -17,7 +17,7 @@ export const interactionRepository = myDataSource
countVisiteOut,
updateInteractionAfterDistribution,
totalInteractionAllUsagersStructure,
getLastInteractionOut,
findLastInteractionOut,
});

async function updateInteractionAfterDistribution(
Expand Down Expand Up @@ -240,17 +240,20 @@ async function totalInteractionAllUsagersStructure({
);
}

async function getLastInteractionOut(
async function findLastInteractionOut(
usager: Pick<Usager, "uuid">
): Promise<Pick<CommonInteraction, "uuid" | "dateInteraction"> | null> {
return interactionRepository
.createQueryBuilder("interactions")
.where(`"usagerUUID" = :uuid`, { uuid: usager.uuid })
.andWhere("type IN (:...types)", { types: INTERACTION_OK_LIST })
.andWhere(`"procuration" = false OR "procuration" IS NULL`, {
procurationFalse: false,
})
.select([`"dateInteraction"`, "uuid"])
.orderBy(`"dateInteraction"`, "DESC")
.getOne();
return interactionRepository.findOne({
where: {
type: In(INTERACTION_OK_LIST),
procuration: IsNull(),
usagerUUID: usager.uuid,
},
select: {
dateInteraction: true,
},
order: {
dateInteraction: "DESC",
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import {
userUsagerLoginRepository,
} from "../../database";
import { CommonInteraction } from "@domifa/common";

export const getLastInteractionOut = async (
usager: Usager,
structure: Pick<Structure, "id" | "sms" | "telephone" | "portailUsager">,
interaction?: CommonInteraction
) => {
let dateInteraction = await getDateFromInteraction(usager, interaction);

dateInteraction = await getDateFromUserLogin(
usager,
structure,
Expand All @@ -32,9 +34,10 @@ const getDateFromInteraction = async (
!interaction
) {
const lastInteractionOut =
await interactionRepository.getLastInteractionOut(usager);
await interactionRepository.findLastInteractionOut(usager);
return lastInteractionOut ? lastInteractionOut.dateInteraction : null;
}

return null;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class ProfilHistoriqueCourriersComponent implements OnInit, OnDestroy {
public params: PageOptions = {
order: Order.DESC,
page: 1,
take: 10,
take: 50,
};

public searchResults: PageResults<Interaction> = {
Expand Down Expand Up @@ -103,6 +103,7 @@ export class ProfilHistoriqueCourriersComponent implements OnInit, OnDestroy {
.getInteractions(this.usager.ref, this.params)
.subscribe((searchResults: PageResults<Interaction>) => {
this.loading = false;
console.log(searchResults);
this.interactions = searchResults.data;
this.searchResults = searchResults;
window.scroll({
Expand Down

0 comments on commit b1e78eb

Please sign in to comment.