Merge from registration branch which was in prod

This commit is contained in:
pikiou
2022-04-19 03:23:53 +02:00
50 changed files with 1584 additions and 820 deletions

View File

@@ -30,6 +30,9 @@ export default class ServiceAccessors<
...axiosConfig,
params: { id },
})
if (data.error) {
throw Error(data.error)
}
return { data }
} catch (error) {
return { error: error as Error }
@@ -51,6 +54,9 @@ export default class ServiceAccessors<
`${config.API_URL}/${this.elementName}ListGet`,
axiosConfig
)
if (data.error) {
throw Error(data.error)
}
return { data }
} catch (error) {
return { error: error as Error }
@@ -58,7 +64,7 @@ export default class ServiceAccessors<
}
}
secureListGet(): (jwt: string) => Promise<{
securedListGet(): (jwt: string) => Promise<{
data?: Element[]
error?: Error
}> {
@@ -100,6 +106,9 @@ export default class ServiceAccessors<
volunteerWithoutId,
axiosConfig
)
if (data.error) {
throw Error(data.error)
}
return { data }
} catch (error) {
return { error: error as Error }
@@ -122,6 +131,9 @@ export default class ServiceAccessors<
volunteer,
axiosConfig
)
if (data.error) {
throw Error(data.error)
}
return { data }
} catch (error) {
return { error: error as Error }
@@ -143,6 +155,9 @@ export default class ServiceAccessors<
`${config.API_URL}/${this.elementName}CountGet`,
axiosConfig
)
if (data.error) {
throw Error(data.error)
}
return { data }
} catch (error) {
return { error: error as Error }
@@ -177,6 +192,37 @@ export default class ServiceAccessors<
}
}
securedCustomGet<InputElements extends Array<any>>(
apiName: string
): (
jwt: string,
...params: InputElements
) => Promise<{
data?: any
error?: Error
}> {
interface ElementGetResponse {
data?: any
error?: Error
}
return async (jwt: string, ...params: InputElements): Promise<ElementGetResponse> => {
try {
const auth = { headers: { Authorization: `Bearer ${jwt}` } }
const fullAxiosConfig = _.defaultsDeep(auth, axiosConfig)
const { data } = await axios.get(
`${config.API_URL}/${this.elementName}${apiName}`,
{ ...fullAxiosConfig, params }
)
if (data.error) {
throw Error(data.error)
}
return { data }
} catch (error) {
return { error: error as Error }
}
}
}
securedCustomPost<InputElements extends Array<any>>(
apiName: string
): (

View File

@@ -7,4 +7,4 @@ const serviceAccessors = new ServiceAccessors<AnnouncementWithoutId, Announcemen
// export const announcementAdd = serviceAccessors.add()
// export const announcementSet = serviceAccessors.set()
export const announcementListGet = serviceAccessors.secureListGet()
export const announcementListGet = serviceAccessors.securedListGet()

View File

@@ -0,0 +1,45 @@
export class Postulant {
id = 0
firstname = ""
lastname = ""
email = ""
mobile = ""
howToContact = ""
potential = false
alreadyCame = false
firstMeeting = ""
commentFirstMeeting = ""
comment = ""
}
export const translationPostulant: { [k in keyof Postulant]: string } = {
id: "id",
firstname: "prenom",
lastname: "nom",
email: "email",
mobile: "telephone",
howToContact: "commentContacter",
potential: "potentiel",
alreadyCame: "déjàVenu",
firstMeeting: "dateRencontre",
commentFirstMeeting: "commentaireDateRencontre",
comment: "commentaire",
}
export const elementName = "Postulant"
export const emailRegexp =
/^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i
export const passwordMinLength = 4
export type PostulantWithoutId = Omit<Postulant, "id">

View File

@@ -0,0 +1,9 @@
import ServiceAccessors from "./accessors"
import { elementName, Postulant, PostulantWithoutId } from "./postulants"
const serviceAccessors = new ServiceAccessors<PostulantWithoutId, Postulant>(elementName)
export const postulantListGet = serviceAccessors.listGet()
export const postulantGet = serviceAccessors.get()
export const postulantAdd = serviceAccessors.add()
export const postulantSet = serviceAccessors.set()

View File

@@ -1,33 +0,0 @@
export class PreVolunteer {
id = 0
firstname = ""
lastname = ""
email = ""
mobile = ""
alreadyVolunteer = false
comment = ""
}
export const translationPreVolunteer: { [k in keyof PreVolunteer]: string } = {
id: "id",
firstname: "prenom",
lastname: "nom",
email: "email",
mobile: "telephone",
alreadyVolunteer: "dejaBenevole",
comment: "commentaire",
}
export const elementName = "PreVolunteer"
export const emailRegexp =
/^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i
export const passwordMinLength = 4
export type PreVolunteerWithoutId = Omit<PreVolunteer, "id">

View File

@@ -1,10 +0,0 @@
import ServiceAccessors from "./accessors"
import { elementName, PreVolunteer, PreVolunteerWithoutId } from "./preVolunteers"
const serviceAccessors = new ServiceAccessors<PreVolunteerWithoutId, PreVolunteer>(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()

View File

@@ -1,4 +1,5 @@
export class Volunteer {
/* eslint-disable max-classes-per-file */
export class Volunteer implements VolunteerPartial {
id = 0
lastname = ""
@@ -9,7 +10,7 @@ export class Volunteer {
mobile = ""
photo = ""
photo = "anonyme.png"
adult = 1
@@ -23,11 +24,11 @@ export class Volunteer {
dayWishesComment = ""
tshirtCount = ""
tshirtCount = 0
tshirtSize = ""
food = ""
food = "Aucune"
team = 0
@@ -35,6 +36,12 @@ export class Volunteer {
teamWishesComment = ""
howToContact = ""
canHelpBefore = ""
pelMember = false
hiddenAsks: number[] = []
created = new Date()
@@ -67,6 +74,9 @@ export const translationVolunteer: { [k in keyof Volunteer]: string } = {
team: "équipe",
teamWishes: "enviesEquipe",
teamWishesComment: "commentaireEnviesEquipe",
howToContact: "commentContacter",
canHelpBefore: "aideEnAmont",
pelMember: "membrePel",
hiddenAsks: "questionsCachees",
created: "creation",
password1: "passe1",
@@ -75,6 +85,16 @@ export const translationVolunteer: { [k in keyof Volunteer]: string } = {
acceptsNotifs: "accepteLesNotifs",
}
export class VolunteerPartial {
lastname = ""
firstname = ""
email = ""
mobile = ""
}
export const elementName = "Volunteer"
export const volunteerExample: Volunteer = {
@@ -90,12 +110,15 @@ export const volunteerExample: Volunteer = {
discordId: "",
dayWishes: [],
dayWishesComment: "",
tshirtCount: "1",
tshirtCount: 1,
tshirtSize: "Femme M",
food: "Végétarien",
team: 2,
teamWishes: [],
teamWishesComment: "",
howToContact: "",
canHelpBefore: "",
pelMember: false,
hiddenAsks: [],
created: new Date(0),
password1: "$2y$10$fSxY9AIuxSiEjwF.J3eXGubIxUPkdq9d5fqpbl8ASimSjNj4SR.9O",
@@ -120,6 +143,11 @@ export interface VolunteerForgot {
message: string
}
export interface VolunteerDiscordId {
id: Volunteer["id"]
discordId: Volunteer["discordId"]
}
export interface VolunteerAsks {
id: Volunteer["id"]
firstname: Volunteer["firstname"]

View File

@@ -13,8 +13,8 @@ import {
const serviceAccessors = new ServiceAccessors<VolunteerWithoutId, Volunteer>(elementName)
export const volunteerListGet = serviceAccessors.listGet()
export const volunteerGet = serviceAccessors.get()
export const volunteerAdd = serviceAccessors.add()
export const volunteerDiscordIdGet = serviceAccessors.securedCustomGet<[number]>("DiscordId")
export const volunteerPartialAdd = serviceAccessors.customPost<[Partial<Volunteer>]>("PartialAdd")
export const volunteerSet = serviceAccessors.set()
export const volunteerLogin =