Skip to content

Commit

Permalink
Merge pull request #25 from betagouv/mep
Browse files Browse the repository at this point in the history
feat: share reports + pwa
  • Loading branch information
ledouxm authored Jun 25, 2024
2 parents f2566b9 + 8e53a9a commit 2435e85
Show file tree
Hide file tree
Showing 29 changed files with 2,242 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

dev-dist
# dependencies
node_modules
/.pnp
Expand Down
1 change: 1 addition & 0 deletions db/migrations/09-add_redacted_id.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "report" ADD COLUMN "redactedById" TEXT;
23 changes: 18 additions & 5 deletions packages/backend/src/features/mail.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { createTransport } from "nodemailer";
import { ENV } from "../envVars";
import { Report } from "@cr-vif/electric-client/frontend";
import { format } from "date-fns";

const transporter = createTransport({
host: ENV.EMAIL_HOST,
Expand All @@ -13,26 +15,37 @@ const transporter = createTransport({
export const sendReportMail = ({
recipients,
pdfBuffer,
reportTitle,
report,
}: {
recipients: string;
pdfBuffer: Buffer;
reportTitle?: string;
report: Report;
}) => {
return transporter.sendMail({
from: ENV.EMAIL_EMITTER,
to: recipients,
subject: "CR VIF - Compte rendu" + (reportTitle ? ` : ${reportTitle}` : ""),
text: "Veuillez trouver ci-joint le compte rendu de votre rendez-vous.",
subject: "Compte-rendu UDAP : " + (report?.title ? ` : ${report.title}` : ""),
text: `Bonjour,
vous trouverez ci-joint le compte-rendu de notre rendez-vous.
Ce compte-rendu est un nouveau dispositif en phase de développement pour but d’aider l’usager
dans sa démarche. Aidez-nous à l’améliorer en répondant à ce questionnaire anonyme de moins d’une minute : https://adtk8x51mbw.eu.typeform.com/to/LHrKhXkd
Cordialement`,
attachments: [
{
filename: "compte_rendu.pdf",
filename: getPDFInMailName(report),
content: pdfBuffer,
},
],
});
};

const getPDFInMailName = (report: Report) => {
const date = format(report.meetDate || new Date(), "dd-MM-yyyy");
return `compte_rendu_UDAP_${[report.applicantName?.replaceAll(" ", ""), date].filter(Boolean).join("_")}.pdf`;
};

export const sendPasswordResetMail = ({ email, temporaryLink }: { email: string; temporaryLink: string }) => {
return transporter.sendMail({
from: ENV.EMAIL_EMITTER,
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/routes/pdfRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const pdfPlugin: FastifyPluginAsyncTypebox = async (fastify, _) => {

const report = await db.report.findUnique({ where: { id: reportId } });

await sendReportMail({ recipients: recipients.join(","), pdfBuffer: pdf, reportTitle: report?.title ?? undefined });
await sendReportMail({ recipients: recipients.join(","), pdfBuffer: pdf, report: report! });

return url;
});
Expand Down
45 changes: 36 additions & 9 deletions packages/electric-client/src/generated/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const DelegationScalarFieldEnumSchema = z.enum(['createdBy','delegatedTo'

export const QueryModeSchema = z.enum(['default','insensitive']);

export const ReportScalarFieldEnumSchema = z.enum(['id','title','projectDescription','redactedBy','meetDate','applicantName','applicantAddress','projectCadastralRef','projectSpaceType','decision','precisions','contacts','furtherInformation','createdBy','createdAt','serviceInstructeur','pdf','disabled','udap_id']);
export const ReportScalarFieldEnumSchema = z.enum(['id','title','projectDescription','redactedBy','meetDate','applicantName','applicantAddress','projectCadastralRef','projectSpaceType','decision','precisions','contacts','furtherInformation','createdBy','createdAt','serviceInstructeur','pdf','disabled','udap_id','redactedById']);

export const Service_instructeursScalarFieldEnumSchema = z.enum(['id','full_name','short_name','email','tel','udap_id']);

Expand Down Expand Up @@ -82,6 +82,7 @@ export const ReportSchema = z.object({
pdf: z.string().nullable(),
disabled: z.boolean().nullable(),
udap_id: z.string().nullable(),
redactedById: z.string().nullable(),
})

export type Report = z.infer<typeof ReportSchema>
Expand Down Expand Up @@ -201,6 +202,7 @@ export const ReportSelectSchema: z.ZodType<Prisma.ReportSelect> = z.object({
pdf: z.boolean().optional(),
disabled: z.boolean().optional(),
udap_id: z.boolean().optional(),
redactedById: z.boolean().optional(),
user: z.union([z.boolean(),z.lazy(() => UserArgsSchema)]).optional(),
}).strict()

Expand Down Expand Up @@ -398,6 +400,7 @@ export const ReportWhereInputSchema: z.ZodType<Prisma.ReportWhereInput> = z.obje
pdf: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(),
disabled: z.union([ z.lazy(() => BoolNullableFilterSchema),z.boolean() ]).optional().nullable(),
udap_id: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(),
redactedById: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(),
user: z.union([ z.lazy(() => UserRelationFilterSchema),z.lazy(() => UserWhereInputSchema) ]).optional(),
}).strict();

Expand All @@ -421,6 +424,7 @@ export const ReportOrderByWithRelationInputSchema: z.ZodType<Prisma.ReportOrderB
pdf: z.lazy(() => SortOrderSchema).optional(),
disabled: z.lazy(() => SortOrderSchema).optional(),
udap_id: z.lazy(() => SortOrderSchema).optional(),
redactedById: z.lazy(() => SortOrderSchema).optional(),
user: z.lazy(() => UserOrderByWithRelationInputSchema).optional()
}).strict();

Expand Down Expand Up @@ -448,6 +452,7 @@ export const ReportOrderByWithAggregationInputSchema: z.ZodType<Prisma.ReportOrd
pdf: z.lazy(() => SortOrderSchema).optional(),
disabled: z.lazy(() => SortOrderSchema).optional(),
udap_id: z.lazy(() => SortOrderSchema).optional(),
redactedById: z.lazy(() => SortOrderSchema).optional(),
_count: z.lazy(() => ReportCountOrderByAggregateInputSchema).optional(),
_avg: z.lazy(() => ReportAvgOrderByAggregateInputSchema).optional(),
_max: z.lazy(() => ReportMaxOrderByAggregateInputSchema).optional(),
Expand Down Expand Up @@ -478,6 +483,7 @@ export const ReportScalarWhereWithAggregatesInputSchema: z.ZodType<Prisma.Report
pdf: z.union([ z.lazy(() => StringNullableWithAggregatesFilterSchema),z.string() ]).optional().nullable(),
disabled: z.union([ z.lazy(() => BoolNullableWithAggregatesFilterSchema),z.boolean() ]).optional().nullable(),
udap_id: z.union([ z.lazy(() => StringNullableWithAggregatesFilterSchema),z.string() ]).optional().nullable(),
redactedById: z.union([ z.lazy(() => StringNullableWithAggregatesFilterSchema),z.string() ]).optional().nullable(),
}).strict();

export const Service_instructeursWhereInputSchema: z.ZodType<Prisma.Service_instructeursWhereInput> = z.object({
Expand Down Expand Up @@ -756,6 +762,7 @@ export const ReportCreateInputSchema: z.ZodType<Prisma.ReportCreateInput> = z.ob
pdf: z.string().optional().nullable(),
disabled: z.boolean().optional().nullable(),
udap_id: z.string().optional().nullable(),
redactedById: z.string().optional().nullable(),
user: z.lazy(() => UserCreateNestedOneWithoutReportInputSchema)
}).strict();

Expand All @@ -778,7 +785,8 @@ export const ReportUncheckedCreateInputSchema: z.ZodType<Prisma.ReportUncheckedC
serviceInstructeur: z.number().int().gte(-2147483648).lte(2147483647).optional().nullable(),
pdf: z.string().optional().nullable(),
disabled: z.boolean().optional().nullable(),
udap_id: z.string().optional().nullable()
udap_id: z.string().optional().nullable(),
redactedById: z.string().optional().nullable()
}).strict();

