Newer
Older
import axios, { AxiosRequestConfig } from 'axios'
import { DateTime } from 'luxon'
import { toast } from 'react-toastify'
GrdfConsentEntity,
GrdfConsentPaginationEntity,
IGrdfConsent,
IGrdfConsentPagination,
} from '../models/grdfConsent'
/**
* Search for consents
* @param search
* @param limit
* @param page
public searchConsents = async (
search: string,
): Promise<IGrdfConsentPagination | null> => {
const { data } = await axios.get<GrdfConsentPaginationEntity>(
`/api/admin/grdf/consent?search=${search}&limit=${limit}&page=${page}`,
return this.parseConsentPagination(data)
toast.error("Accès refusé : vous n'avez pas les droits nécessaires")
toast.error('Erreur lors de la récupération des consentements')
}
console.error(e)
return null
}
}
/**
* Converts consent entity into consent
* @param consentEntity
*/
public parseConsent = (consentEntity: GrdfConsentEntity): IGrdfConsent => {
const startDate = DateTime.fromISO(consentEntity.CreatedAt, {
const endDate = DateTime.fromISO(consentEntity.endDate, {
ID: consentEntity.ID,
startDate: startDate,
endDate: endDate,
firstname: consentEntity.firstname,
lastname: consentEntity.lastname,
postalCode: consentEntity.postalCode,
}
}
/**
* Converts consent pagination entity into consent pagination
* @param consentPaginationEntity
*/
public parseConsentPagination = (
consentPaginationEntity: GrdfConsentPaginationEntity
): IGrdfConsentPagination => {
const consentPagination: IGrdfConsentPagination = {
rows: rows,
totalRows: consentPaginationEntity.totalRows,
totalPages: consentPaginationEntity.totalPages,
}
return consentPagination
}
}