Add announcements page, i.e gazettes and comptes rendus

This commit is contained in:
pikiou
2022-02-07 17:21:22 +01:00
parent bd8a74cd17
commit 998691b542
19 changed files with 347 additions and 18 deletions

View File

@@ -58,6 +58,32 @@ export default class ServiceAccessors<
}
}
secureListGet(): (jwt: string) => Promise<{
data?: Element[]
error?: Error
}> {
interface ElementListGetResponse {
data?: Element[]
error?: Error
}
return async (jwt: string): Promise<ElementListGetResponse> => {
try {
const auth = { headers: { Authorization: `Bearer ${jwt}` } }
const fullAxiosConfig = _.defaultsDeep(auth, axiosConfig)
const { data } = await axios.get(
`${config.API_URL}/${this.elementName}ListGet`,
fullAxiosConfig
)
if (data.error) {
throw Error(data.error)
}
return { data }
} catch (error) {
return { error: error as Error }
}
}
}
// eslint-disable-next-line @typescript-eslint/ban-types
add(): (volunteerWithoutId: ElementNoId) => Promise<{
data?: Element

View File

@@ -0,0 +1,23 @@
export class Announcement {
id = 0
created = new Date()
type = ""
title = ""
url = ""
}
export const translationAnnouncement: { [k in keyof Announcement]: string } = {
id: "id",
created: "creation",
type: "type",
title: "titre",
url: "url",
}
export const elementName = "Announcement"
export type AnnouncementWithoutId = Omit<Announcement, "id">

View File

@@ -0,0 +1,10 @@
import ServiceAccessors from "./accessors"
import { elementName, Announcement, AnnouncementWithoutId } from "./announcement"
const serviceAccessors = new ServiceAccessors<AnnouncementWithoutId, Announcement>(elementName)
// export const announcementGet = serviceAccessors.get()
// export const announcementAdd = serviceAccessors.add()
// export const announcementSet = serviceAccessors.set()
export const announcementListGet = serviceAccessors.secureListGet()