export const ReportUpdateInputSchema: z.ZodType<Prisma.ReportUpdateInput> = z.object({
Expand All @@ -800,6 +808,7 @@ export const ReportUpdateInputSchema: z.ZodType<Prisma.ReportUpdateInput> = z.ob
pdf: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
disabled: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(),
udap_id: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
user: z.lazy(() => UserUpdateOneRequiredWithoutReportNestedInputSchema).optional()
}).strict();

Expand All @@ -823,6 +832,7 @@ export const ReportUncheckedUpdateInputSchema: z.ZodType<Prisma.ReportUncheckedU
pdf: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
disabled: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(),
udap_id: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
}).strict();

export const ReportCreateManyInputSchema: z.ZodType<Prisma.ReportCreateManyInput> = z.object({
Expand All @@ -844,7 +854,8 @@ export const ReportCreateManyInputSchema: z.ZodType<Prisma.ReportCreateManyInput
serviceInstructeur: z.number().int().gte(-2147483648).lte(2147483647).optional().nullable(),
pdf: z.string().optional().nullable(),
disabled: z.boolean().optional().nullable(),
udap_id: z.string().optional().nullable()
udap_id: z.string().optional().nullable(),
redactedById: z.string().optional().nullable()
}).strict();

export const ReportUpdateManyMutationInputSchema: z.ZodType<Prisma.ReportUpdateManyMutationInput> = z.object({
Expand All @@ -866,6 +877,7 @@ export const ReportUpdateManyMutationInputSchema: z.ZodType<Prisma.ReportUpdateM
pdf: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
disabled: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(),
udap_id: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
}).strict();

