mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-09-11 13:56:29 +02:00
Add Ask Discord
This commit is contained in:
@@ -64,7 +64,7 @@ export default class ServiceAccessors<
|
||||
}
|
||||
}
|
||||
|
||||
secureListGet(): (jwt: string) => Promise<{
|
||||
securedListGet(): (jwt: string) => Promise<{
|
||||
data?: Element[]
|
||||
error?: Error
|
||||
}> {
|
||||
@@ -192,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
|
||||
): (
|
||||
|
@@ -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()
|
||||
|
@@ -139,6 +139,11 @@ export interface VolunteerForgot {
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface VolunteerDiscordId {
|
||||
id: Volunteer["id"]
|
||||
discordId: Volunteer["discordId"]
|
||||
}
|
||||
|
||||
export interface VolunteerAsks {
|
||||
id: Volunteer["id"]
|
||||
firstname: Volunteer["firstname"]
|
||||
|
@@ -12,7 +12,7 @@ import {
|
||||
const serviceAccessors = new ServiceAccessors<VolunteerWithoutId, Volunteer>(elementName)
|
||||
|
||||
export const volunteerListGet = serviceAccessors.listGet()
|
||||
export const volunteerGet = serviceAccessors.get()
|
||||
export const volunteerDiscordIdGet = serviceAccessors.securedCustomGet<[number]>("DiscordId")
|
||||
export const volunteerPartialAdd = serviceAccessors.customPost<[Partial<Volunteer>]>("PartialAdd")
|
||||
export const volunteerSet = serviceAccessors.set()
|
||||
|
||||
|
Reference in New Issue
Block a user