Skip to content

Commit 8a5efa2

Browse files
authored
Merge pull request #1841 from proconnect-gouv/douglasduteil/track-the-sp-name-from-the-session-in-created-moderations
2 parents a49bbf9 + e142d9f commit 8a5efa2

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

src/controllers/organization.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export const postJoinOrganizationMiddleware = async (
143143
user_id,
144144
confirmed,
145145
certificationRequested: req.session.certificationDirigeantRequested,
146+
sp_name: req.session.spName,
146147
});
147148

148149
if (req.session.mustReturnOneOrganizationInPayload) {

src/managers/organization/join.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,13 @@ export const joinOrganization = async ({
171171
user_id,
172172
confirmed = false,
173173
certificationRequested = false,
174+
sp_name,
174175
}: {
175176
organization: Organization;
176177
user_id: number;
177178
confirmed: boolean;
178179
certificationRequested?: boolean;
180+
sp_name?: string;
179181
}): Promise<UserOrganizationLink> => {
180182
const { siret } = organization;
181183

@@ -435,6 +437,7 @@ export const joinOrganization = async ({
435437
organization_id,
436438
type: ModerationTypeSchema.enum.non_verified_domain,
437439
ticket_id: null,
440+
sp_name,
438441
});
439442
return await linkUserToOrganization({
440443
organization_id,
@@ -501,9 +504,11 @@ export const greetForCertification = async ({
501504
export const createPendingModeration = async ({
502505
user,
503506
organization,
507+
sp_name,
504508
}: {
505509
user: User;
506510
organization: Organization;
511+
sp_name?: string;
507512
}) => {
508513
let ticket_id = null;
509514
const { id: user_id, email } = user;
@@ -527,6 +532,7 @@ export const createPendingModeration = async ({
527532
return createModeration({
528533
user_id,
529534
organization_id,
535+
sp_name,
530536
type: ModerationTypeSchema.enum.organization_join_block,
531537
ticket_id,
532538
});

src/middlewares/navigation-guards.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,9 @@ const processPendingModerationGuard = async (prev: Pass<RequestContext>) => {
829829
if (!Pass.is_passing(context)) return context;
830830

831831
const { id: moderation_id } = await createPendingModeration({
832-
user,
833832
organization,
833+
sp_name: req.session.spName,
834+
user,
834835
});
835836

836837
req.session.pendingModerationOrganizationId = undefined;

src/repositories/moderation.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,30 @@ import { getDatabaseConnection } from "../connectors/postgres";
1010
export const createModeration = async ({
1111
user_id,
1212
organization_id,
13+
sp_name,
1314
type,
1415
ticket_id,
1516
}: {
1617
user_id: number;
1718
organization_id: number;
19+
sp_name?: string;
1820
type: ModerationType;
1921
ticket_id: string | null;
2022
}) => {
2123
const connection = getDatabaseConnection();
2224

2325
const { rows }: QueryResult<Moderation> = await connection.query(
2426
`
25-
INSERT INTO moderations (user_id, organization_id, status, type, ticket_id)
26-
VALUES ($1, $2, $3, $4, $5)
27+
INSERT INTO moderations (user_id, organization_id, status, type, ticket_id, sp_name)
28+
VALUES ($1, $2, $3, $4, $5, $6)
2729
RETURNING *;`,
2830
[
2931
user_id,
3032
organization_id,
3133
ModerationStatusSchema.enum.pending,
3234
type,
3335
ticket_id,
36+
sp_name ?? null,
3437
],
3538
);
3639

0 commit comments

Comments
 (0)