export const ReportUncheckedUpdateManyInputSchema: z.ZodType<Prisma.ReportUncheckedUpdateManyInput> = z.object({
Expand All @@ -888,6 +900,7 @@ export const ReportUncheckedUpdateManyInputSchema: z.ZodType<Prisma.ReportUnchec
pdf: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
disabled: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(),
udap_id: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
}).strict();

export const Service_instructeursCreateInputSchema: z.ZodType<Prisma.Service_instructeursCreateInput> = z.object({
Expand Down Expand Up @@ -1279,7 +1292,8 @@ export const ReportCountOrderByAggregateInputSchema: z.ZodType<Prisma.ReportCoun
serviceInstructeur: z.lazy(() => SortOrderSchema).optional(),
pdf: z.lazy(() => SortOrderSchema).optional(),
disabled: z.lazy(() => SortOrderSchema).optional(),
udap_id: z.lazy(() => SortOrderSchema).optional()
udap_id: z.lazy(() => SortOrderSchema).optional(),
redactedById: z.lazy(() => SortOrderSchema).optional()
}).strict();

export const ReportAvgOrderByAggregateInputSchema: z.ZodType<Prisma.ReportAvgOrderByAggregateInput> = z.object({
Expand All @@ -1305,7 +1319,8 @@ export const ReportMaxOrderByAggregateInputSchema: z.ZodType<Prisma.ReportMaxOrd
serviceInstructeur: z.lazy(() => SortOrderSchema).optional(),
pdf: z.lazy(() => SortOrderSchema).optional(),
disabled: z.lazy(() => SortOrderSchema).optional(),
udap_id: z.lazy(() => SortOrderSchema).optional()
udap_id: z.lazy(() => SortOrderSchema).optional(),
redactedById: z.lazy(() => SortOrderSchema).optional()
}).strict();

export const ReportMinOrderByAggregateInputSchema: z.ZodType<Prisma.ReportMinOrderByAggregateInput> = z.object({
Expand All @@ -1327,7 +1342,8 @@ export const ReportMinOrderByAggregateInputSchema: z.ZodType<Prisma.ReportMinOrd
serviceInstructeur: z.lazy(() => SortOrderSchema).optional(),
pdf: z.lazy(() => SortOrderSchema).optional(),
disabled: z.lazy(() => SortOrderSchema).optional(),
udap_id: z.lazy(() => SortOrderSchema).optional()
udap_id: z.lazy(() => SortOrderSchema).optional(),
redactedById: z.lazy(() => SortOrderSchema).optional()
}).strict();

