Newer
Older
export class MonthlyNewsService {
private readonly _apiUrl: string
constructor() {
this._apiUrl = 'https://localhost:1443/'
}
* Creates a quotation and header for selected month
* @param date
* @param header
* @param quote
*/
await axios.post(
`${this._apiUrl}api/admin/monthlyNews`,
month: date.getMonth(),
year: date.getFullYear(),
header: header,
quote: quote,
},
{
headers: {
'XSRF-TOKEN': token,
},
/**
* Gets a quotation and header for selected month
*/
year: number,
month: number,
token: string
const { data } = await axios.get(
`${this._apiUrl}api/admin/monthlyNews/${year}/${month}`,
headers: {
'XSRF-TOKEN': token,
},
console.log('monthlyFetched', data)
if (data == {}) {
return null
}
69
70
71
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
return null
}
}
/**
* Gets a poll with question and link for selected month
*/
public getSinglePoll = async (
year: number,
month: number,
token: string
): Promise<IPoll | null> => {
try {
const { data } = await axios.get(
`${this._apiUrl}api/admin/poll/${year}/${month}`,
{
headers: {
'XSRF-TOKEN': token,
},
}
)
if (data === {}) {
return null
}
return data as IPoll
} catch (e) {
console.log('error', e)
return null
}
}
/**
* Creates a poll with question and link for selected month
* @param date
* @param question
* @param link
*/
public createPoll = async (
date: Date,
question: string,
link: string,
token: string
): Promise<void> => {
try {
await axios.post(
`${this._apiUrl}api/admin/poll`,
{
month: date.getMonth(),
year: date.getFullYear(),
link: link,
question: question,
},
{
headers: {
'XSRF-TOKEN': token,
},
}
)
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/**
* Deletes a poll for selected month
* @param month
* @param year
* @param token
*/
public deletePoll = async (
year: number,
month: number,
token: string
): Promise<void> => {
try {
await axios.delete(`${this._apiUrl}api/admin/poll/${year}/${month}`, {
headers: {
'XSRF-TOKEN': token,
},
})
toast.success('Poll succesfully deleted !')
} catch (e) {
toast.error('Failed to delete poll')
console.log(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(
`${this._apiUrl}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.log(e)
}
}