Skip to content
Snippets Groups Projects
editor.service.ts 854 B
Newer Older
  • Learn to ignore specific revisions
  • Guilhem CARRON's avatar
    Guilhem CARRON committed
    export class EditorService {
      /**
       * Createsa quotation and header for selected month
       * @param date
       * @param header
       * @param quote
       */
      public sendQuotation = async (
        date: string,
        header: string,
        quote: string
      ): Promise<void> => {
        try {
          const response = await fetch(
            'https://localhost:1443/api/admin/monthlyNews',
            {
              method: 'POST',
              body: JSON.stringify({
                month: date.split('-')[0],
                year: date.split('-')[1],
                header: header,
                quote: quote,
              }),
            }
          )
          if (response.status !== 201) {
            throw new Error(
              `Le post n'a pas pu être créé (code ${response.status})`
            )
          }
          console.log('Le post a été créé avec succès')
        } catch (e) {
          console.log(e)
        }
      }
    }