mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-09-11 22:06:29 +02:00
Add global variables for meeting dates
This commit is contained in:
@@ -165,6 +165,32 @@ export default class ServiceAccessors<
|
||||
}
|
||||
}
|
||||
|
||||
customGet<InputElements extends Array<any>, OutputType>(
|
||||
apiName: string
|
||||
): (...params: InputElements) => Promise<{
|
||||
data?: any
|
||||
error?: Error
|
||||
}> {
|
||||
interface ElementGetResponse {
|
||||
data?: any
|
||||
error?: Error
|
||||
}
|
||||
return async (...params: InputElements): Promise<ElementGetResponse> => {
|
||||
try {
|
||||
const { data } = await axios.get(
|
||||
`${config.API_URL}/${this.elementName}${apiName}`,
|
||||
{ ...axiosConfig, params }
|
||||
)
|
||||
if (data.error) {
|
||||
throw Error(data.error)
|
||||
}
|
||||
return { data } as { data: OutputType }
|
||||
} catch (error) {
|
||||
return { error: error as Error }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
customPost<InputElements extends Array<any>>(
|
||||
apiName: string
|
||||
): (...params: InputElements) => Promise<{
|
||||
@@ -192,7 +218,7 @@ export default class ServiceAccessors<
|
||||
}
|
||||
}
|
||||
|
||||
securedCustomGet<InputElements extends Array<any>>(
|
||||
securedCustomGet<InputElements extends Array<any>, OutputType>(
|
||||
apiName: string
|
||||
): (
|
||||
jwt: string,
|
||||
@@ -216,7 +242,7 @@ export default class ServiceAccessors<
|
||||
if (data.error) {
|
||||
throw Error(data.error)
|
||||
}
|
||||
return { data }
|
||||
return { data } as { data: OutputType }
|
||||
} catch (error) {
|
||||
return { error: error as Error }
|
||||
}
|
||||
|
32
src/services/miscs.ts
Normal file
32
src/services/miscs.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/* eslint-disable max-classes-per-file */
|
||||
export class Misc {
|
||||
id = 0
|
||||
|
||||
meetingId = ""
|
||||
|
||||
meetingTitle = ""
|
||||
|
||||
discordInvitation = ""
|
||||
}
|
||||
|
||||
export const translationMisc: { [k in keyof Misc]: string } = {
|
||||
id: "id",
|
||||
meetingId: "rencontreId",
|
||||
meetingTitle: "rencontreTitre",
|
||||
discordInvitation: "invitationDiscord",
|
||||
}
|
||||
|
||||
export const elementName = "Misc"
|
||||
|
||||
export type MiscWithoutId = Omit<Misc, "id">
|
||||
|
||||
export interface MiscMeetingDate {
|
||||
id: Misc["id"]
|
||||
meetingId: Misc["meetingId"]
|
||||
meetingTitle: Misc["meetingTitle"]
|
||||
}
|
||||
|
||||
export interface MiscDiscordInvitation {
|
||||
id: Misc["id"]
|
||||
discordInvitation: Misc["discordInvitation"]
|
||||
}
|
12
src/services/miscsAccessors.ts
Normal file
12
src/services/miscsAccessors.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import ServiceAccessors from "./accessors"
|
||||
import { elementName, Misc, MiscDiscordInvitation, MiscMeetingDate, MiscWithoutId } from "./miscs"
|
||||
|
||||
const serviceAccessors = new ServiceAccessors<MiscWithoutId, Misc>(elementName)
|
||||
|
||||
export const miscDiscordInvitation = serviceAccessors.securedCustomGet<[], MiscDiscordInvitation>(
|
||||
"DiscordInvitationGet"
|
||||
)
|
||||
|
||||
export const miscMeetingDateListGet = serviceAccessors.customGet<[], MiscMeetingDate>(
|
||||
"MeetingDateListGet"
|
||||
)
|
@@ -8,12 +8,16 @@ import {
|
||||
VolunteerTeamWishes,
|
||||
VolunteerTeamAssign,
|
||||
VolunteerWithoutId,
|
||||
VolunteerDiscordId,
|
||||
} from "./volunteers"
|
||||
|
||||
const serviceAccessors = new ServiceAccessors<VolunteerWithoutId, Volunteer>(elementName)
|
||||
|
||||
export const volunteerListGet = serviceAccessors.securedListGet()
|
||||
export const volunteerDiscordIdGet = serviceAccessors.securedCustomGet<[number]>("DiscordId")
|
||||
export const volunteerDiscordIdGet = serviceAccessors.securedCustomGet<
|
||||
[number],
|
||||
VolunteerDiscordId
|
||||
>("DiscordId")
|
||||
export const volunteerPartialAdd = serviceAccessors.customPost<[Partial<Volunteer>]>("PartialAdd")
|
||||
export const volunteerSet = serviceAccessors.set()
|
||||
|
||||
|
Reference in New Issue
Block a user