mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-09-11 22:06:29 +02:00
Add announcements page, i.e gazettes and comptes rendus
This commit is contained in:
@@ -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
|
||||
|
23
src/services/announcement.ts
Normal file
23
src/services/announcement.ts
Normal 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">
|
10
src/services/announcementAccessors.ts
Normal file
10
src/services/announcementAccessors.ts
Normal 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()
|
Reference in New Issue
Block a user