Newer
Older
import { IMonthlyInfo } from '../models/monthlyInfo.model'
export class NewsletterService {
* Creates a monthlyInfo for selected month
public saveMonthlyInfo = async (
month: date.getMonth(),
year: date.getFullYear(),
},
{
headers: {
'XSRF-TOKEN': token,
},
toast.success('Monthly info succesfully saved !')
toast.error('Failed to create monthly info')
console.error(e)
* Gets the information for selected month
public getSingleMonthlyInfo = async (
year: number,
month: number,
token: string
): Promise<IMonthlyInfo | null> => {
`/api/admin/monthlyInfo/${year}/${month}`,
headers: {
'XSRF-TOKEN': token,
},
return data as IMonthlyInfo
* Deletes a Monthly Info for selected month
* @param year
* @param month
* @param token
public deleteMonthlyInfo = async (
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
): Promise<void> => {
try {
await axios.delete(`/api/admin/monthlyInfo/${year}/${month}`, {
headers: {
'XSRF-TOKEN': token,
},
})
toast.success('Monthly info succesfully deleted !')
} catch (e) {
toast.error('Failed to delete monthly info')
console.error(e)
}
}
/**
* Creates a monthlyNews for selected month
* @param date
* @param title
* @param content
*/
public saveMonthlyNews = async (
date: Date,
title: string,
content: string,
token: string
): Promise<void> => {
try {
await axios.put(
`/api/admin/monthlyNews`,
{
month: date.getMonth(),
year: date.getFullYear(),
title: title,
content: content,
},
{
headers: {
'XSRF-TOKEN': token,
},
}
)
toast.success('Monthly news succesfully saved !')
} catch (e) {
toast.error('Failed to create monthly news')
console.error(e)
}
}
/**
* Gets a news title and content for selected month
*/
public getSingleMonthlyNews = async (
year: number,
month: number,
token: string
): Promise<IMonthlyNews | null> => {
`/api/admin/monthlyNews/${year}/${month}`,
{
headers: {
'XSRF-TOKEN': token,
},
}
)
return data as IMonthlyNews
console.error('error', e)
/**
* Deletes a Monthly News for selected month
* @param year
* @param month
* @param token
*/
public deleteMonthlyNews = async (
year: number,
month: number,
token: string
): Promise<void> => {
try {
await axios.delete(`/api/admin/monthlyNews/${year}/${month}`, {
headers: {
'XSRF-TOKEN': token,
},
})
toast.success('Monthly news succesfully deleted !')
} catch (e) {
toast.error('Failed to delete monthly news')
console.error(e)
}
}
/**
* Creates a poll with question and link for selected month
* @param date
* @param question
* @param link
*/
public savePoll = async (
date: Date,
question: string,
link: string,
token: string
): Promise<void> => {
try {
{
month: date.getMonth(),
year: date.getFullYear(),
link: link,
question: question,
},
{
headers: {
'XSRF-TOKEN': token,
},
}
)
toast.success('Poll successfully saved !')
* Gets a poll with question and link for selected month
public getSinglePoll = async (
year: number,
month: number,
token: string
): Promise<IPoll | null> => {
const { data } = await axios.get(`/api/admin/poll/${year}/${month}`, {
headers: {
'XSRF-TOKEN': token,
},
})
return data as IPoll
console.error('error', e)
return null
* Deletes a poll for selected month
public deletePoll = async (
year: number,
month: number,
token: string
): Promise<void> => {
try {
await axios.delete(`/api/admin/poll/${year}/${month}`, {
headers: {
'XSRF-TOKEN': token,
},
})
toast.success('Poll succesfully deleted !')
toast.error('Failed to delete poll')
console.error(e)