Newer
Older
import { IMonthlyInfo } from '../models/monthlyInfo.model'
export class NewsletterService {
* Creates a monthlyInfo for selected month
public saveMonthlyInfo = async (
},
{
headers: {
'XSRF-TOKEN': token,
},
toast.success('Monthly info succesfully saved !')
} catch (e: any) {
if (e.response.status === 403) {
toast.error(
"Unauthorized : You don't have the rights to do this operation"
)
} else {
toast.error('Failed to create monthly info')
}
* Gets the information for selected month
public getSingleMonthlyInfo = async (
): Promise<IMonthlyInfo | null> => {
`/api/admin/monthlyInfo/${date.getFullYear()}/${date.getMonth() + 1}`,
headers: {
'XSRF-TOKEN': token,
},
return data as IMonthlyInfo
* Deletes a Monthly Info for selected month
public deleteMonthlyInfo = async (
): Promise<void> => {
try {
await axios.delete(
`/api/admin/monthlyInfo/${date.getFullYear()}/${date.getMonth() + 1}`,
{
headers: {
'XSRF-TOKEN': token,
},
}
)
toast.success('Monthly info succesfully deleted !')
} catch (e: any) {
if (e.response.status === 403) {
toast.error(
"Unauthorized : You don't have the rights to do this operation"
)
} else {
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`,
{
year: date.getFullYear(),
title: title,
content: content,
},
{
headers: {
'XSRF-TOKEN': token,
},
}
)
toast.success('Monthly news succesfully saved !')
} catch (e: any) {
if (e.response.status === 403) {
toast.error(
"Unauthorized : You don't have the rights to do this operation"
)
} else {
toast.error('Failed to save monthly news')
}
console.error(e)
}
}
/**
* Gets a news title and content for selected month
*/
public getSingleMonthlyNews = async (
token: string
): Promise<IMonthlyNews | null> => {
`/api/admin/monthlyNews/${date.getFullYear()}/${date.getMonth() + 1}`,
{
headers: {
'XSRF-TOKEN': token,
},
}
)
return data as IMonthlyNews
console.error('error', e)
/**
* Deletes a Monthly News for selected month
* @param token
*/
public deleteMonthlyNews = async (
token: string
): Promise<void> => {
try {
await axios.delete(
`/api/admin/monthlyNews/${date.getFullYear()}/${date.getMonth() + 1}`,
{
headers: {
'XSRF-TOKEN': token,
},
}
)
toast.success('Monthly news succesfully deleted !')
} catch (e: any) {
if (e.response.status === 403) {
toast.error(
"Unauthorized : You don't have the rights to do this operation"
)
} else {
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 {
year: date.getFullYear(),
link: link,
question: question,
},
{
headers: {
'XSRF-TOKEN': token,
},
}
)
toast.success('Poll successfully saved !')
} catch (e: any) {
if (e.response.status === 403) {
toast.error(
"Unauthorized : You don't have the rights to do this operation"
)
} else {
toast.error('Failed to create poll')
}
* Gets a poll with question and link for selected month
public getSinglePoll = async (
): Promise<IPoll | null> => {
const { data } = await axios.get(
`/api/admin/poll/${date.getFullYear()}/${date.getMonth() + 1}`,
{
headers: {
'XSRF-TOKEN': token,
},
}
)
console.error('error', e)
return null
* Deletes a poll for selected month
public deletePoll = async (date: Date, token: string): Promise<void> => {
await axios.delete(
`/api/admin/poll/${date.getFullYear()}/${date.getMonth() + 1}`,
{
headers: {
'XSRF-TOKEN': token,
},
}
)
toast.success('Poll succesfully deleted !')
} catch (e: any) {
if (e.response.status === 403) {
toast.error(
"Unauthorized : You don't have the rights to do this operation"
)
} else {
toast.error('Failed to delete poll')
}
/**
* Gets the ecogesture images URLs
*/
public getEcogestureImages = async (token: string): Promise<string[]> => {
try {
const { data: imageNames } = await axios.get(`/api/admin/imageNames`, {
headers: {
'XSRF-TOKEN': token,
},
})
if (imageNames && imageNames !== null) {
const imageURLs = imageNames.map((image: string) => {
})
return imageURLs
}
return []
} catch (e) {
console.error('error', e)
return []
}
}