Skip to content

Commit 25db647

Browse files
committed
feat(FON-414): sort members in protocol order
1 parent 3913a6f commit 25db647

10 files changed

Lines changed: 40 additions & 6 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
BEGIN;
2+
3+
-- AlterTable
4+
ALTER TABLE "identity_and_access_context"."users" ADD COLUMN "sort" SMALLINT NOT NULL DEFAULT 1000;
5+
6+
-- AlterTable
7+
ALTER TABLE "docs"."official_report_member" ADD COLUMN "sort" SMALLINT NOT NULL DEFAULT 1000;
8+
9+
ALTER TABLE "docs"."official_report_member" ALTER COLUMN "sort" DROP DEFAULT;
10+
11+
12+
COMMIT;

apps/api/prisma/schemas/docs.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ model OfficialReportMember {
125125
firstName String @map("first_name")
126126
lastName String @map("last_name")
127127
title String?
128+
sort Int @db.SmallInt
128129
129130
officialReport OfficialReport @relation(fields: [officialReportId], references: [id], onDelete: Cascade, onUpdate: NoAction)
130131

apps/api/prisma/schemas/identity.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ model User {
3535
password String
3636
gender PrismaGenderEnum
3737
createdAt DateTime @default(now()) @map("created_at") @db.Timestamp(6)
38+
sort Int @default(1000) @db.SmallInt
3839
3940
title PrismaUserTitleEnum? @unique()
4041
duty PrismaUserDutyEnum?

apps/api/src/modules/docs/domain/official-report.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('OfficialReport', () => {
2121
id: 'chairman-1',
2222
role: Role.MEMBRE_DU_SIEGE,
2323
title: 'PRESIDENT_SIEGE',
24+
sort: 1,
2425
},
2526
formation: Magistrat.Formation.SIEGE,
2627
hasRenunciation: true,
@@ -63,6 +64,7 @@ describe('OfficialReport', () => {
6364
lastName: 'descartes',
6465
gender: Gender.M,
6566
title: null,
67+
sort: 2,
6668
},
6769
],
6870
absentMembers: new Set(['member-1']),
@@ -77,6 +79,7 @@ describe('OfficialReport', () => {
7779
id: 'chairman-1',
7880
role: Role.MEMBRE_DU_SIEGE,
7981
title: 'PRESIDENT_SIEGE',
82+
sort: 1,
8083
},
8184
formation: Magistrat.Formation.SIEGE,
8285
hasRenunciation: true,
@@ -115,6 +118,7 @@ describe('OfficialReport', () => {
115118

116119
authorId: 'author-1',
117120
chairman: {
121+
sort: 1,
118122
displayTitle: null,
119123
duty: 'PRESIDENT',
120124
firstName: 'victor',
@@ -165,6 +169,7 @@ describe('OfficialReport', () => {
165169
lastName: 'descartes',
166170
gender: Gender.M,
167171
title: null,
172+
sort: 2,
168173
},
169174
],
170175
absentMembers: new Set(['member-1']),
@@ -179,6 +184,7 @@ describe('OfficialReport', () => {
179184
id: 'chairman-1',
180185
role: Role.MEMBRE_DU_SIEGE,
181186
title: 'PRESIDENT_SIEGE',
187+
sort: 1,
182188
},
183189
hasRenunciation: true,
184190
justiceDepartmentContactId: 'contact-1',

apps/api/src/modules/docs/domain/official-report.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type OfficialReportUser = {
1717
displayTitle: string | null;
1818
title: UserTitleEnum | null;
1919
duty: UserDutyEnum | null;
20+
sort: number;
2021
};
2122

2223
export class ChairmanIsNotMember extends Error {}
@@ -37,7 +38,7 @@ export class OfficialReportCreated {
3738
readonly hasRenunciation: boolean,
3839
readonly justiceDepartmentContactId: string,
3940
readonly chairman: OfficialReportUser,
40-
readonly secretary: OfficialReportUser,
41+
readonly secretary: Omit<OfficialReportUser, 'sort'>,
4142
readonly agendaIds: readonly string[],
4243
readonly members: readonly {
4344
id: string;
@@ -46,6 +47,7 @@ export class OfficialReportCreated {
4647
gender: Gender;
4748
title: string | null;
4849
isAbsent: boolean;
50+
sort: number;
4951
}[],
5052
readonly authorId: string,
5153
) {}
@@ -64,7 +66,7 @@ export class OfficialReportUpdated {
6466
readonly hasRenunciation: boolean,
6567
readonly justiceDepartmentContactId: string,
6668
readonly chairman: OfficialReportUser,
67-
readonly secretary: OfficialReportUser,
69+
readonly secretary: Omit<OfficialReportUser, 'sort'>,
6870
readonly agendaIds: readonly string[],
6971
readonly members: readonly {
7072
id: string;
@@ -73,6 +75,7 @@ export class OfficialReportUpdated {
7375
gender: Gender;
7476
title: string | null;
7577
isAbsent: boolean;
78+
sort: number;
7679
}[],
7780
readonly authorId: string,
7881
) {}
@@ -103,7 +106,7 @@ export class OfficialReport {
103106
hasRenunciation: boolean;
104107
justiceDepartmentContactId: string;
105108
chairman: OfficialReportUser;
106-
secretary: OfficialReportUser;
109+
secretary: Omit<OfficialReportUser, 'sort'>;
107110
agendas: readonly {
108111
id: string;
109112
formation: Magistrat.Formation;
@@ -190,7 +193,7 @@ export class OfficialReport {
190193
hasRenunciation: boolean;
191194
justiceDepartmentContactId: string;
192195
chairman: OfficialReportUser;
193-
secretary: OfficialReportUser;
196+
secretary: Omit<OfficialReportUser, 'sort'>;
194197
agendas: readonly {
195198
id: string;
196199
formation: Magistrat.Formation;
@@ -232,7 +235,7 @@ export class OfficialReport {
232235
hasRenunciation: boolean;
233236
justiceDepartmentContactId: string;
234237
chairman: OfficialReportUser;
235-
secretary: OfficialReportUser;
238+
secretary: Omit<OfficialReportUser, 'sort'>;
236239
agendas: readonly {
237240
id: string;
238241
formation: Magistrat.Formation;

apps/api/src/modules/docs/infrastructure/queries/find-official-report-document.query.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export class FindOfficialReportDocumentQuery {
5757
gender: true,
5858
title: true,
5959
isAbsent: true,
60+
sort: true,
6061
},
6162
},
6263
nominationFiles: {
@@ -132,6 +133,7 @@ export class FindOfficialReportDocumentQuery {
132133
gender: prismaGenderEnumToGenderEnum(m.gender),
133134
displayTitle: m.title,
134135
isAbsent: m.isAbsent,
136+
sort: m.sort,
135137
})),
136138
files: ctx.nominationFiles.flatMap((f) => {
137139
if (!f.outcome) return [];

apps/api/src/modules/docs/infrastructure/repositories/official-report.repository.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export class OfficialReportRepository {
153153
gender: m.gender,
154154
title: m.title,
155155
isAbsent: m.isAbsent,
156+
sort: m.sort,
156157
})),
157158
},
158159
},
@@ -191,6 +192,7 @@ export class OfficialReportRepository {
191192
gender: m.gender,
192193
title: m.title,
193194
isAbsent: m.isAbsent,
195+
sort: m.sort,
194196
})),
195197
},
196198
},

apps/api/src/modules/docs/infrastructure/services/renderers/templates/official-report.html.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { conjunctionList, date, displayTitled, fullname } from '../helpers';
66
import { UserTitleEnum } from 'src/modules/administration/domain/user-enum';
77
import { DocNominationFileOutcomeEnum } from 'src/modules/docs/domain/doc-nomination-file-outcome';
88
import { DateOnly } from 'src/utils/date-only';
9+
import { unaccent } from 'src/utils/unaccent';
910

1011
import { commonDocumentCss, documentLayout } from './common.html';
1112

@@ -75,6 +76,7 @@ function content(ctx: {
7576
gender: Gender;
7677
displayTitle: string | null;
7778
isAbsent: boolean;
79+
sort: number;
7880
}[];
7981
chairman: {
8082
id: string | null;
@@ -107,7 +109,7 @@ function content(ctx: {
107109
${ctx.members
108110
.filter((member) => ctx.chairman.id === null || member.id === null || member.id !== ctx.chairman.id)
109111
.filter((member) => !member.isAbsent)
110-
.sort((a, b) => a.lastName.localeCompare(b.lastName))
112+
.sort((a, b) => a.sort - b.sort || unaccent(a.lastName).localeCompare(unaccent(b.lastName)))
111113
.map((member) => `<li>${displayTitled(member)}</li>`)
112114
.join('')}
113115
</ul>

apps/api/src/modules/members/infrastructure/queries/internal-find-members-by-formation.query.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class InternalFindMembersByFormationQuery {
3636
title: true,
3737
displayTitle: true,
3838
duty: true,
39+
sort: true,
3940
},
4041
});
4142

@@ -48,6 +49,7 @@ export class InternalFindMembersByFormationQuery {
4849
title: u.title ?? null,
4950
displayTitle: u.displayTitle ?? null,
5051
duty: u.duty ?? null,
52+
sort: u.sort,
5153
}));
5254
}
5355
}
@@ -62,5 +64,6 @@ export class InternalMemberListDto extends createZodDto(
6264
title: z.enum(PrismaUserTitleEnum).nullable(),
6365
displayTitle: z.string().nullable(),
6466
duty: z.enum(PrismaUserDutyEnum).nullable(),
67+
sort: z.number(),
6568
}),
6669
) {}

apps/api/src/modules/members/infrastructure/queries/internal-get-member.query.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class InternalGetMemberQuery {
2929
displayTitle: true,
3030
title: true,
3131
duty: true,
32+
sort: true,
3233
},
3334
});
3435

@@ -53,5 +54,6 @@ export class InternalMemberDto extends createZodDto(
5354
displayTitle: z.string().nullable(),
5455
title: z.enum(PrismaUserTitleEnum).nullable(),
5556
duty: z.enum(PrismaUserDutyEnum).nullable(),
57+
sort: z.number(),
5658
}),
5759
) {}

0 commit comments

Comments
 (0)