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

fix: changed month range from [0;11] to [1;12]

parent 3a6b22c7
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 #16481 passed
...@@ -67,31 +67,19 @@ const Editing: React.FC = () => { ...@@ -67,31 +67,19 @@ const Editing: React.FC = () => {
const handleDeleteMonthlyInfo = async (): Promise<void> => { const handleDeleteMonthlyInfo = async (): Promise<void> => {
if (user) { if (user) {
await newsletterService.deleteMonthlyInfo( await newsletterService.deleteMonthlyInfo(date, user.xsrftoken)
date.getFullYear(),
date.getMonth(),
user.xsrftoken
)
setRefreshData(true) setRefreshData(true)
} }
} }
const handleDeleteMonthlyNews = async (): Promise<void> => { const handleDeleteMonthlyNews = async (): Promise<void> => {
if (user) { if (user) {
await newsletterService.deleteMonthlyNews( await newsletterService.deleteMonthlyNews(date, user.xsrftoken)
date.getFullYear(),
date.getMonth(),
user.xsrftoken
)
setRefreshData(true) setRefreshData(true)
} }
} }
const handleDeletePoll = async (): Promise<void> => { const handleDeletePoll = async (): Promise<void> => {
if (user) { if (user) {
await newsletterService.deletePoll( await newsletterService.deletePoll(date, user.xsrftoken)
date.getFullYear(),
date.getMonth(),
user.xsrftoken
)
setRefreshData(true) setRefreshData(true)
} }
} }
...@@ -167,20 +155,11 @@ const Editing: React.FC = () => { ...@@ -167,20 +155,11 @@ const Editing: React.FC = () => {
if (user) { if (user) {
const newsletterService = new NewsletterService() const newsletterService = new NewsletterService()
const montlhyInfo: IMonthlyInfo | null = const montlhyInfo: IMonthlyInfo | null =
await newsletterService.getSingleMonthlyInfo( await newsletterService.getSingleMonthlyInfo(date, user.xsrftoken)
date.getFullYear(),
date.getMonth(),
user.xsrftoken
)
const montlhyNews: IMonthlyNews | null = const montlhyNews: IMonthlyNews | null =
await newsletterService.getSingleMonthlyNews( await newsletterService.getSingleMonthlyNews(date, user.xsrftoken)
date.getFullYear(),
date.getMonth(),
user.xsrftoken
)
const poll: IPoll | null = await newsletterService.getSinglePoll( const poll: IPoll | null = await newsletterService.getSinglePoll(
date.getFullYear(), date,
date.getMonth(),
user.xsrftoken user.xsrftoken
) )
if (montlhyInfo) { if (montlhyInfo) {
......
...@@ -19,7 +19,7 @@ export class NewsletterService { ...@@ -19,7 +19,7 @@ export class NewsletterService {
await axios.put( await axios.put(
`/api/admin/monthlyInfo`, `/api/admin/monthlyInfo`,
{ {
month: date.getMonth(), month: date.getMonth() + 1,
year: date.getFullYear(), year: date.getFullYear(),
info: info, info: info,
image: image, image: image,
...@@ -39,15 +39,16 @@ export class NewsletterService { ...@@ -39,15 +39,16 @@ export class NewsletterService {
/** /**
* Gets the information for selected month * Gets the information for selected month
* @param date
* @param token
*/ */
public getSingleMonthlyInfo = async ( public getSingleMonthlyInfo = async (
year: number, date: Date,
month: number,
token: string token: string
): Promise<IMonthlyInfo | null> => { ): Promise<IMonthlyInfo | null> => {
try { try {
const { data } = await axios.get( const { data } = await axios.get(
`/api/admin/monthlyInfo/${year}/${month}`, `/api/admin/monthlyInfo/${date.getFullYear()}/${date.getMonth() + 1}`,
{ {
headers: { headers: {
'XSRF-TOKEN': token, 'XSRF-TOKEN': token,
...@@ -63,21 +64,22 @@ export class NewsletterService { ...@@ -63,21 +64,22 @@ export class NewsletterService {
/** /**
* Deletes a Monthly Info for selected month * Deletes a Monthly Info for selected month
* @param year * @param date
* @param month
* @param token * @param token
*/ */
public deleteMonthlyInfo = async ( public deleteMonthlyInfo = async (
year: number, date: Date,
month: number,
token: string token: string
): Promise<void> => { ): Promise<void> => {
try { try {
await axios.delete(`/api/admin/monthlyInfo/${year}/${month}`, { await axios.delete(
headers: { `/api/admin/monthlyInfo/${date.getFullYear()}/${date.getMonth() + 1}`,
'XSRF-TOKEN': token, {
}, headers: {
}) 'XSRF-TOKEN': token,
},
}
)
toast.success('Monthly info succesfully deleted !') toast.success('Monthly info succesfully deleted !')
} catch (e) { } catch (e) {
toast.error('Failed to delete monthly info') toast.error('Failed to delete monthly info')
...@@ -101,7 +103,7 @@ export class NewsletterService { ...@@ -101,7 +103,7 @@ export class NewsletterService {
await axios.put( await axios.put(
`/api/admin/monthlyNews`, `/api/admin/monthlyNews`,
{ {
month: date.getMonth(), month: date.getMonth() + 1,
year: date.getFullYear(), year: date.getFullYear(),
title: title, title: title,
content: content, content: content,
...@@ -121,15 +123,16 @@ export class NewsletterService { ...@@ -121,15 +123,16 @@ export class NewsletterService {
/** /**
* Gets a news title and content for selected month * Gets a news title and content for selected month
* @param date
* @param token
*/ */
public getSingleMonthlyNews = async ( public getSingleMonthlyNews = async (
year: number, date: Date,
month: number,
token: string token: string
): Promise<IMonthlyNews | null> => { ): Promise<IMonthlyNews | null> => {
try { try {
const { data } = await axios.get( const { data } = await axios.get(
`/api/admin/monthlyNews/${year}/${month}`, `/api/admin/monthlyNews/${date.getFullYear()}/${date.getMonth() + 1}`,
{ {
headers: { headers: {
'XSRF-TOKEN': token, 'XSRF-TOKEN': token,
...@@ -145,21 +148,22 @@ export class NewsletterService { ...@@ -145,21 +148,22 @@ export class NewsletterService {
/** /**
* Deletes a Monthly News for selected month * Deletes a Monthly News for selected month
* @param year * @param date
* @param month
* @param token * @param token
*/ */
public deleteMonthlyNews = async ( public deleteMonthlyNews = async (
year: number, date: Date,
month: number,
token: string token: string
): Promise<void> => { ): Promise<void> => {
try { try {
await axios.delete(`/api/admin/monthlyNews/${year}/${month}`, { await axios.delete(
headers: { `/api/admin/monthlyNews/${date.getFullYear()}/${date.getMonth() + 1}`,
'XSRF-TOKEN': token, {
}, headers: {
}) 'XSRF-TOKEN': token,
},
}
)
toast.success('Monthly news succesfully deleted !') toast.success('Monthly news succesfully deleted !')
} catch (e) { } catch (e) {
toast.error('Failed to delete monthly news') toast.error('Failed to delete monthly news')
...@@ -183,7 +187,7 @@ export class NewsletterService { ...@@ -183,7 +187,7 @@ export class NewsletterService {
await axios.put( await axios.put(
`/api/admin/poll`, `/api/admin/poll`,
{ {
month: date.getMonth(), month: date.getMonth() + 1,
year: date.getFullYear(), year: date.getFullYear(),
link: link, link: link,
question: question, question: question,
...@@ -203,18 +207,22 @@ export class NewsletterService { ...@@ -203,18 +207,22 @@ export class NewsletterService {
/** /**
* Gets a poll with question and link for selected month * Gets a poll with question and link for selected month
* @param date
* @param token
*/ */
public getSinglePoll = async ( public getSinglePoll = async (
year: number, date: Date,
month: number,
token: string token: string
): Promise<IPoll | null> => { ): Promise<IPoll | null> => {
try { try {
const { data } = await axios.get(`/api/admin/poll/${year}/${month}`, { const { data } = await axios.get(
headers: { `/api/admin/poll/${date.getFullYear()}/${date.getMonth() + 1}`,
'XSRF-TOKEN': token, {
}, headers: {
}) 'XSRF-TOKEN': token,
},
}
)
return data as IPoll return data as IPoll
} catch (e) { } catch (e) {
console.error('error', e) console.error('error', e)
...@@ -224,21 +232,19 @@ export class NewsletterService { ...@@ -224,21 +232,19 @@ export class NewsletterService {
/** /**
* Deletes a poll for selected month * Deletes a poll for selected month
* @param month * @param date
* @param year
* @param token * @param token
*/ */
public deletePoll = async ( public deletePoll = async (date: Date, token: string): Promise<void> => {
year: number,
month: number,
token: string
): Promise<void> => {
try { try {
await axios.delete(`/api/admin/poll/${year}/${month}`, { await axios.delete(
headers: { `/api/admin/poll/${date.getFullYear()}/${date.getMonth() + 1}`,
'XSRF-TOKEN': token, {
}, headers: {
}) 'XSRF-TOKEN': token,
},
}
)
toast.success('Poll succesfully deleted !') toast.success('Poll succesfully deleted !')
} catch (e) { } catch (e) {
toast.error('Failed to delete poll') 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