export const ReportSumOrderByAggregateInputSchema: z.ZodType<Prisma.ReportSumOrderByAggregateInput> = z.object({
Expand Down Expand Up @@ -2259,7 +2275,8 @@ export const ReportCreateWithoutUserInputSchema: z.ZodType<Prisma.ReportCreateWi
serviceInstructeur: z.number().optional().nullable(),
pdf: z.string().optional().nullable(),
disabled: z.boolean().optional().nullable(),
udap_id: z.string().optional().nullable()
udap_id: z.string().optional().nullable(),
redactedById: z.string().optional().nullable()
}).strict();

export const ReportUncheckedCreateWithoutUserInputSchema: z.ZodType<Prisma.ReportUncheckedCreateWithoutUserInput> = z.object({
Expand All @@ -2280,7 +2297,8 @@ export const ReportUncheckedCreateWithoutUserInputSchema: z.ZodType<Prisma.Repor
serviceInstructeur: z.number().optional().nullable(),
pdf: z.string().optional().nullable(),
disabled: z.boolean().optional().nullable(),
udap_id: z.string().optional().nullable()
udap_id: z.string().optional().nullable(),
redactedById: z.string().optional().nullable()
}).strict();

export const ReportCreateOrConnectWithoutUserInputSchema: z.ZodType<Prisma.ReportCreateOrConnectWithoutUserInput> = z.object({
Expand Down Expand Up @@ -2409,6 +2427,7 @@ export const ReportScalarWhereInputSchema: z.ZodType<Prisma.ReportScalarWhereInp
pdf: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(),
disabled: z.union([ z.lazy(() => BoolNullableFilterSchema),z.boolean() ]).optional().nullable(),
udap_id: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(),
redactedById: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(),
}).strict();

export const UdapUpsertWithoutUserInputSchema: z.ZodType<Prisma.UdapUpsertWithoutUserInput> = z.object({
Expand Down Expand Up @@ -2500,7 +2519,8 @@ export const ReportCreateManyUserInputSchema: z.ZodType<Prisma.ReportCreateManyU
serviceInstructeur: z.number().int().gte(-2147483648).lte(2147483647).optional().nullable(),
pdf: z.string().optional().nullable(),
disabled: z.boolean().optional().nullable(),
udap_id: z.string().optional().nullable()
udap_id: z.string().optional().nullable(),
redactedById: z.string().optional().nullable()
}).strict();

export const DelegationUpdateWithoutUser_delegation_createdByTouserInputSchema: z.ZodType<Prisma.DelegationUpdateWithoutUser_delegation_createdByTouserInput> = z.object({
Expand Down Expand Up @@ -2546,6 +2566,7 @@ export const ReportUpdateWithoutUserInputSchema: z.ZodType<Prisma.ReportUpdateWi
pdf: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
disabled: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(),
udap_id: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
}).strict();

export const ReportUncheckedUpdateWithoutUserInputSchema: z.ZodType<Prisma.ReportUncheckedUpdateWithoutUserInput> = z.object({
Expand All @@ -2567,6 +2588,7 @@ export const ReportUncheckedUpdateWithoutUserInputSchema: z.ZodType<Prisma.Repor
pdf: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
disabled: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(),
udap_id: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
}).strict();

export const ReportUncheckedUpdateManyWithoutReportInputSchema: z.ZodType<Prisma.ReportUncheckedUpdateManyWithoutReportInput> = z.object({
Expand All @@ -2588,6 +2610,7 @@ export const ReportUncheckedUpdateManyWithoutReportInputSchema: z.ZodType<Prisma
pdf: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
disabled: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(),
udap_id: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(),
}).strict();

/////////////////////////////////////////
Expand Down Expand Up @@ -3386,6 +3409,10 @@ export const tableSchemas = {
[
"udap_id",
"TEXT"
],
[
"redactedById",
"TEXT"
]
]),
relations: [
Expand Down
Loading

0 comments on commit 2435e85

Please sign in to comment.