Newer
Older
import axios, { AxiosRequestConfig } from 'axios'
import { DateTime } from 'luxon'
import { toast } from 'react-toastify'
ISgeConsent,
ISgeConsentPagination,
SgeConsentEntity,
SgeConsentPaginationEntity,
} from '../models/sgeConsent.model'
/**
* Search for consents
* @param search
* @param limit
* @param page
public searchConsents = async (
search: string,
): Promise<ISgeConsentPagination | null> => {
const { data } = await axios.get<SgeConsentPaginationEntity>(
`/api/admin/sge/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: SgeConsentEntity): ISgeConsent => {
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,
pointID: consentEntity.pointID,
address: consentEntity.address,
postalCode: consentEntity.postalCode,
safetyOnBoarding: consentEntity.safetyOnBoarding,
}
}
/**
* Converts consent pagination entity into consent pagination
* @param consentPaginationEntity
*/
public parseConsentPagination = (
consentPaginationEntity: SgeConsentPaginationEntity
): ISgeConsentPagination => {
const consentPagination: ISgeConsentPagination = {
rows: rows,
totalRows: consentPaginationEntity.totalRows,
totalPages: consentPaginationEntity.totalPages,
}
return consentPagination
}
}