From 110f3505abfcbf97b13cce9432de5c12457b6157 Mon Sep 17 00:00:00 2001 From: pikiou Date: Wed, 26 Jan 2022 22:37:19 +0100 Subject: [PATCH] Move database accessors in separate files to separate them from database definitions --- src/server/gsheets/volunteers.ts | 2 +- src/services/javGames.ts | 11 +----- src/services/javGamesAccessors.ts | 9 +++++ src/services/preVolunteers.ts | 12 +------ src/services/preVolunteersAccessors.ts | 10 ++++++ src/services/teams.ts | 9 +---- src/services/teamsAccessors.ts | 7 ++++ src/services/volunteers.ts | 28 +++------------ src/services/volunteersAccessors.ts | 36 +++++++++++++++++++ src/services/wishes.ts | 11 +----- src/services/wishesAccessors.ts | 9 +++++ src/store/javGameList.ts | 3 +- src/store/preVolunteerAdd.ts | 3 +- src/store/preVolunteerCount.ts | 2 +- src/store/teamList.ts | 3 +- src/store/volunteer.ts | 3 +- src/store/volunteerAdd.ts | 3 +- src/store/volunteerDayWishesSet.ts | 3 +- src/store/volunteerForgot.ts | 3 +- src/store/volunteerList.ts | 3 +- src/store/volunteerLogin.ts | 3 +- src/store/volunteerNotifsSet.ts | 3 +- src/store/volunteerParticipationDetailsSet.ts | 6 ++-- src/store/volunteerSet.ts | 3 +- src/store/volunteerTeamWishesSet.ts | 3 +- src/store/wishAdd.ts | 3 +- src/store/wishList.ts | 3 +- src/utils/standardization.ts | 30 +++++++++------- 28 files changed, 130 insertions(+), 94 deletions(-) create mode 100644 src/services/javGamesAccessors.ts create mode 100644 src/services/preVolunteersAccessors.ts create mode 100644 src/services/teamsAccessors.ts create mode 100644 src/services/volunteersAccessors.ts create mode 100644 src/services/wishesAccessors.ts diff --git a/src/server/gsheets/volunteers.ts b/src/server/gsheets/volunteers.ts index 26cdd72..3a00b15 100644 --- a/src/server/gsheets/volunteers.ts +++ b/src/server/gsheets/volunteers.ts @@ -106,7 +106,7 @@ async function sendForgetEmail(email: string, password: string): Promise { const msg = { to: email, from: "contact@parisestludique.fr", - subject: "Nouveau mot de passe pour le site de Paris est Ludique", + subject: "Nouveau mot de passe pour le site bénévole de Paris est Ludique", text: `Voici le nouveau mot de passe : ${password}\nL'ancien fonctionne encore, si tu t'en rappelles.`, html: `Voici le nouveau mot de passe : ${password}
L'ancien fonctionne encore, si tu t'en rappelles.`, } diff --git a/src/services/javGames.ts b/src/services/javGames.ts index e82f4e5..7d40a72 100644 --- a/src/services/javGames.ts +++ b/src/services/javGames.ts @@ -1,5 +1,3 @@ -import ServiceAccessors from "./accessors" - export class JavGame { id = 0 @@ -50,13 +48,6 @@ export const translationJavGame: { [k in keyof JavGame]: string } = { bggPhoto: "bggPhoto", } -const elementName = "JavGame" +export const elementName = "JavGame" export type JavGameWithoutId = Omit - -const serviceAccessors = new ServiceAccessors(elementName) - -export const javGameListGet = serviceAccessors.listGet() -export const javGameGet = serviceAccessors.get() -export const javGameAdd = serviceAccessors.add() -export const javGameSet = serviceAccessors.set() diff --git a/src/services/javGamesAccessors.ts b/src/services/javGamesAccessors.ts new file mode 100644 index 0000000..c27c58d --- /dev/null +++ b/src/services/javGamesAccessors.ts @@ -0,0 +1,9 @@ +import ServiceAccessors from "./accessors" +import { elementName, JavGame, JavGameWithoutId } from "./javGames" + +const serviceAccessors = new ServiceAccessors(elementName) + +export const javGameListGet = serviceAccessors.listGet() +export const javGameGet = serviceAccessors.get() +export const javGameAdd = serviceAccessors.add() +export const javGameSet = serviceAccessors.set() diff --git a/src/services/preVolunteers.ts b/src/services/preVolunteers.ts index 4149b17..55e4e3b 100644 --- a/src/services/preVolunteers.ts +++ b/src/services/preVolunteers.ts @@ -1,5 +1,3 @@ -import ServiceAccessors from "./accessors" - export class PreVolunteer { id = 0 @@ -26,18 +24,10 @@ export const translationPreVolunteer: { [k in keyof PreVolunteer]: string } = { comment: "commentaire", } -const elementName = "PreVolunteer" +export const elementName = "PreVolunteer" export const emailRegexp = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i export const passwordMinLength = 4 export type PreVolunteerWithoutId = Omit - -const serviceAccessors = new ServiceAccessors(elementName) - -export const preVolunteerListGet = serviceAccessors.listGet() -export const preVolunteerGet = serviceAccessors.get() -export const preVolunteerAdd = serviceAccessors.add() -export const preVolunteerSet = serviceAccessors.set() -export const preVolunteerCountGet = serviceAccessors.countGet() diff --git a/src/services/preVolunteersAccessors.ts b/src/services/preVolunteersAccessors.ts new file mode 100644 index 0000000..3c04c11 --- /dev/null +++ b/src/services/preVolunteersAccessors.ts @@ -0,0 +1,10 @@ +import ServiceAccessors from "./accessors" +import { elementName, PreVolunteer, PreVolunteerWithoutId } from "./preVolunteers" + +const serviceAccessors = new ServiceAccessors(elementName) + +export const preVolunteerListGet = serviceAccessors.listGet() +export const preVolunteerGet = serviceAccessors.get() +export const preVolunteerAdd = serviceAccessors.add() +export const preVolunteerSet = serviceAccessors.set() +export const preVolunteerCountGet = serviceAccessors.countGet() diff --git a/src/services/teams.ts b/src/services/teams.ts index 02acf1d..cfb19d3 100644 --- a/src/services/teams.ts +++ b/src/services/teams.ts @@ -1,5 +1,3 @@ -import ServiceAccessors from "./accessors" - export class Team { id = 0 @@ -29,11 +27,6 @@ export const translationTeam: { [k in keyof Team]: string } = { after: "après", } -const elementName = "Team" +export const elementName = "Team" export type TeamWithoutId = Omit - -const serviceAccessors = new ServiceAccessors(elementName) - -export const teamListGet = serviceAccessors.listGet() -export const teamGet = serviceAccessors.get() diff --git a/src/services/teamsAccessors.ts b/src/services/teamsAccessors.ts new file mode 100644 index 0000000..5015866 --- /dev/null +++ b/src/services/teamsAccessors.ts @@ -0,0 +1,7 @@ +import ServiceAccessors from "./accessors" +import { Team, TeamWithoutId, elementName } from "./teams" + +const serviceAccessors = new ServiceAccessors(elementName) + +export const teamListGet = serviceAccessors.listGet() +export const teamGet = serviceAccessors.get() diff --git a/src/services/volunteers.ts b/src/services/volunteers.ts index fea8e6e..226d411 100644 --- a/src/services/volunteers.ts +++ b/src/services/volunteers.ts @@ -1,5 +1,3 @@ -import ServiceAccessors from "./accessors" - export class Volunteer { id = 0 @@ -19,6 +17,8 @@ export class Volunteer { active = "" + discordId = "" + dayWishes: string[] = [] dayWishesComment = "" @@ -56,6 +56,7 @@ export const translationVolunteer: { [k in keyof Volunteer]: string } = { adult: "majeur", privileges: "privilege", active: "actif", + discordId: "discordId", dayWishes: "enviesJours", dayWishesComment: "commentaireEnviesJours", age: "age", @@ -71,7 +72,7 @@ export const translationVolunteer: { [k in keyof Volunteer]: string } = { acceptsNotifs: "accepteLesNotifs", } -const elementName = "Volunteer" +export const elementName = "Volunteer" export const volunteerExample: Volunteer = { id: 1, @@ -83,6 +84,7 @@ export const volunteerExample: Volunteer = { adult: 1, privileges: 0, active: "inconnu", + discordId: "", dayWishes: [], dayWishesComment: "", age: 33, @@ -104,24 +106,14 @@ export const passwordMinLength = 4 export type VolunteerWithoutId = Omit -const serviceAccessors = new ServiceAccessors(elementName) - -export const volunteerListGet = serviceAccessors.listGet() -export const volunteerGet = serviceAccessors.get() -export const volunteerAdd = serviceAccessors.add() -export const volunteerSet = serviceAccessors.set() - export interface VolunteerLogin { id: number jwt: string } -export const volunteerLogin = - serviceAccessors.customPost<[{ email: string; password: string }]>("Login") export interface VolunteerForgot { message: string } -export const volunteerForgot = serviceAccessors.customPost<[{ email: string }]>("Forgot") export interface VolunteerNotifs { id: Volunteer["id"] @@ -132,24 +124,18 @@ export interface VolunteerNotifs { pushNotifSubscription: Volunteer["pushNotifSubscription"] acceptsNotifs: Volunteer["acceptsNotifs"] } -export const volunteerNotifsSet = - serviceAccessors.securedCustomPost<[number, Partial]>("NotifsSet") export interface VolunteerTeamWishes { id: Volunteer["id"] teamWishes: Volunteer["teamWishes"] teamWishesComment: Volunteer["teamWishesComment"] } -export const volunteerTeamWishesSet = - serviceAccessors.securedCustomPost<[number, Partial]>("TeamWishesSet") export interface VolunteerDayWishes { id: Volunteer["id"] dayWishes: Volunteer["dayWishes"] dayWishesComment: Volunteer["dayWishesComment"] } -export const volunteerDayWishesSet = - serviceAccessors.securedCustomPost<[number, Partial]>("DayWishesSet") export interface VolunteerParticipationDetails { id: Volunteer["id"] @@ -157,7 +143,3 @@ export interface VolunteerParticipationDetails { teeshirtSize: Volunteer["teeshirtSize"] food: Volunteer["food"] } -export const volunteerParticipationDetailsSet = - serviceAccessors.securedCustomPost<[number, Partial]>( - "ParticipationDetailsSet" - ) diff --git a/src/services/volunteersAccessors.ts b/src/services/volunteersAccessors.ts new file mode 100644 index 0000000..d6dc3d0 --- /dev/null +++ b/src/services/volunteersAccessors.ts @@ -0,0 +1,36 @@ +import ServiceAccessors from "./accessors" +import { + elementName, + Volunteer, + VolunteerDayWishes, + VolunteerNotifs, + VolunteerParticipationDetails, + VolunteerTeamWishes, + VolunteerWithoutId, +} from "./volunteers" + +const serviceAccessors = new ServiceAccessors(elementName) + +export const volunteerListGet = serviceAccessors.listGet() +export const volunteerGet = serviceAccessors.get() +export const volunteerAdd = serviceAccessors.add() +export const volunteerSet = serviceAccessors.set() + +export const volunteerLogin = + serviceAccessors.customPost<[{ email: string; password: string }]>("Login") + +export const volunteerForgot = serviceAccessors.customPost<[{ email: string }]>("Forgot") + +export const volunteerNotifsSet = + serviceAccessors.securedCustomPost<[number, Partial]>("NotifsSet") + +export const volunteerTeamWishesSet = + serviceAccessors.securedCustomPost<[number, Partial]>("TeamWishesSet") + +export const volunteerDayWishesSet = + serviceAccessors.securedCustomPost<[number, Partial]>("DayWishesSet") + +export const volunteerParticipationDetailsSet = + serviceAccessors.securedCustomPost<[number, Partial]>( + "ParticipationDetailsSet" + ) diff --git a/src/services/wishes.ts b/src/services/wishes.ts index 1ec86a9..fefc6bd 100644 --- a/src/services/wishes.ts +++ b/src/services/wishes.ts @@ -1,5 +1,3 @@ -import ServiceAccessors from "./accessors" - export class Wish { id = 0 @@ -23,13 +21,6 @@ export const translationWish: { [k in keyof Wish]: string } = { addedDate: "dateAjout", } -const elementName = "Wish" +export const elementName = "Wish" export type WishWithoutId = Omit - -const serviceAccessors = new ServiceAccessors(elementName) - -export const wishListGet = serviceAccessors.listGet() -export const wishGet = serviceAccessors.get() -export const wishAdd = serviceAccessors.add() -export const wishSet = serviceAccessors.set() diff --git a/src/services/wishesAccessors.ts b/src/services/wishesAccessors.ts new file mode 100644 index 0000000..7428caf --- /dev/null +++ b/src/services/wishesAccessors.ts @@ -0,0 +1,9 @@ +import ServiceAccessors from "./accessors" +import { elementName, Wish, WishWithoutId } from "./wishes" + +const serviceAccessors = new ServiceAccessors(elementName) + +export const wishListGet = serviceAccessors.listGet() +export const wishGet = serviceAccessors.get() +export const wishAdd = serviceAccessors.add() +export const wishSet = serviceAccessors.set() diff --git a/src/store/javGameList.ts b/src/store/javGameList.ts index 978ef34..eb4106f 100644 --- a/src/store/javGameList.ts +++ b/src/store/javGameList.ts @@ -1,8 +1,9 @@ import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit" import { StateRequest, toastError, elementListFetch } from "./utils" -import { JavGame, javGameListGet } from "../services/javGames" +import { JavGame } from "../services/javGames" import { AppThunk, AppState } from "." +import { javGameListGet } from "../services/javGamesAccessors" const javGameAdapter = createEntityAdapter() diff --git a/src/store/preVolunteerAdd.ts b/src/store/preVolunteerAdd.ts index d9610c2..09149ba 100644 --- a/src/store/preVolunteerAdd.ts +++ b/src/store/preVolunteerAdd.ts @@ -1,7 +1,8 @@ import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit" import { StateRequest, elementAddFetch } from "./utils" -import { PreVolunteer, preVolunteerAdd } from "../services/preVolunteers" +import { PreVolunteer } from "../services/preVolunteers" +import { preVolunteerAdd } from "../services/preVolunteersAccessors" const preVolunteerAdapter = createEntityAdapter() diff --git a/src/store/preVolunteerCount.ts b/src/store/preVolunteerCount.ts index 660aeb9..50cdcd8 100644 --- a/src/store/preVolunteerCount.ts +++ b/src/store/preVolunteerCount.ts @@ -1,7 +1,7 @@ import { PayloadAction, createSlice } from "@reduxjs/toolkit" import { StateRequest, toastError, elementValueFetch } from "./utils" -import { preVolunteerCountGet } from "../services/preVolunteers" +import { preVolunteerCountGet } from "../services/preVolunteersAccessors" import { AppThunk, AppState } from "." export const initialState: StateRequest & { value?: number } = { readyStatus: "idle" } diff --git a/src/store/teamList.ts b/src/store/teamList.ts index 8e27367..34cd079 100644 --- a/src/store/teamList.ts +++ b/src/store/teamList.ts @@ -1,8 +1,9 @@ import { PayloadAction, createSlice, createEntityAdapter, createSelector } from "@reduxjs/toolkit" import { StateRequest, toastError, elementListFetch } from "./utils" -import { Team, teamListGet } from "../services/teams" +import { Team } from "../services/teams" import { AppThunk, AppState, EntitiesRequest } from "." +import { teamListGet } from "../services/teamsAccessors" const teamAdapter = createEntityAdapter() diff --git a/src/store/volunteer.ts b/src/store/volunteer.ts index 081570c..b883500 100644 --- a/src/store/volunteer.ts +++ b/src/store/volunteer.ts @@ -1,8 +1,9 @@ import { PayloadAction, createSlice } from "@reduxjs/toolkit" import { StateRequest, toastError, elementFetch } from "./utils" -import { Volunteer, volunteerGet } from "../services/volunteers" +import { Volunteer } from "../services/volunteers" import { AppThunk, AppState } from "." +import { volunteerGet } from "../services/volunteersAccessors" type StateVolunteer = { entity?: Volunteer } & StateRequest diff --git a/src/store/volunteerAdd.ts b/src/store/volunteerAdd.ts index 2a8fb92..24803e3 100644 --- a/src/store/volunteerAdd.ts +++ b/src/store/volunteerAdd.ts @@ -1,7 +1,8 @@ import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit" import { StateRequest, toastError, toastSuccess, elementAddFetch } from "./utils" -import { Volunteer, volunteerAdd } from "../services/volunteers" +import { Volunteer } from "../services/volunteers" +import { volunteerAdd } from "../services/volunteersAccessors" const volunteerAdapter = createEntityAdapter() diff --git a/src/store/volunteerDayWishesSet.ts b/src/store/volunteerDayWishesSet.ts index 1bfca0a..f5420cc 100644 --- a/src/store/volunteerDayWishesSet.ts +++ b/src/store/volunteerDayWishesSet.ts @@ -1,8 +1,9 @@ import { PayloadAction, createSlice } from "@reduxjs/toolkit" import { StateRequest, toastError, elementFetch } from "./utils" -import { VolunteerDayWishes, volunteerDayWishesSet } from "../services/volunteers" +import { VolunteerDayWishes } from "../services/volunteers" import { AppThunk, AppState } from "." +import { volunteerDayWishesSet } from "../services/volunteersAccessors" type StateVolunteerDayWishesSet = { entity?: VolunteerDayWishes } & StateRequest diff --git a/src/store/volunteerForgot.ts b/src/store/volunteerForgot.ts index a7e2435..0789775 100644 --- a/src/store/volunteerForgot.ts +++ b/src/store/volunteerForgot.ts @@ -1,7 +1,8 @@ import { PayloadAction, createSlice } from "@reduxjs/toolkit" import { StateRequest, elementFetch } from "./utils" -import { VolunteerForgot, volunteerForgot } from "../services/volunteers" +import { VolunteerForgot } from "../services/volunteers" +import { volunteerForgot } from "../services/volunteersAccessors" type StateVolunteer = { entity?: VolunteerForgot } & StateRequest diff --git a/src/store/volunteerList.ts b/src/store/volunteerList.ts index b28c396..68e5705 100644 --- a/src/store/volunteerList.ts +++ b/src/store/volunteerList.ts @@ -1,8 +1,9 @@ import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit" import { StateRequest, toastError, elementListFetch } from "./utils" -import { Volunteer, volunteerListGet } from "../services/volunteers" +import { Volunteer } from "../services/volunteers" import { AppThunk, AppState } from "." +import { volunteerListGet } from "../services/volunteersAccessors" const volunteerAdapter = createEntityAdapter() diff --git a/src/store/volunteerLogin.ts b/src/store/volunteerLogin.ts index bc7a2c8..f2d8365 100644 --- a/src/store/volunteerLogin.ts +++ b/src/store/volunteerLogin.ts @@ -1,11 +1,12 @@ import { PayloadAction, createSlice } from "@reduxjs/toolkit" import { StateRequest, elementFetch } from "./utils" -import { VolunteerLogin, volunteerLogin } from "../services/volunteers" +import { VolunteerLogin } from "../services/volunteers" import { setJWT } from "../services/auth" import { AppDispatch } from "." import { setCurrentUser } from "./auth" import { fetchVolunteerNotifsSet } from "./volunteerNotifsSet" +import { volunteerLogin } from "../services/volunteersAccessors" type StateVolunteer = { entity?: VolunteerLogin } & StateRequest diff --git a/src/store/volunteerNotifsSet.ts b/src/store/volunteerNotifsSet.ts index 3b50836..a0f24ef 100644 --- a/src/store/volunteerNotifsSet.ts +++ b/src/store/volunteerNotifsSet.ts @@ -1,8 +1,9 @@ import { PayloadAction, createSlice } from "@reduxjs/toolkit" import { StateRequest, toastError, elementFetch } from "./utils" -import { VolunteerNotifs, volunteerNotifsSet } from "../services/volunteers" +import { VolunteerNotifs } from "../services/volunteers" import { AppThunk, AppState } from "." +import { volunteerNotifsSet } from "../services/volunteersAccessors" type StateVolunteerNotifsSet = { entity?: VolunteerNotifs } & StateRequest diff --git a/src/store/volunteerParticipationDetailsSet.ts b/src/store/volunteerParticipationDetailsSet.ts index 1d9c769..521d9f8 100644 --- a/src/store/volunteerParticipationDetailsSet.ts +++ b/src/store/volunteerParticipationDetailsSet.ts @@ -1,11 +1,9 @@ import { PayloadAction, createSlice } from "@reduxjs/toolkit" import { StateRequest, toastError, elementFetch } from "./utils" -import { - VolunteerParticipationDetails, - volunteerParticipationDetailsSet, -} from "../services/volunteers" +import { VolunteerParticipationDetails } from "../services/volunteers" import { AppThunk, AppState } from "." +import { volunteerParticipationDetailsSet } from "../services/volunteersAccessors" type StateVolunteerParticipationDetailsSet = { entity?: VolunteerParticipationDetails diff --git a/src/store/volunteerSet.ts b/src/store/volunteerSet.ts index 1266107..ae78474 100644 --- a/src/store/volunteerSet.ts +++ b/src/store/volunteerSet.ts @@ -1,7 +1,8 @@ import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit" import { StateRequest, toastError, toastSuccess, elementSet } from "./utils" -import { Volunteer, volunteerSet } from "../services/volunteers" +import { Volunteer } from "../services/volunteers" +import { volunteerSet } from "../services/volunteersAccessors" const volunteerAdapter = createEntityAdapter() diff --git a/src/store/volunteerTeamWishesSet.ts b/src/store/volunteerTeamWishesSet.ts index a4b0f1e..179af1d 100644 --- a/src/store/volunteerTeamWishesSet.ts +++ b/src/store/volunteerTeamWishesSet.ts @@ -1,8 +1,9 @@ import { PayloadAction, createSlice } from "@reduxjs/toolkit" import { StateRequest, toastError, elementFetch } from "./utils" -import { VolunteerTeamWishes, volunteerTeamWishesSet } from "../services/volunteers" +import { VolunteerTeamWishes } from "../services/volunteers" import { AppThunk, AppState } from "." +import { volunteerTeamWishesSet } from "../services/volunteersAccessors" type StateVolunteerTeamWishesSet = { entity?: VolunteerTeamWishes } & StateRequest diff --git a/src/store/wishAdd.ts b/src/store/wishAdd.ts index f9e1a73..d8440e8 100644 --- a/src/store/wishAdd.ts +++ b/src/store/wishAdd.ts @@ -1,7 +1,8 @@ import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit" import { StateRequest, toastError, toastSuccess, elementAddFetch } from "./utils" -import { Wish, wishAdd } from "../services/wishes" +import { Wish } from "../services/wishes" +import { wishAdd } from "../services/wishesAccessors" const wishAdapter = createEntityAdapter() diff --git a/src/store/wishList.ts b/src/store/wishList.ts index ee71595..23ce147 100644 --- a/src/store/wishList.ts +++ b/src/store/wishList.ts @@ -1,8 +1,9 @@ import { PayloadAction, createSlice, createEntityAdapter } from "@reduxjs/toolkit" import { StateRequest, toastError, elementListFetch } from "./utils" -import { Wish, wishListGet } from "../services/wishes" +import { Wish } from "../services/wishes" import { AppThunk, AppState } from "." +import { wishListGet } from "../services/wishesAccessors" const wishAdapter = createEntityAdapter() diff --git a/src/utils/standardization.ts b/src/utils/standardization.ts index d200952..21523da 100644 --- a/src/utils/standardization.ts +++ b/src/utils/standardization.ts @@ -45,6 +45,22 @@ export function trim(src: string): string { return typeof src !== "string" ? "" : src.replace(/^\s*/, "").replace(/\s*$/, "") } +export function canonicalFirstname(firstname: string): string { + return trim(firstname) + .toLowerCase() + .replace(/(?<=^|[\s'-])([a-zA-Z]|[à-ú]|[À-Ú])/gi, (s) => s.toUpperCase()) + .replace(/\b(de|d'|du|le|la)\b/gi, (s) => s.toLowerCase()) + .replace(/\b(d'|l')/gi, (s) => s.toLowerCase()) +} + +export function canonicalLastname(lastname: string): string { + return trim(lastname) + .toLowerCase() + .replace(/(?<=^|[\s'-])([a-zA-Z]|[à-ú]|[À-Ú])/gi, (s) => s.toUpperCase()) + .replace(/\b(de|d'|du|le|la)\b/gi, (s) => s.toLowerCase()) + .replace(/\b(d'|l')/gi, (s) => s.toLowerCase()) +} + // eslint-disable-next-line @typescript-eslint/ban-types export function doCleanVolunteer< Element extends { firstname: string; lastname: string; email: string; mobile: string } @@ -55,19 +71,9 @@ export function doCleanVolunteer< vol.mobile = canonicalMobile(vol.mobile) } - vol.firstname = trim(vol.firstname) - vol.firstname = vol.firstname - .toLowerCase() - .replace(/(?<=^|[\s'-])([a-zA-Z]|[à-ú]|[À-Ú])/gi, (s) => s.toUpperCase()) - .replace(/\b(de|d'|du|le|la)\b/gi, (s) => s.toLowerCase()) - .replace(/\b(d'|l')/gi, (s) => s.toLowerCase()) + vol.firstname = canonicalFirstname(vol.firstname) - vol.lastname = trim(vol.lastname) - vol.lastname = vol.lastname - .toLowerCase() - .replace(/(?<=^|[\s'-])([a-zA-Z]|[à-ú]|[À-Ú])/gi, (s) => s.toUpperCase()) - .replace(/\b(de|d'|du|le|la)\b/gi, (s) => s.toLowerCase()) - .replace(/\b(d'|l')/gi, (s) => s.toLowerCase()) + vol.lastname = canonicalLastname(vol.lastname) vol.email = canonicalEmail(vol.email) }