@communecter/cocolight-api-client 1.0.18 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cocolight-api-client.browser.js +3 -3
- package/dist/cocolight-api-client.cjs +1 -1
- package/dist/cocolight-api-client.mjs.js +1 -1
- package/package.json +2 -2
- package/src/Api.js +7 -4
- package/src/ApiClient.js +3 -3
- package/src/api/Badge.js +117 -0
- package/src/api/BaseEntity.js +162 -0
- package/src/api/EndpointApi.js +6 -6
- package/src/api/Event.js +144 -0
- package/src/api/News.js +134 -219
- package/src/api/Organization.js +117 -238
- package/src/api/Poi.js +158 -0
- package/src/api/Project.js +124 -234
- package/src/api/User.js +332 -91
- package/src/api/UserApi.js +5 -2
- package/src/endpoints.module.js +2 -2
- package/src/mixin/EntityMixin.js +320 -1
- package/src/mixin/MutualEntityMixin.js +224 -3
- package/src/mixin/UtilMixin.js +7 -3
- package/src/mixin/NewsMixin.js +0 -42
package/src/api/User.js
CHANGED
|
@@ -6,9 +6,10 @@ import { UtilMixin } from "../mixin/UtilMixin.js";
|
|
|
6
6
|
|
|
7
7
|
// User.js
|
|
8
8
|
export class User {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
_draftData = {};
|
|
10
|
+
_initialDraftData = {};
|
|
11
|
+
_serverData = null;
|
|
12
|
+
_calledFromSave = false;
|
|
12
13
|
|
|
13
14
|
static entityType = "citoyens";
|
|
14
15
|
|
|
@@ -41,12 +42,15 @@ export class User {
|
|
|
41
42
|
* @param {function|object} deps.EndpointApi - Classe ou instance de EndpointApi.
|
|
42
43
|
* @param {function} deps.Organization - Classe Organization.
|
|
43
44
|
* @param {function} deps.Project - Classe Project.
|
|
45
|
+
* @param {function} deps.Event - Classe Events.
|
|
46
|
+
* @param {function} deps.Poi - Classe Poi.
|
|
47
|
+
* @param {function} deps.Badge - Classe Badge.
|
|
44
48
|
* @param {function} deps.News - Classe News.
|
|
45
49
|
*
|
|
46
50
|
* @throws {ApiError} - Si des dépendances nécessaires sont manquantes ou invalides.
|
|
47
51
|
*/
|
|
48
52
|
|
|
49
|
-
constructor(
|
|
53
|
+
constructor(parent, data = {}, deps = {}) {
|
|
50
54
|
this.__entityTag = "User";
|
|
51
55
|
|
|
52
56
|
if(!deps.EndpointApi){
|
|
@@ -58,9 +62,20 @@ export class User {
|
|
|
58
62
|
|
|
59
63
|
if (!deps.Organization) throw new ApiError("Organization class must be injected.");
|
|
60
64
|
if (!deps.Project) throw new ApiError("Project class must be injected.");
|
|
65
|
+
if (!deps.Event) throw new ApiError("Event class must be injected.");
|
|
66
|
+
if (!deps.Poi) throw new ApiError("Poi class must be injected.");
|
|
67
|
+
if (!deps.Badge) throw new ApiError("Badge class must be injected.");
|
|
61
68
|
if (!deps.News) throw new ApiError("News class must be injected.");
|
|
62
69
|
|
|
63
|
-
|
|
70
|
+
if (parent?.__entityTag === "ApiClient") {
|
|
71
|
+
this.apiClient = parent;
|
|
72
|
+
this.parent = null;
|
|
73
|
+
} else if (parent?.apiClient) {
|
|
74
|
+
this.apiClient = parent.apiClient;
|
|
75
|
+
this.parent = parent;
|
|
76
|
+
} else {
|
|
77
|
+
throw new ApiError("Parent invalide ou ApiClient manquant.");
|
|
78
|
+
}
|
|
64
79
|
|
|
65
80
|
this.deps = deps;
|
|
66
81
|
|
|
@@ -73,32 +88,32 @@ export class User {
|
|
|
73
88
|
throw new ApiError("deps.EndpointApi doit être une classe ou une instance valide.");
|
|
74
89
|
}
|
|
75
90
|
|
|
76
|
-
this
|
|
91
|
+
this._serverData = null;
|
|
77
92
|
|
|
78
93
|
const { draft, proxy } = this._buildDraftAndProxy({
|
|
79
94
|
data: { ...data, ...this.defaultFields },
|
|
80
|
-
serverData: this
|
|
95
|
+
serverData: this._serverData,
|
|
81
96
|
constant: User.SCHEMA_CONSTANTS,
|
|
82
97
|
apiClient: this.apiClient,
|
|
83
98
|
transforms: this.transforms,
|
|
84
99
|
removeFields: this.removeFields
|
|
85
100
|
});
|
|
86
101
|
|
|
87
|
-
this
|
|
88
|
-
this
|
|
102
|
+
this._initialDraftData = JSON.parse(JSON.stringify(draft)); // snapshot propre
|
|
103
|
+
this._draftData = draft;
|
|
89
104
|
this.data = proxy;
|
|
90
105
|
}
|
|
91
106
|
|
|
92
107
|
get id() {
|
|
93
|
-
return this
|
|
108
|
+
return this._draftData.id || null;
|
|
94
109
|
}
|
|
95
110
|
|
|
96
111
|
_id(newId) {
|
|
97
|
-
this
|
|
112
|
+
this._draftData.id = newId;
|
|
98
113
|
}
|
|
99
114
|
|
|
100
115
|
get slug() {
|
|
101
|
-
return this
|
|
116
|
+
return this._draftData.slug || null;
|
|
102
117
|
}
|
|
103
118
|
|
|
104
119
|
get isConnected() {
|
|
@@ -106,18 +121,18 @@ export class User {
|
|
|
106
121
|
}
|
|
107
122
|
|
|
108
123
|
_setData(newData) {
|
|
109
|
-
this
|
|
124
|
+
this._serverData = { ...newData };
|
|
110
125
|
|
|
111
126
|
const { draft, proxy } = this._buildDraftAndProxy({
|
|
112
127
|
data: { ...newData, ...this.defaultFields },
|
|
113
|
-
serverData: this
|
|
128
|
+
serverData: this._serverData,
|
|
114
129
|
constant: User.SCHEMA_CONSTANTS,
|
|
115
130
|
apiClient: this.apiClient,
|
|
116
131
|
transforms: this.transforms,
|
|
117
132
|
removeFields: this.removeFields
|
|
118
133
|
});
|
|
119
|
-
this
|
|
120
|
-
this
|
|
134
|
+
this._initialDraftData = JSON.parse(JSON.stringify(draft));
|
|
135
|
+
this._draftData = draft;
|
|
121
136
|
this.data = proxy;
|
|
122
137
|
}
|
|
123
138
|
|
|
@@ -134,15 +149,15 @@ export class User {
|
|
|
134
149
|
}
|
|
135
150
|
|
|
136
151
|
get draftData() {
|
|
137
|
-
return this
|
|
152
|
+
return this._draftData;
|
|
138
153
|
}
|
|
139
154
|
|
|
140
155
|
get initialDraftData() {
|
|
141
|
-
return this
|
|
156
|
+
return this._initialDraftData;
|
|
142
157
|
}
|
|
143
158
|
|
|
144
159
|
get serverData() {
|
|
145
|
-
return this
|
|
160
|
+
return this._serverData;
|
|
146
161
|
}
|
|
147
162
|
|
|
148
163
|
async refresh() {
|
|
@@ -199,16 +214,20 @@ export class User {
|
|
|
199
214
|
if(!this.isMe){
|
|
200
215
|
throw new ApiError("Vous devez être connecté et être l'utilisateur pour sauvegarder.");
|
|
201
216
|
}
|
|
202
|
-
|
|
203
|
-
|
|
217
|
+
this._calledFromSave = true;
|
|
218
|
+
try{
|
|
219
|
+
const payload = { ...this._draftData };
|
|
204
220
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
221
|
+
if (this.id) {
|
|
222
|
+
const hasChanged = await this._update(payload);
|
|
223
|
+
if (hasChanged) {
|
|
208
224
|
// this._updateInitialDraftSnapshot();
|
|
209
|
-
|
|
225
|
+
await this.refresh();
|
|
226
|
+
}
|
|
227
|
+
return this._serverData;
|
|
210
228
|
}
|
|
211
|
-
|
|
229
|
+
} finally {
|
|
230
|
+
this._calledFromSave = false;
|
|
212
231
|
}
|
|
213
232
|
|
|
214
233
|
}
|
|
@@ -220,6 +239,10 @@ export class User {
|
|
|
220
239
|
* @returns {Promise<boolean>} - Indique s'il y a eu une modification réelle.
|
|
221
240
|
*/
|
|
222
241
|
async _update(payload){
|
|
242
|
+
if (!this._calledFromSave) {
|
|
243
|
+
throw new Error("utilisation invalide de _update, utilisez save");
|
|
244
|
+
}
|
|
245
|
+
|
|
223
246
|
if(payload.id){
|
|
224
247
|
delete payload.id;
|
|
225
248
|
}
|
|
@@ -244,6 +267,26 @@ export class User {
|
|
|
244
267
|
return hasChanged;
|
|
245
268
|
}
|
|
246
269
|
|
|
270
|
+
static fromServerData(data, parent, deps) {
|
|
271
|
+
const instance = new User(parent.apiClient, data, deps);
|
|
272
|
+
instance._serverData = { ...data };
|
|
273
|
+
// est ce que je besoin de ça si il est contruit dans le constructeur ?
|
|
274
|
+
// il doit y avaoir une raison pour les autres objets
|
|
275
|
+
const { draft, proxy } = instance._buildDraftAndProxy({
|
|
276
|
+
data: { ...data, ...instance.defaultFields },
|
|
277
|
+
serverData: instance._serverData,
|
|
278
|
+
constant: User.SCHEMA_CONSTANTS,
|
|
279
|
+
apiClient: instance.apiClient,
|
|
280
|
+
transforms: instance.transforms,
|
|
281
|
+
removeFields: instance.removeFields
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
instance._draftData = draft;
|
|
285
|
+
instance.data = proxy;
|
|
286
|
+
|
|
287
|
+
return instance;
|
|
288
|
+
}
|
|
289
|
+
|
|
247
290
|
/**
|
|
248
291
|
* Mettre à jour les paramètres utilisateur : Mise à jour des paramètres spécifiques d'un utilisateur.
|
|
249
292
|
* Constant : UPDATE_SETTINGS
|
|
@@ -346,14 +389,8 @@ export class User {
|
|
|
346
389
|
const totalCount = Object.values(arrayObjetOrganizations.count || {}).reduce((acc, val) => acc + val, 0);
|
|
347
390
|
arrayObjetOrganizations.count.total = totalCount;
|
|
348
391
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
this.deps.Organization.fromServerData(orgData, this, {
|
|
352
|
-
User,
|
|
353
|
-
Project: this.deps.Project,
|
|
354
|
-
News: this.deps.News,
|
|
355
|
-
EndpointApi: this.deps.EndpointApi
|
|
356
|
-
})
|
|
392
|
+
const rawOrganizationsList = arrayObjetOrganizations.results.map(
|
|
393
|
+
(d) => this.linkEntity?.(d.collection, d) ?? d
|
|
357
394
|
);
|
|
358
395
|
|
|
359
396
|
return {
|
|
@@ -361,26 +398,6 @@ export class User {
|
|
|
361
398
|
results: rawOrganizationsList
|
|
362
399
|
};
|
|
363
400
|
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* Crée une instance d'organisation et récupère son profil si nécessaire.
|
|
367
|
-
*
|
|
368
|
-
* @param {Object} organizationData - Les données nécessaires pour initialiser l'organisation.
|
|
369
|
-
* @returns {Promise<Organization>} Une promesse qui résout l'objet Organisation créé.
|
|
370
|
-
* @throws {Error} Si une erreur se produit lors de la création de l'organisation.
|
|
371
|
-
*/
|
|
372
|
-
async organization(organizationData = {}, ) {
|
|
373
|
-
try {
|
|
374
|
-
const organization = new this.deps.Organization(this, organizationData, { User, Project: this.deps.Project, News: this.deps.News, EndpointApi : this.deps.EndpointApi });
|
|
375
|
-
if (organizationData.id || organizationData.slug) {
|
|
376
|
-
await organization.get();
|
|
377
|
-
}
|
|
378
|
-
return organization;
|
|
379
|
-
} catch (error) {
|
|
380
|
-
this.apiClient._logger.error(`[Api.${this.__entityTag}.organization] Erreur lors de la création d'une instance organization :`, error.message);
|
|
381
|
-
throw error;
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
401
|
|
|
385
402
|
/**
|
|
386
403
|
* Récupérer les projets d'un utilisateur : Récupère la liste des projets auxquels l'utilisateur contribue.
|
|
@@ -409,13 +426,9 @@ export class User {
|
|
|
409
426
|
if (!Array.isArray(arrayObjetProjects.results)) {
|
|
410
427
|
throw new ApiResponseError("Erreur lors de la récupération des projets.", 500, arrayObjetProjects.results);
|
|
411
428
|
}
|
|
412
|
-
|
|
413
|
-
const rawProjectsList = arrayObjetProjects.results.map(
|
|
414
|
-
this.
|
|
415
|
-
User,
|
|
416
|
-
News: this.deps.News,
|
|
417
|
-
EndpointApi: this.deps.EndpointApi
|
|
418
|
-
})
|
|
429
|
+
|
|
430
|
+
const rawProjectsList = arrayObjetProjects.results.map(
|
|
431
|
+
(d) => this.linkEntity?.(d.collection, d) ?? d
|
|
419
432
|
);
|
|
420
433
|
|
|
421
434
|
return {
|
|
@@ -423,25 +436,39 @@ export class User {
|
|
|
423
436
|
results: rawProjectsList
|
|
424
437
|
};
|
|
425
438
|
}
|
|
426
|
-
|
|
439
|
+
|
|
427
440
|
/**
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
* @param {Object} projectData - Les données nécessaires pour initialiser le projet.
|
|
431
|
-
* @returns {Promise<Project>} Une promesse qui résout l'objet Projet créé.
|
|
432
|
-
* @throws {Error} Si une erreur se produit lors de la création du projet.
|
|
441
|
+
* Récupérer les POIs
|
|
442
|
+
* Constant : GET_POIS_NO_ADMIN / GET_POIS_ADMIN
|
|
433
443
|
*/
|
|
434
|
-
async
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
+
async getPois(data = {}) {
|
|
445
|
+
delete data?.pathParams;
|
|
446
|
+
|
|
447
|
+
const fetchFn = this.isMe
|
|
448
|
+
? () => this.callIsMe(() => this.endpointApi.getPoisAdmin(data))
|
|
449
|
+
: () => this.endpointApi.getPoisNoAdmin(data);
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
if (!this.isMe && !data.filters) {
|
|
453
|
+
data.filters = {
|
|
454
|
+
[`parent.${this.id}`]: { "$exists": true },
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const arrayObjetPois = await fetchFn();
|
|
459
|
+
if (!Array.isArray(arrayObjetPois.results)) {
|
|
460
|
+
throw new ApiResponseError("Erreur lors de la récupération des POIs.", 500, arrayObjetPois.results);
|
|
444
461
|
}
|
|
462
|
+
|
|
463
|
+
// lier les entités au objets
|
|
464
|
+
const rawPoisList = arrayObjetPois.results.map(
|
|
465
|
+
(d) => this.linkEntity?.(d.collection, d) ?? d
|
|
466
|
+
);
|
|
467
|
+
|
|
468
|
+
return {
|
|
469
|
+
count: arrayObjetPois.count?.poi ?? 0,
|
|
470
|
+
results: rawPoisList
|
|
471
|
+
};
|
|
445
472
|
}
|
|
446
473
|
|
|
447
474
|
/**
|
|
@@ -460,13 +487,191 @@ export class User {
|
|
|
460
487
|
if(!Array.isArray(arrayObjetNews)){
|
|
461
488
|
throw new ApiResponseError("Erreur lors de la récupération des actualités.", 500, arrayObjetNews);
|
|
462
489
|
}
|
|
463
|
-
|
|
464
|
-
|
|
490
|
+
|
|
491
|
+
const rawNewsList = arrayObjetNews.map(
|
|
492
|
+
(d) => this.linkEntity?.(d.collection, d) ?? d
|
|
465
493
|
);
|
|
466
494
|
|
|
467
495
|
return this._createFilteredProxy(rawNewsList);
|
|
468
496
|
}
|
|
469
497
|
|
|
498
|
+
/**
|
|
499
|
+
* Récupérer les amis administrables : Récupère les amis administrée par l’utilisateur.
|
|
500
|
+
* Constant : GET_FRIENDS_ADMIN
|
|
501
|
+
* question : qui peut voir la liste d'amis, seulement l'utilisateur connecté ? ou tous les utilisateurs connectés ?
|
|
502
|
+
* actuellement, c'est tous les utilisateurs connectés
|
|
503
|
+
*/
|
|
504
|
+
async getFriends(data = {}) {
|
|
505
|
+
delete data?.pathParams;
|
|
506
|
+
|
|
507
|
+
if (!this.isMe){
|
|
508
|
+
// is not me add id
|
|
509
|
+
data.pathParams = { id: this.id };
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
const arrayObjetFriends = await this.endpointApi.getFriendsAdmin(data);
|
|
513
|
+
if(!Array.isArray(arrayObjetFriends.results)){
|
|
514
|
+
throw new ApiResponseError("Erreur lors de la récupération des amis administrables.", 500, arrayObjetFriends);
|
|
515
|
+
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
const rawFriendsList = arrayObjetFriends.results.map(
|
|
519
|
+
(d) => this.linkEntity?.(d.collection, d) ?? d
|
|
520
|
+
);
|
|
521
|
+
|
|
522
|
+
return {
|
|
523
|
+
count: arrayObjetFriends?.count?.citoyens ?? 0,
|
|
524
|
+
results: rawFriendsList
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Récupérer les suivis
|
|
530
|
+
* Constant : GET_SUBSCRIPTIONS / GET_SUBSCRIPTIONS_ADMIN
|
|
531
|
+
*/
|
|
532
|
+
async getSubscriptions(data = {}) {
|
|
533
|
+
delete data?.pathParams;
|
|
534
|
+
|
|
535
|
+
const fetchFn = this.isMe
|
|
536
|
+
? () => this.callIsMe(() => this.endpointApi.getSubscriptionsAdmin(data))
|
|
537
|
+
: () => this.endpointApi.getSubscriptions(data);
|
|
538
|
+
|
|
539
|
+
if (!this.isMe && !data.filters) {
|
|
540
|
+
data.filters = {
|
|
541
|
+
[`links.followers.${this.id}`]: { "$exists": true },
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const arrayObjetSubscriptions = await fetchFn();
|
|
546
|
+
if (!Array.isArray(arrayObjetSubscriptions.results)) {
|
|
547
|
+
throw new ApiResponseError("Erreur lors de la récupération des abonnements.", 500, arrayObjetSubscriptions.results);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// lier les entités au objets
|
|
551
|
+
const rawSubscriptionsList = arrayObjetSubscriptions.results.map(
|
|
552
|
+
(d) => this.linkEntity?.(d.collection, d) ?? d
|
|
553
|
+
);
|
|
554
|
+
|
|
555
|
+
return {
|
|
556
|
+
count: arrayObjetSubscriptions.count,
|
|
557
|
+
results: rawSubscriptionsList
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Récupérer les abonnés
|
|
563
|
+
* Constant : GET_SUBSCRIBERS
|
|
564
|
+
*/
|
|
565
|
+
async getSubscribers(data = {}) {
|
|
566
|
+
delete data?.pathParams;
|
|
567
|
+
|
|
568
|
+
if (!this.isMe && !data.filters) {
|
|
569
|
+
data.filters = {
|
|
570
|
+
[`links.follows.${this.id}`]: { "$exists": true },
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
const arrayObjetSubscribers = await this.endpointApi.getSubscribers(data);
|
|
575
|
+
if (!Array.isArray(arrayObjetSubscribers.results)) {
|
|
576
|
+
throw new ApiResponseError("Erreur lors de la récupération des abonnés.", 500, arrayObjetSubscribers.results);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// lier les entités au objets
|
|
580
|
+
const rawSubscribersList = arrayObjetSubscribers.results.map(
|
|
581
|
+
(d) => this.linkEntity?.(d.collection, d) ?? d
|
|
582
|
+
);
|
|
583
|
+
|
|
584
|
+
return {
|
|
585
|
+
count: arrayObjetSubscribers.count,
|
|
586
|
+
results: rawSubscribersList
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Obtenir la liste des événements
|
|
592
|
+
* Constant : GET_EVENTS
|
|
593
|
+
* TODO : il n'est pas fait encore pour GET_EVENTS_ADMIN / GET_EVENTS_NO_ADMIN comme les autres dans endpointApi
|
|
594
|
+
*/
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Liste des badges créés par l'utilisateur
|
|
598
|
+
* Constant : GET_BADGES
|
|
599
|
+
*/
|
|
600
|
+
async getBadgesIssuer(data = {}) {
|
|
601
|
+
delete data?.pathParams;
|
|
602
|
+
|
|
603
|
+
data.filters = data.filters || {};
|
|
604
|
+
data.filters["$or"] = {};
|
|
605
|
+
data.filters["$or"][`issuer.${this.id}`] = { "$exists": true };
|
|
606
|
+
|
|
607
|
+
const arrayObjetBadges = await this.endpointApi.getBadges(data);
|
|
608
|
+
if (!Array.isArray(arrayObjetBadges.results)) {
|
|
609
|
+
throw new ApiResponseError("Erreur lors de la récupération des badges.", 500, arrayObjetBadges.results);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// lier les entités au objets
|
|
613
|
+
const rawBadgesList = arrayObjetBadges.results.map(
|
|
614
|
+
(d) => this.linkEntity?.(d.collection, d) ?? d
|
|
615
|
+
);
|
|
616
|
+
|
|
617
|
+
return {
|
|
618
|
+
count: arrayObjetBadges.count?.badges ?? 0,
|
|
619
|
+
results: rawBadgesList
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Liste des badges associés à l'utilisateur
|
|
625
|
+
*
|
|
626
|
+
* TODO : documenté le fonctionnement et sont utilisation avec un exemple
|
|
627
|
+
*/
|
|
628
|
+
async getBadges(filter = {}) {
|
|
629
|
+
/*
|
|
630
|
+
"badges": {
|
|
631
|
+
"627df5663a0fae60e57f4a31": {
|
|
632
|
+
"attenteRecepteur": true,
|
|
633
|
+
"expiredOn": false,
|
|
634
|
+
"isParcours": "false",
|
|
635
|
+
"issuedOn": "2023-10-02T14:00:00.000Z",
|
|
636
|
+
"name": "CODEV",
|
|
637
|
+
"show": "true",
|
|
638
|
+
},
|
|
639
|
+
},
|
|
640
|
+
*/
|
|
641
|
+
|
|
642
|
+
const filteredBadges = await this.linkEntitiesFromServerData("badges", filter);
|
|
643
|
+
// voir si je les met dans objet { count, results }
|
|
644
|
+
return filteredBadges;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Crée une instance d'organisation et récupère son profil si nécessaire.
|
|
649
|
+
*
|
|
650
|
+
* @param {Object} organizationData - Les données nécessaires pour initialiser l'organisation.
|
|
651
|
+
* @returns {Promise<Organization>} Une promesse qui résout l'objet Organisation créé.
|
|
652
|
+
* @throws {Error} Si une erreur se produit lors de la création de l'organisation.
|
|
653
|
+
*/
|
|
654
|
+
async organization(organizationData = {}) {
|
|
655
|
+
if(!this.isMe){
|
|
656
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour créer une organisation.");
|
|
657
|
+
}
|
|
658
|
+
return this.entity("organizations", organizationData);
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* Crée une instance de projet et récupère son profil si nécessaire.
|
|
663
|
+
*
|
|
664
|
+
* @param {Object} projectData - Les données nécessaires pour initialiser le projet.
|
|
665
|
+
* @returns {Promise<Project>} Une promesse qui résout l'objet Projet créé.
|
|
666
|
+
* @throws {Error} Si une erreur se produit lors de la création du projet.
|
|
667
|
+
*/
|
|
668
|
+
async project(projectData = {}) {
|
|
669
|
+
if(!this.isMe){
|
|
670
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour créer un projet.");
|
|
671
|
+
}
|
|
672
|
+
return this.entity("projects", projectData);
|
|
673
|
+
}
|
|
674
|
+
|
|
470
675
|
/**
|
|
471
676
|
* Crée une instance de news et la récupère si nécessaire.
|
|
472
677
|
*
|
|
@@ -474,26 +679,62 @@ export class User {
|
|
|
474
679
|
* @returns {Promise<News>} Une promesse qui résout l'objet News créé.
|
|
475
680
|
* @throws {Error} Si une erreur se produit lors de la création de la news.
|
|
476
681
|
*/
|
|
477
|
-
async news(newsData = {}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
682
|
+
async news(newsData = {}) {
|
|
683
|
+
if(!this.isMe){
|
|
684
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour créer une actualité.");
|
|
685
|
+
}
|
|
686
|
+
return this.entity("news", newsData);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Crée une instance de POI et la récupère si nécessaire.
|
|
691
|
+
*
|
|
692
|
+
* @param {Object} poiData - Les données nécessaires pour initialiser le POI.
|
|
693
|
+
* @returns {Promise<Poi>} Une promesse qui résout l'objet POI créé.
|
|
694
|
+
* @throws {Error} Si une erreur se produit lors de la création du POI.
|
|
695
|
+
*/
|
|
696
|
+
async poi(poiData = {}) {
|
|
697
|
+
if(!this.isMe){
|
|
698
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour créer un POI.");
|
|
699
|
+
}
|
|
700
|
+
return this.entity("poi", poiData);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* Crée une instance d'événement et la récupère si nécessaire.
|
|
705
|
+
*
|
|
706
|
+
* @param {Object} eventData - Les données nécessaires pour initialiser l'événement.
|
|
707
|
+
* @returns {Promise<Event>} Une promesse qui résout l'objet Événement créé.
|
|
708
|
+
* @throws {Error} Si une erreur se produit lors de la création de l'événement.
|
|
709
|
+
*/
|
|
710
|
+
async event(eventData = {}) {
|
|
711
|
+
if(!this.isMe){
|
|
712
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour créer un événement.");
|
|
713
|
+
}
|
|
714
|
+
return this.entity("events", eventData);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* Crée une instance de badge et la récupère si nécessaire.
|
|
719
|
+
*
|
|
720
|
+
* @param {Object} badgeData - Les données nécessaires pour initialiser le badge.
|
|
721
|
+
* @returns {Promise<Badge>} Une promesse qui résout l'objet Badge créé.
|
|
722
|
+
* @throws {Error} Si une erreur se produit lors de la création du badge.
|
|
723
|
+
*/
|
|
724
|
+
async badge(badgeData = {}) {
|
|
725
|
+
if(!this.isMe){
|
|
726
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour créer un badge.");
|
|
487
727
|
}
|
|
728
|
+
return this.entity("badges", badgeData);
|
|
488
729
|
}
|
|
489
730
|
|
|
490
731
|
_updateInitialDraftSnapshot() {
|
|
491
|
-
this
|
|
732
|
+
this._initialDraftData = JSON.parse(JSON.stringify(this._draftData));
|
|
492
733
|
}
|
|
493
734
|
|
|
494
735
|
// TODO: ne fonctionne pas
|
|
495
736
|
hasChanges() {
|
|
496
|
-
return JSON.stringify(this
|
|
737
|
+
return JSON.stringify(this._draftData) !== JSON.stringify(this._initialDraftData);
|
|
497
738
|
}
|
|
498
739
|
|
|
499
740
|
/**
|
package/src/api/UserApi.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
// UserApi.js
|
|
2
2
|
import ApiClient from "../ApiClient.js";
|
|
3
3
|
import { ApiError, ApiResponseError } from "../error.js";
|
|
4
|
+
import { Badge } from "./Badge.js";
|
|
4
5
|
import EndpointApi from "./EndpointApi.js";
|
|
6
|
+
import { Event } from "./Event.js";
|
|
5
7
|
import { News } from "./News.js";
|
|
6
8
|
import { Organization } from "./Organization.js";
|
|
9
|
+
import { Poi } from "./Poi.js";
|
|
7
10
|
import { Project } from "./Project.js";
|
|
8
11
|
import { User } from "./User.js";
|
|
9
12
|
|
|
@@ -34,7 +37,7 @@ export class UserApi {
|
|
|
34
37
|
// Appel à un endpoint d'authentification
|
|
35
38
|
const response = await this.client.callEndpoint("AUTHENTICATE_URL", { email, password });
|
|
36
39
|
// Création d'une instance de LoggedInUser à partir des données reçues
|
|
37
|
-
this.loggedUser = new User(this.client, response.data.user, { EndpointApi, Organization, Project, News });
|
|
40
|
+
this.loggedUser = new User(this.client, response.data.user, { EndpointApi, Organization, Project, Event, Poi, Badge, News });
|
|
38
41
|
return this.loggedUser;
|
|
39
42
|
});
|
|
40
43
|
}
|
|
@@ -44,7 +47,7 @@ export class UserApi {
|
|
|
44
47
|
throw new ApiError("User not connected", 401);
|
|
45
48
|
}
|
|
46
49
|
this.client._logger.info("UserApi", "meIsconnected", this.client.userId);
|
|
47
|
-
this.loggedUser = new User(this.client, { id: this.client.userId }, { EndpointApi, Organization, Project, News });
|
|
50
|
+
this.loggedUser = new User(this.client, { id: this.client.userId }, { EndpointApi, Organization, Project, Event, Poi, Badge, News });
|
|
48
51
|
return this.loggedUser;
|
|
49
52
|
}
|
|
50
53
|
|