From 3dd0b5d11e9c9e404ad2ea62e1e5ed7824e673d2 Mon Sep 17 00:00:00 2001 From: Adrian Andersen Date: Tue, 15 Oct 2024 15:32:10 +0200 Subject: [PATCH] feat(user-detail): clean guardian info --- .../user-detail/hooks/user-detail-update.hook.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/collections/user-detail/hooks/user-detail-update.hook.ts b/src/collections/user-detail/hooks/user-detail-update.hook.ts index d844a9f1..38976172 100644 --- a/src/collections/user-detail/hooks/user-detail-update.hook.ts +++ b/src/collections/user-detail/hooks/user-detail-update.hook.ts @@ -16,6 +16,18 @@ export class UserDetailUpdateHook extends Hook { .join(""); }; + private cleanGuardianInfo( + guardian: UserDetail["guardian"], + ): UserDetail["guardian"] { + return ( + guardian && { + ...guardian, + name: this.cleanUserInput(guardian.name), + email: guardian.email.toLowerCase(), + } + ); + } + public override async before( body: unknown, accessToken: AccessToken, @@ -51,7 +63,9 @@ export class UserDetailUpdateHook extends Hook { ...(postCode !== undefined && { postCode }), ...(phone !== undefined && { phone }), ...(emailConfirmed !== undefined && { emailConfirmed }), - ...(guardian !== undefined && { guardian }), + ...(guardian !== undefined && { + guardian: this.cleanGuardianInfo(guardian) ?? guardian, + }), }; } }