Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import axios, { AxiosRequestConfig } from 'axios'
import { DateTime } from 'luxon'
import { toast } from 'react-toastify'
import {
ISgeConsent,
ISgeConsentPagination,
SgeConsentEntity,
SgeConsentPaginationEntity,
} from '../models/sgeConsent.model'
export class SgeConsentService {
/**
* Search for consents
* @param search
* @param limit
* @param page
* @param axiosHeaders
*/
public searchConsents = async (
search: string,
limit: number,
page: number,
axiosHeaders: AxiosRequestConfig
): Promise<ISgeConsentPagination | null> => {
try {
const { data } = await axios.get(
`/api/admin/sge/consent?search=${search}&limit=${limit}&page=${page}`,
axiosHeaders
)
const consentPagination = data as SgeConsentPaginationEntity
return this.parseConsentPagination(consentPagination)
} catch (e) {
if (e.response.status === 403) {
toast.error("Accès refusé : vous n'avez pas les droits nécessaires")
} else {
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, {
zone: 'utc',
}).setLocale('fr-FR')
const endDate = DateTime.fromISO(consentEntity.endDate, {
zone: 'utc',
}).setLocale('fr-FR')
return {
ID: consentEntity.ID,
startDate: startDate,
endDate: endDate,
firstname: consentEntity.firstname,
lastname: consentEntity.lastname,
pointID: consentEntity.pointID,
address: consentEntity.address,
postalCode: consentEntity.postalCode,
city: consentEntity.city,
safetyOnBoarding: consentEntity.safetyOnBoarding,
}
}
/**
* Converts consent pagination entity into consent pagination
* @param consentPaginationEntity
*/
public parseConsentPagination = (
consentPaginationEntity: SgeConsentPaginationEntity
): ISgeConsentPagination => {
const rows = consentPaginationEntity.rows.map(consent =>
this.parseConsent(consent)
)
const consentPagination: ISgeConsentPagination = {
rows: rows,
totalRows: consentPaginationEntity.totalRows,
totalPages: consentPaginationEntity.totalPages,
}
return consentPagination
}
}