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
}
65
66
67
68
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
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,
},
}
)
} catch (e) {
console.log(e)