Add global variables for meeting dates

This commit is contained in:
pikiou
2022-04-29 01:52:08 +02:00
parent 514cf1b833
commit 18c6f75511
16 changed files with 311 additions and 25 deletions

View File

@@ -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
View 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"]
}

View 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"
)

View File

@@ -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()