Add Ask Discord

This commit is contained in:
pikiou
2022-04-19 02:33:05 +02:00
parent ebefcb247c
commit 74b5ef9e96
20 changed files with 198 additions and 223 deletions

View File

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

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

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

View File

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