mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-09-11 13:56:29 +02:00
Add password reset
This commit is contained in:
@@ -7,12 +7,15 @@ export type ElementWithId = unknown & { id: number }
|
||||
|
||||
export type ElementTranslation<Element> = { [k in keyof Element]: string }
|
||||
|
||||
export default function getServiceAccessors<
|
||||
export default class ServiceAccessors<
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
ElementNoId extends object,
|
||||
Element extends ElementNoId & ElementWithId
|
||||
>(elementName: string): any {
|
||||
function get(): (id: number) => Promise<{
|
||||
> {
|
||||
// eslint-disable-next-line no-useless-constructor
|
||||
constructor(readonly elementName: string) {}
|
||||
|
||||
get(): (id: number) => Promise<{
|
||||
data?: Element
|
||||
error?: Error
|
||||
}> {
|
||||
@@ -22,7 +25,7 @@ export default function getServiceAccessors<
|
||||
}
|
||||
return async (id: number): Promise<ElementGetResponse> => {
|
||||
try {
|
||||
const { data } = await axios.get(`${config.API_URL}/${elementName}Get`, {
|
||||
const { data } = await axios.get(`${config.API_URL}/${this.elementName}Get`, {
|
||||
...axiosConfig,
|
||||
params: { id },
|
||||
})
|
||||
@@ -33,7 +36,7 @@ export default function getServiceAccessors<
|
||||
}
|
||||
}
|
||||
|
||||
function listGet(): () => Promise<{
|
||||
listGet(): () => Promise<{
|
||||
data?: Element[]
|
||||
error?: Error
|
||||
}> {
|
||||
@@ -44,7 +47,7 @@ export default function getServiceAccessors<
|
||||
return async (): Promise<ElementListGetResponse> => {
|
||||
try {
|
||||
const { data } = await axios.get(
|
||||
`${config.API_URL}/${elementName}ListGet`,
|
||||
`${config.API_URL}/${this.elementName}ListGet`,
|
||||
axiosConfig
|
||||
)
|
||||
return { data }
|
||||
@@ -55,7 +58,7 @@ export default function getServiceAccessors<
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
function add(): (volunteerWithoutId: ElementNoId) => Promise<{
|
||||
add(): (volunteerWithoutId: ElementNoId) => Promise<{
|
||||
data?: Element
|
||||
error?: Error
|
||||
}> {
|
||||
@@ -66,7 +69,7 @@ export default function getServiceAccessors<
|
||||
return async (volunteerWithoutId: ElementNoId): Promise<ElementGetResponse> => {
|
||||
try {
|
||||
const { data } = await axios.post(
|
||||
`${config.API_URL}/${elementName}Add`,
|
||||
`${config.API_URL}/${this.elementName}Add`,
|
||||
volunteerWithoutId,
|
||||
axiosConfig
|
||||
)
|
||||
@@ -77,7 +80,7 @@ export default function getServiceAccessors<
|
||||
}
|
||||
}
|
||||
|
||||
function set(): (volunteer: Element) => Promise<{
|
||||
set(): (volunteer: Element) => Promise<{
|
||||
data?: Element
|
||||
error?: Error
|
||||
}> {
|
||||
@@ -88,7 +91,7 @@ export default function getServiceAccessors<
|
||||
return async (volunteer: Element): Promise<ElementGetResponse> => {
|
||||
try {
|
||||
const { data } = await axios.post(
|
||||
`${config.API_URL}/${elementName}Set`,
|
||||
`${config.API_URL}/${this.elementName}Set`,
|
||||
volunteer,
|
||||
axiosConfig
|
||||
)
|
||||
@@ -99,7 +102,7 @@ export default function getServiceAccessors<
|
||||
}
|
||||
}
|
||||
|
||||
function countGet(): () => Promise<{
|
||||
countGet(): () => Promise<{
|
||||
data?: number
|
||||
error?: Error
|
||||
}> {
|
||||
@@ -110,7 +113,7 @@ export default function getServiceAccessors<
|
||||
return async (): Promise<ElementCountGetResponse> => {
|
||||
try {
|
||||
const { data } = await axios.get(
|
||||
`${config.API_URL}/${elementName}CountGet`,
|
||||
`${config.API_URL}/${this.elementName}CountGet`,
|
||||
axiosConfig
|
||||
)
|
||||
return { data }
|
||||
@@ -120,18 +123,18 @@ export default function getServiceAccessors<
|
||||
}
|
||||
}
|
||||
|
||||
function customPost(apiName: string): (params: any) => Promise<{
|
||||
data?: Element
|
||||
customPost(apiName: string): (params: any) => Promise<{
|
||||
data?: any
|
||||
error?: Error
|
||||
}> {
|
||||
interface ElementGetResponse {
|
||||
data?: Element
|
||||
data?: any
|
||||
error?: Error
|
||||
}
|
||||
return async (params: any): Promise<ElementGetResponse> => {
|
||||
try {
|
||||
const { data } = await axios.post(
|
||||
`${config.API_URL}/${elementName}${apiName}`,
|
||||
`${config.API_URL}/${this.elementName}${apiName}`,
|
||||
params,
|
||||
axiosConfig
|
||||
)
|
||||
@@ -144,6 +147,4 @@ export default function getServiceAccessors<
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { listGet, get, set, add, countGet, customPost }
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import getServiceAccessors from "./accessors"
|
||||
import ServiceAccessors from "./accessors"
|
||||
|
||||
export class JavGame {
|
||||
id = 0
|
||||
@@ -54,9 +54,9 @@ const elementName = "JavGame"
|
||||
|
||||
export type JavGameWithoutId = Omit<JavGame, "id">
|
||||
|
||||
const { listGet, get, set, add } = getServiceAccessors<JavGameWithoutId, JavGame>(elementName)
|
||||
const serviceAccessors = new ServiceAccessors<JavGameWithoutId, JavGame>(elementName)
|
||||
|
||||
export const javGameListGet = listGet()
|
||||
export const javGameGet = get()
|
||||
export const javGameAdd = add()
|
||||
export const javGameSet = set()
|
||||
export const javGameListGet = serviceAccessors.listGet()
|
||||
export const javGameGet = serviceAccessors.get()
|
||||
export const javGameAdd = serviceAccessors.add()
|
||||
export const javGameSet = serviceAccessors.set()
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import getServiceAccessors from "./accessors"
|
||||
import ServiceAccessors from "./accessors"
|
||||
|
||||
export class PreVolunteer {
|
||||
id = 0
|
||||
@@ -34,13 +34,10 @@ export const passwordMinLength = 4
|
||||
|
||||
export type PreVolunteerWithoutId = Omit<PreVolunteer, "id">
|
||||
|
||||
const { listGet, get, set, add, countGet } = getServiceAccessors<
|
||||
PreVolunteerWithoutId,
|
||||
PreVolunteer
|
||||
>(elementName)
|
||||
const serviceAccessors = new ServiceAccessors<PreVolunteerWithoutId, PreVolunteer>(elementName)
|
||||
|
||||
export const preVolunteerListGet = listGet()
|
||||
export const preVolunteerGet = get()
|
||||
export const preVolunteerAdd = add()
|
||||
export const preVolunteerSet = set()
|
||||
export const preVolunteerCountGet = countGet()
|
||||
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()
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import getServiceAccessors from "./accessors"
|
||||
import ServiceAccessors from "./accessors"
|
||||
|
||||
export class Volunteer {
|
||||
id = 0
|
||||
@@ -21,11 +21,11 @@ export class Volunteer {
|
||||
|
||||
active = 0
|
||||
|
||||
comment = ""
|
||||
created = new Date()
|
||||
|
||||
timestamp = new Date()
|
||||
password1 = ""
|
||||
|
||||
password = ""
|
||||
password2 = ""
|
||||
}
|
||||
|
||||
export const translationVolunteer: { [k in keyof Volunteer]: string } = {
|
||||
@@ -39,9 +39,9 @@ export const translationVolunteer: { [k in keyof Volunteer]: string } = {
|
||||
adult: "majeur",
|
||||
privileges: "privilege",
|
||||
active: "actif",
|
||||
comment: "commentaire",
|
||||
timestamp: "horodatage",
|
||||
password: "passe",
|
||||
created: "creation",
|
||||
password1: "passe1",
|
||||
password2: "passe2",
|
||||
}
|
||||
|
||||
const elementName = "Volunteer"
|
||||
@@ -52,16 +52,20 @@ export const passwordMinLength = 4
|
||||
|
||||
export type VolunteerWithoutId = Omit<Volunteer, "id">
|
||||
|
||||
const accessors = getServiceAccessors<VolunteerWithoutId, Volunteer>(elementName)
|
||||
const { listGet, get, set, add } = accessors
|
||||
const serviceAccessors = new ServiceAccessors<VolunteerWithoutId, Volunteer>(elementName)
|
||||
|
||||
export const volunteerListGet = listGet()
|
||||
export const volunteerGet = get()
|
||||
export const volunteerAdd = add()
|
||||
export const volunteerSet = set()
|
||||
export const volunteerListGet = serviceAccessors.listGet()
|
||||
export const volunteerGet = serviceAccessors.get()
|
||||
export const volunteerAdd = serviceAccessors.add()
|
||||
export const volunteerSet = serviceAccessors.set()
|
||||
|
||||
export interface VolunteerLogin {
|
||||
firstname: string
|
||||
jwt: string
|
||||
}
|
||||
export const volunteerLogin = accessors.customPost("Login")
|
||||
export const volunteerLogin = serviceAccessors.customPost("Login")
|
||||
|
||||
export interface VolunteerForgot {
|
||||
message: string
|
||||
}
|
||||
export const volunteerForgot = serviceAccessors.customPost("Forgot")
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import getServiceAccessors from "./accessors"
|
||||
import ServiceAccessors from "./accessors"
|
||||
|
||||
export class Wish {
|
||||
id = 0
|
||||
@@ -27,9 +27,9 @@ const elementName = "Wish"
|
||||
|
||||
export type WishWithoutId = Omit<Wish, "id">
|
||||
|
||||
const { listGet, get, set, add } = getServiceAccessors<WishWithoutId, Wish>(elementName)
|
||||
const serviceAccessors = new ServiceAccessors<WishWithoutId, Wish>(elementName)
|
||||
|
||||
export const wishListGet = listGet()
|
||||
export const wishGet = get()
|
||||
export const wishAdd = add()
|
||||
export const wishSet = set()
|
||||
export const wishListGet = serviceAccessors.listGet()
|
||||
export const wishGet = serviceAccessors.get()
|
||||
export const wishAdd = serviceAccessors.add()
|
||||
export const wishSet = serviceAccessors.set()
|
||||
|
Reference in New Issue
Block a user