Skip to content
Snippets Groups Projects
Commit d8222102 authored by Rémi PAILHAREY's avatar Rémi PAILHAREY :fork_knife_plate:
Browse files

Merge branch 'fix-requested-month-is-1' into 'dev'

Fix requested month is -1

See merge request web-et-numerique/llle_project/backoffice-client!14
parents 8c592bdb 73a16644
No related branches found
No related tags found
3 merge requests!24fix(typo): écogestes + optionnel poll,!22feat: Add partners issue info,!14Fix requested month is -1
Pipeline #16650 passed
......@@ -67,31 +67,19 @@ const Editing: React.FC = () => {
const handleDeleteMonthlyInfo = async (): Promise<void> => {
if (user) {
await newsletterService.deleteMonthlyInfo(
date.getFullYear(),
date.getMonth(),
user.xsrftoken
)
await newsletterService.deleteMonthlyInfo(date, user.xsrftoken)
setRefreshData(true)
}
}
const handleDeleteMonthlyNews = async (): Promise<void> => {
if (user) {
await newsletterService.deleteMonthlyNews(
date.getFullYear(),
date.getMonth(),
user.xsrftoken
)
await newsletterService.deleteMonthlyNews(date, user.xsrftoken)
setRefreshData(true)
}
}
const handleDeletePoll = async (): Promise<void> => {
if (user) {
await newsletterService.deletePoll(
date.getFullYear(),
date.getMonth(),
user.xsrftoken
)
await newsletterService.deletePoll(date, user.xsrftoken)
setRefreshData(true)
}
}
......@@ -167,20 +155,11 @@ const Editing: React.FC = () => {
if (user) {
const newsletterService = new NewsletterService()
const montlhyInfo: IMonthlyInfo | null =
await newsletterService.getSingleMonthlyInfo(
date.getFullYear(),
date.getMonth(),
user.xsrftoken
)
await newsletterService.getSingleMonthlyInfo(date, user.xsrftoken)
const montlhyNews: IMonthlyNews | null =
await newsletterService.getSingleMonthlyNews(
date.getFullYear(),
date.getMonth(),
user.xsrftoken
)
await newsletterService.getSingleMonthlyNews(date, user.xsrftoken)
const poll: IPoll | null = await newsletterService.getSinglePoll(
date.getFullYear(),
date.getMonth(),
date,
user.xsrftoken
)
if (montlhyInfo) {
......
......@@ -19,7 +19,7 @@ export class NewsletterService {
await axios.put(
`/api/admin/monthlyInfo`,
{
month: date.getMonth(),
month: date.getMonth() + 1,
year: date.getFullYear(),
info: info,
image: image,
......@@ -39,15 +39,16 @@ export class NewsletterService {
/**
* Gets the information for selected month
* @param date
* @param token
*/
public getSingleMonthlyInfo = async (
year: number,
month: number,
date: Date,
token: string
): Promise<IMonthlyInfo | null> => {
try {
const { data } = await axios.get(
`/api/admin/monthlyInfo/${year}/${month}`,
`/api/admin/monthlyInfo/${date.getFullYear()}/${date.getMonth() + 1}`,
{
headers: {
'XSRF-TOKEN': token,
......@@ -63,21 +64,22 @@ export class NewsletterService {
/**
* Deletes a Monthly Info for selected month
* @param year
* @param month
* @param date
* @param token
*/
public deleteMonthlyInfo = async (
year: number,
month: number,
date: Date,
token: string
): Promise<void> => {
try {
await axios.delete(`/api/admin/monthlyInfo/${year}/${month}`, {
headers: {
'XSRF-TOKEN': token,
},
})
await axios.delete(
`/api/admin/monthlyInfo/${date.getFullYear()}/${date.getMonth() + 1}`,
{
headers: {
'XSRF-TOKEN': token,
},
}
)
toast.success('Monthly info succesfully deleted !')
} catch (e) {
toast.error('Failed to delete monthly info')
......@@ -101,7 +103,7 @@ export class NewsletterService {
await axios.put(
`/api/admin/monthlyNews`,
{
month: date.getMonth(),
month: date.getMonth() + 1,
year: date.getFullYear(),
title: title,
content: content,
......@@ -121,15 +123,16 @@ export class NewsletterService {
/**
* Gets a news title and content for selected month
* @param date
* @param token
*/
public getSingleMonthlyNews = async (
year: number,
month: number,
date: Date,
token: string
): Promise<IMonthlyNews | null> => {
try {
const { data } = await axios.get(
`/api/admin/monthlyNews/${year}/${month}`,
`/api/admin/monthlyNews/${date.getFullYear()}/${date.getMonth() + 1}`,
{
headers: {
'XSRF-TOKEN': token,
......@@ -145,21 +148,22 @@ export class NewsletterService {
/**
* Deletes a Monthly News for selected month
* @param year
* @param month
* @param date
* @param token
*/
public deleteMonthlyNews = async (
year: number,
month: number,
date: Date,
token: string
): Promise<void> => {
try {
await axios.delete(`/api/admin/monthlyNews/${year}/${month}`, {
headers: {
'XSRF-TOKEN': token,
},
})
await axios.delete(
`/api/admin/monthlyNews/${date.getFullYear()}/${date.getMonth() + 1}`,
{
headers: {
'XSRF-TOKEN': token,
},
}
)
toast.success('Monthly news succesfully deleted !')
} catch (e) {
toast.error('Failed to delete monthly news')
......@@ -183,7 +187,7 @@ export class NewsletterService {
await axios.put(
`/api/admin/poll`,
{
month: date.getMonth(),
month: date.getMonth() + 1,
year: date.getFullYear(),
link: link,
question: question,
......@@ -203,18 +207,22 @@ export class NewsletterService {
/**
* Gets a poll with question and link for selected month
* @param date
* @param token
*/
public getSinglePoll = async (
year: number,
month: number,
date: Date,
token: string
): Promise<IPoll | null> => {
try {
const { data } = await axios.get(`/api/admin/poll/${year}/${month}`, {
headers: {
'XSRF-TOKEN': token,
},
})
const { data } = await axios.get(
`/api/admin/poll/${date.getFullYear()}/${date.getMonth() + 1}`,
{
headers: {
'XSRF-TOKEN': token,
},
}
)
return data as IPoll
} catch (e) {
console.error('error', e)
......@@ -224,21 +232,19 @@ export class NewsletterService {
/**
* Deletes a poll for selected month
* @param month
* @param year
* @param date
* @param token
*/
public deletePoll = async (
year: number,
month: number,
token: string
): Promise<void> => {
public deletePoll = async (date: Date, token: string): Promise<void> => {
try {
await axios.delete(`/api/admin/poll/${year}/${month}`, {
headers: {
'XSRF-TOKEN': token,
},
})
await axios.delete(
`/api/admin/poll/${date.getFullYear()}/${date.getMonth() + 1}`,
{
headers: {
'XSRF-TOKEN': token,
},
}
)
toast.success('Poll succesfully deleted !')
} catch (e) {
toast.error('Failed to delete poll')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment