@communecter/cocolight-api-client 1.0.18 → 1.0.20
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 +171 -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 +274 -246
- 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
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { ApiError, ApiResponseError } from "../error.js";
|
|
2
|
-
import
|
|
3
|
-
import { MutualEntityMixin } from "../mixin/MutualEntityMixin.js";
|
|
2
|
+
import BaseEntity from "./BaseEntity.js";
|
|
4
3
|
import { UserMixin } from "../mixin/UserMixin.js";
|
|
5
|
-
import { UtilMixin } from "../mixin/UtilMixin.js";
|
|
6
4
|
|
|
7
5
|
// User.js
|
|
8
|
-
export class User {
|
|
9
|
-
#draftData = {};
|
|
10
|
-
#initialDraftData = {};
|
|
11
|
-
#serverData = null;
|
|
6
|
+
export class User extends BaseEntity {
|
|
12
7
|
|
|
13
8
|
static entityType = "citoyens";
|
|
14
9
|
|
|
@@ -30,6 +25,41 @@ export class User {
|
|
|
30
25
|
["PROFIL_IMAGE", "updateImageProfil"]
|
|
31
26
|
]);
|
|
32
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Champs par défaut pour les schemas json ou l'on extrait les fields. (pour les if/else/then)
|
|
30
|
+
*
|
|
31
|
+
* @property {Object} defaultFields - Un objet contenant les propriétés par défaut pour l'entité User.
|
|
32
|
+
*/
|
|
33
|
+
defaultFields = {
|
|
34
|
+
typeElement: this.getEntityType(),
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Champs à supprimer de draft lors de la construction du proxy.
|
|
39
|
+
*
|
|
40
|
+
* @property {Array<string>} removeFields - Un tableau de chaînes représentant les champs à supprimer.
|
|
41
|
+
*/
|
|
42
|
+
removeFields = [
|
|
43
|
+
"typeElement",
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Transformateurs appliqués lors de la lecture du draft.
|
|
48
|
+
*
|
|
49
|
+
* @type {Object<string, function>}
|
|
50
|
+
*/
|
|
51
|
+
transforms = {
|
|
52
|
+
github: (val, full) => full?.socialNetwork?.github,
|
|
53
|
+
gitlab: (val, full) => full?.socialNetwork?.gitlab,
|
|
54
|
+
facebook: (val, full) => full?.socialNetwork?.facebook,
|
|
55
|
+
twitter: (val, full) => full?.socialNetwork?.twitter,
|
|
56
|
+
instagram: (val, full) => full?.socialNetwork?.instagram,
|
|
57
|
+
diaspora: (val, full) => full?.socialNetwork?.diaspora,
|
|
58
|
+
mastodon: (val, full) => full?.socialNetwork?.mastodon,
|
|
59
|
+
telegram: (val, full) => full?.socialNetwork?.telegram,
|
|
60
|
+
signal: (val, full) => full?.socialNetwork?.signal
|
|
61
|
+
};
|
|
62
|
+
|
|
33
63
|
/**
|
|
34
64
|
* Crée une instance de User.
|
|
35
65
|
*
|
|
@@ -41,115 +71,42 @@ export class User {
|
|
|
41
71
|
* @param {function|object} deps.EndpointApi - Classe ou instance de EndpointApi.
|
|
42
72
|
* @param {function} deps.Organization - Classe Organization.
|
|
43
73
|
* @param {function} deps.Project - Classe Project.
|
|
74
|
+
* @param {function} deps.Event - Classe Events.
|
|
75
|
+
* @param {function} deps.Poi - Classe Poi.
|
|
76
|
+
* @param {function} deps.Badge - Classe Badge.
|
|
44
77
|
* @param {function} deps.News - Classe News.
|
|
45
78
|
*
|
|
46
79
|
* @throws {ApiError} - Si des dépendances nécessaires sont manquantes ou invalides.
|
|
47
80
|
*/
|
|
48
81
|
|
|
49
|
-
constructor(
|
|
50
|
-
this.__entityTag = "User";
|
|
51
|
-
|
|
82
|
+
constructor(parent, data = {}, deps = {}) {
|
|
52
83
|
if(!deps.EndpointApi){
|
|
53
84
|
throw new ApiError("EndpointApi class must be injected to avoid circular dependency.");
|
|
54
85
|
}
|
|
55
86
|
if (!data?.id && !data?.slug) {
|
|
56
87
|
throw new ApiError("Vous devez fournir un id ou un slug pour créer un User.");
|
|
57
88
|
}
|
|
58
|
-
|
|
89
|
+
|
|
59
90
|
if (!deps.Organization) throw new ApiError("Organization class must be injected.");
|
|
60
91
|
if (!deps.Project) throw new ApiError("Project class must be injected.");
|
|
92
|
+
if (!deps.Event) throw new ApiError("Event class must be injected.");
|
|
93
|
+
if (!deps.Poi) throw new ApiError("Poi class must be injected.");
|
|
94
|
+
if (!deps.Badge) throw new ApiError("Badge class must be injected.");
|
|
61
95
|
if (!deps.News) throw new ApiError("News class must be injected.");
|
|
96
|
+
|
|
97
|
+
super(parent, data, deps);
|
|
62
98
|
|
|
63
|
-
this.
|
|
64
|
-
|
|
65
|
-
this.deps = deps;
|
|
66
|
-
|
|
67
|
-
// Gérer les deux cas : fonction constructeur ou instance
|
|
68
|
-
if (typeof deps.EndpointApi === "function") {
|
|
69
|
-
this.endpointApi = new deps.EndpointApi(this.apiClient);
|
|
70
|
-
} else if (typeof deps.EndpointApi === "object") {
|
|
71
|
-
this.endpointApi = deps.EndpointApi;
|
|
72
|
-
} else {
|
|
73
|
-
throw new ApiError("deps.EndpointApi doit être une classe ou une instance valide.");
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
this.#serverData = null;
|
|
77
|
-
|
|
78
|
-
const { draft, proxy } = this._buildDraftAndProxy({
|
|
79
|
-
data: { ...data, ...this.defaultFields },
|
|
80
|
-
serverData: this.#serverData,
|
|
81
|
-
constant: User.SCHEMA_CONSTANTS,
|
|
82
|
-
apiClient: this.apiClient,
|
|
83
|
-
transforms: this.transforms,
|
|
84
|
-
removeFields: this.removeFields
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
this.#initialDraftData = JSON.parse(JSON.stringify(draft)); // snapshot propre
|
|
88
|
-
this.#draftData = draft;
|
|
89
|
-
this.data = proxy;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
get id() {
|
|
93
|
-
return this.#draftData.id || null;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
_id(newId) {
|
|
97
|
-
this.#draftData.id = newId;
|
|
99
|
+
// this.__entityTag = "User";
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
get slug() {
|
|
101
|
-
return this
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
get isConnected() {
|
|
105
|
-
return this.apiClient.isConnected;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
_setData(newData) {
|
|
109
|
-
this.#serverData = { ...newData };
|
|
110
|
-
|
|
111
|
-
const { draft, proxy } = this._buildDraftAndProxy({
|
|
112
|
-
data: { ...newData, ...this.defaultFields },
|
|
113
|
-
serverData: this.#serverData,
|
|
114
|
-
constant: User.SCHEMA_CONSTANTS,
|
|
115
|
-
apiClient: this.apiClient,
|
|
116
|
-
transforms: this.transforms,
|
|
117
|
-
removeFields: this.removeFields
|
|
118
|
-
});
|
|
119
|
-
this.#initialDraftData = JSON.parse(JSON.stringify(draft));
|
|
120
|
-
this.#draftData = draft;
|
|
121
|
-
this.data = proxy;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
getEntityType() {
|
|
125
|
-
return User.entityType;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
get userId() {
|
|
129
|
-
return this.apiClient.userId;
|
|
103
|
+
return this._draftData.slug || null;
|
|
130
104
|
}
|
|
131
105
|
|
|
132
106
|
get isMe() {
|
|
133
107
|
return this.isConnected && this.userId === this.id;
|
|
134
108
|
}
|
|
135
109
|
|
|
136
|
-
get draftData() {
|
|
137
|
-
return this.#draftData;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
get initialDraftData() {
|
|
141
|
-
return this.#initialDraftData;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
get serverData() {
|
|
145
|
-
return this.#serverData;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
async refresh() {
|
|
149
|
-
if (!this.id) throw new ApiError("Impossible de rafraîchir sans ID.");
|
|
150
|
-
return this.get();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
110
|
/**
|
|
154
111
|
* Récupère le profil complet de l'utilisateur.
|
|
155
112
|
* Si l'utilisateur est connecté, on appelle le endpoint ME_INFO_URL,
|
|
@@ -195,22 +152,14 @@ export class User {
|
|
|
195
152
|
* @throws {ApiError} - Si l'utilisateur n'est pas autorisé.
|
|
196
153
|
*/
|
|
197
154
|
async save() {
|
|
198
|
-
|
|
199
155
|
if(!this.isMe){
|
|
200
156
|
throw new ApiError("Vous devez être connecté et être l'utilisateur pour sauvegarder.");
|
|
201
157
|
}
|
|
158
|
+
await super.save();
|
|
159
|
+
}
|
|
202
160
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (this.id) {
|
|
206
|
-
const hasChanged = await this._update(payload);
|
|
207
|
-
if (hasChanged) {
|
|
208
|
-
// this._updateInitialDraftSnapshot();
|
|
209
|
-
await this.refresh();
|
|
210
|
-
}
|
|
211
|
-
return this.#serverData;
|
|
212
|
-
}
|
|
213
|
-
|
|
161
|
+
async _add() {
|
|
162
|
+
throw new ApiError("Vous ne pouvez pas ajouter un utilisateur par ce moyen.");
|
|
214
163
|
}
|
|
215
164
|
|
|
216
165
|
/**
|
|
@@ -220,6 +169,10 @@ export class User {
|
|
|
220
169
|
* @returns {Promise<boolean>} - Indique s'il y a eu une modification réelle.
|
|
221
170
|
*/
|
|
222
171
|
async _update(payload){
|
|
172
|
+
if (!this._calledFromSave) {
|
|
173
|
+
throw new Error("utilisation invalide de _update, utilisez save");
|
|
174
|
+
}
|
|
175
|
+
|
|
223
176
|
if(payload.id){
|
|
224
177
|
delete payload.id;
|
|
225
178
|
}
|
|
@@ -244,6 +197,26 @@ export class User {
|
|
|
244
197
|
return hasChanged;
|
|
245
198
|
}
|
|
246
199
|
|
|
200
|
+
static fromServerData(data, parent, deps) {
|
|
201
|
+
const instance = new User(parent.apiClient, data, deps);
|
|
202
|
+
instance._serverData = { ...data };
|
|
203
|
+
// est ce que je besoin de ça si il est contruit dans le constructeur ?
|
|
204
|
+
// il doit y avaoir une raison pour les autres objets
|
|
205
|
+
const { draft, proxy } = instance._buildDraftAndProxy({
|
|
206
|
+
data: { ...data, ...instance.defaultFields },
|
|
207
|
+
serverData: instance._serverData,
|
|
208
|
+
constant: User.SCHEMA_CONSTANTS,
|
|
209
|
+
apiClient: instance.apiClient,
|
|
210
|
+
transforms: instance.transforms,
|
|
211
|
+
removeFields: instance.removeFields
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
instance._draftData = draft;
|
|
215
|
+
instance.data = proxy;
|
|
216
|
+
|
|
217
|
+
return instance;
|
|
218
|
+
}
|
|
219
|
+
|
|
247
220
|
/**
|
|
248
221
|
* Mettre à jour les paramètres utilisateur : Mise à jour des paramètres spécifiques d'un utilisateur.
|
|
249
222
|
* Constant : UPDATE_SETTINGS
|
|
@@ -253,7 +226,10 @@ export class User {
|
|
|
253
226
|
* @returns {Promise<void>} - Résultat de la mise à jour.
|
|
254
227
|
*/
|
|
255
228
|
async updateSettings(data = {}) {
|
|
256
|
-
|
|
229
|
+
if(!this.isMe){
|
|
230
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour mettre à jour les paramètres.");
|
|
231
|
+
}
|
|
232
|
+
await super.updateSettings(data);
|
|
257
233
|
await this.refresh();
|
|
258
234
|
}
|
|
259
235
|
|
|
@@ -262,7 +238,10 @@ export class User {
|
|
|
262
238
|
* Constant : UPDATE_BLOCK_DESCRIPTION
|
|
263
239
|
*/
|
|
264
240
|
async updateDescription(data = {}) {
|
|
265
|
-
|
|
241
|
+
if(!this.isMe){
|
|
242
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour mettre à jour la description.");
|
|
243
|
+
}
|
|
244
|
+
return super.updateDescription(data);
|
|
266
245
|
}
|
|
267
246
|
|
|
268
247
|
/**
|
|
@@ -270,7 +249,10 @@ export class User {
|
|
|
270
249
|
* Constant : UPDATE_BLOCK_INFO
|
|
271
250
|
*/
|
|
272
251
|
async updateInfo(data = {}) {
|
|
273
|
-
|
|
252
|
+
if(!this.isMe){
|
|
253
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour mettre à jour les informations.");
|
|
254
|
+
}
|
|
255
|
+
return super.updateInfo(data);
|
|
274
256
|
}
|
|
275
257
|
|
|
276
258
|
/**
|
|
@@ -278,7 +260,10 @@ export class User {
|
|
|
278
260
|
* Constant : UPDATE_BLOCK_SOCIAL
|
|
279
261
|
*/
|
|
280
262
|
async updateSocial(data = {}) {
|
|
281
|
-
|
|
263
|
+
if(!this.isMe){
|
|
264
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour mettre à jour les réseaux sociaux.");
|
|
265
|
+
}
|
|
266
|
+
return super.updateSocial(data);
|
|
282
267
|
}
|
|
283
268
|
|
|
284
269
|
/**
|
|
@@ -286,7 +271,10 @@ export class User {
|
|
|
286
271
|
* Constant : UPDATE_BLOCK_LOCALITY
|
|
287
272
|
*/
|
|
288
273
|
async updateLocality(data = {}) {
|
|
289
|
-
|
|
274
|
+
if(!this.isMe){
|
|
275
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour mettre à jour la localité.");
|
|
276
|
+
}
|
|
277
|
+
return super.updateLocality(data);
|
|
290
278
|
}
|
|
291
279
|
|
|
292
280
|
/**
|
|
@@ -294,15 +282,10 @@ export class User {
|
|
|
294
282
|
* Constant : UPDATE_BLOCK_SLUG
|
|
295
283
|
*/
|
|
296
284
|
async updateSlug({ slug }) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
} catch (error) {
|
|
300
|
-
if(error instanceof ApiResponseError) {
|
|
301
|
-
throw new ApiResponseError("Erreur lors de la vérification du slug.", error.status, error.data);
|
|
302
|
-
}
|
|
303
|
-
throw error;
|
|
285
|
+
if(!this.isMe){
|
|
286
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour mettre à jour le slug.");
|
|
304
287
|
}
|
|
305
|
-
return
|
|
288
|
+
return super.updateSlug({ slug });
|
|
306
289
|
}
|
|
307
290
|
|
|
308
291
|
/**
|
|
@@ -310,8 +293,10 @@ export class User {
|
|
|
310
293
|
* Constant : PROFIL_IMAGE
|
|
311
294
|
*/
|
|
312
295
|
async updateImageProfil({ profil_avatar: image }) {
|
|
313
|
-
|
|
314
|
-
|
|
296
|
+
if(!this.isMe){
|
|
297
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour mettre à jour l'image de profil.");
|
|
298
|
+
}
|
|
299
|
+
return super.updateImageProfil({ profil_avatar: image });
|
|
315
300
|
}
|
|
316
301
|
|
|
317
302
|
/**
|
|
@@ -346,14 +331,8 @@ export class User {
|
|
|
346
331
|
const totalCount = Object.values(arrayObjetOrganizations.count || {}).reduce((acc, val) => acc + val, 0);
|
|
347
332
|
arrayObjetOrganizations.count.total = totalCount;
|
|
348
333
|
|
|
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
|
-
})
|
|
334
|
+
const rawOrganizationsList = arrayObjetOrganizations.results.map(
|
|
335
|
+
(d) => this.linkEntity?.(d.collection, d) ?? d
|
|
357
336
|
);
|
|
358
337
|
|
|
359
338
|
return {
|
|
@@ -361,110 +340,166 @@ export class User {
|
|
|
361
340
|
results: rawOrganizationsList
|
|
362
341
|
};
|
|
363
342
|
}
|
|
364
|
-
|
|
343
|
+
|
|
365
344
|
/**
|
|
366
|
-
*
|
|
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.
|
|
345
|
+
* Récupérer les projets d'un utilisateur : Récupère la liste des projets auxquels l'utilisateur contribue.
|
|
346
|
+
* Constant : GET_PROJECTS_ADMIN | GET_PROJECTS_NO_ADMIN
|
|
371
347
|
*/
|
|
372
|
-
async
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
348
|
+
async getProjects(data = {}) {
|
|
349
|
+
return super.getProjects(data);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Récupérer les POIs
|
|
354
|
+
* Constant : GET_POIS_NO_ADMIN / GET_POIS_ADMIN
|
|
355
|
+
*/
|
|
356
|
+
async getPois(data = {}) {
|
|
357
|
+
return super.getPois(data);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Récupérer les actualités : Récupère la liste des actualités liées à l'utilisateur.
|
|
362
|
+
* Constant : GET_NEWS
|
|
363
|
+
*/
|
|
364
|
+
async getNews(data = {}) {
|
|
365
|
+
return super.getNews(data);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Récupérer les amis administrables : Récupère les amis administrée par l’utilisateur.
|
|
370
|
+
* Constant : GET_FRIENDS_ADMIN
|
|
371
|
+
* question : qui peut voir la liste d'amis, seulement l'utilisateur connecté ? ou tous les utilisateurs connectés ?
|
|
372
|
+
* actuellement, c'est tous les utilisateurs connectés
|
|
373
|
+
*/
|
|
374
|
+
async getFriends(data = {}) {
|
|
375
|
+
delete data?.pathParams;
|
|
376
|
+
|
|
377
|
+
if (!this.isMe){
|
|
378
|
+
// is not me add id
|
|
379
|
+
data.pathParams = { id: this.id };
|
|
382
380
|
}
|
|
381
|
+
|
|
382
|
+
const arrayObjetFriends = await this.endpointApi.getFriendsAdmin(data);
|
|
383
|
+
if(!Array.isArray(arrayObjetFriends.results)){
|
|
384
|
+
throw new ApiResponseError("Erreur lors de la récupération des amis administrables.", 500, arrayObjetFriends);
|
|
385
|
+
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const rawFriendsList = arrayObjetFriends.results.map(
|
|
389
|
+
(d) => this.linkEntity?.(d.collection, d) ?? d
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
return {
|
|
393
|
+
count: arrayObjetFriends?.count?.citoyens ?? 0,
|
|
394
|
+
results: rawFriendsList
|
|
395
|
+
};
|
|
383
396
|
}
|
|
384
397
|
|
|
385
398
|
/**
|
|
386
|
-
* Récupérer les
|
|
387
|
-
* Constant :
|
|
399
|
+
* Récupérer les suivis
|
|
400
|
+
* Constant : GET_SUBSCRIPTIONS / GET_SUBSCRIPTIONS_ADMIN
|
|
388
401
|
*/
|
|
389
|
-
async
|
|
402
|
+
async getSubscriptions(data = {}) {
|
|
390
403
|
delete data?.pathParams;
|
|
391
404
|
|
|
392
405
|
const fetchFn = this.isMe
|
|
393
|
-
? () => this.callIsMe(() => this.endpointApi.
|
|
394
|
-
: () => this.endpointApi.
|
|
406
|
+
? () => this.callIsMe(() => this.endpointApi.getSubscriptionsAdmin(data))
|
|
407
|
+
: () => this.endpointApi.getSubscriptions(data);
|
|
395
408
|
|
|
396
409
|
if (!this.isMe && !data.filters) {
|
|
397
410
|
data.filters = {
|
|
398
|
-
"$
|
|
399
|
-
[`links.contributors.${this.id}`]: { "$exists": true },
|
|
400
|
-
[`parent.${this.id}`]: { "$exists": true }
|
|
401
|
-
},
|
|
402
|
-
[`links.contributors.${this.id}`]: { "$exists": true }
|
|
403
|
-
// TODO : revoir les filtres pour harmoniser avec orga (schema pris de cocolight)
|
|
411
|
+
[`links.followers.${this.id}`]: { "$exists": true },
|
|
404
412
|
};
|
|
405
413
|
}
|
|
406
414
|
|
|
407
|
-
const
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
throw new ApiResponseError("Erreur lors de la récupération des projets.", 500, arrayObjetProjects.results);
|
|
415
|
+
const arrayObjetSubscriptions = await fetchFn();
|
|
416
|
+
if (!Array.isArray(arrayObjetSubscriptions.results)) {
|
|
417
|
+
throw new ApiResponseError("Erreur lors de la récupération des abonnements.", 500, arrayObjetSubscriptions.results);
|
|
411
418
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
News: this.deps.News,
|
|
417
|
-
EndpointApi: this.deps.EndpointApi
|
|
418
|
-
})
|
|
419
|
+
|
|
420
|
+
// lier les entités au objets
|
|
421
|
+
const rawSubscriptionsList = arrayObjetSubscriptions.results.map(
|
|
422
|
+
(d) => this.linkEntity?.(d.collection, d) ?? d
|
|
419
423
|
);
|
|
420
|
-
|
|
424
|
+
|
|
421
425
|
return {
|
|
422
|
-
count:
|
|
423
|
-
results:
|
|
426
|
+
count: arrayObjetSubscriptions.count,
|
|
427
|
+
results: rawSubscriptionsList
|
|
424
428
|
};
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Récupérer les abonnés
|
|
433
|
+
* Constant : GET_SUBSCRIBERS
|
|
434
|
+
*/
|
|
435
|
+
async getSubscribers(data = {}) {
|
|
436
|
+
return super.getSubscribers(data);
|
|
425
437
|
}
|
|
426
|
-
|
|
438
|
+
|
|
427
439
|
/**
|
|
428
|
-
*
|
|
440
|
+
* Obtenir la liste des événements
|
|
441
|
+
* Constant : GET_EVENTS
|
|
442
|
+
* TODO : il n'est pas fait encore pour GET_EVENTS_ADMIN / GET_EVENTS_NO_ADMIN comme les autres dans endpointApi
|
|
443
|
+
*/
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Liste des badges créés par l'utilisateur
|
|
447
|
+
* Constant : GET_BADGES
|
|
448
|
+
*/
|
|
449
|
+
async getBadgesIssuer(data = {}) {
|
|
450
|
+
return super.getBadgesIssuer(data);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Liste des badges associés à l'utilisateur
|
|
455
|
+
*
|
|
456
|
+
* TODO : documenté le fonctionnement et sont utilisation avec un exemple
|
|
457
|
+
*/
|
|
458
|
+
async getBadges(filter = {}) {
|
|
459
|
+
/*
|
|
460
|
+
"badges": {
|
|
461
|
+
"627df5663a0fae60e57f4a31": {
|
|
462
|
+
"attenteRecepteur": true,
|
|
463
|
+
"expiredOn": false,
|
|
464
|
+
"isParcours": "false",
|
|
465
|
+
"issuedOn": "2023-10-02T14:00:00.000Z",
|
|
466
|
+
"name": "CODEV",
|
|
467
|
+
"show": "true",
|
|
468
|
+
},
|
|
469
|
+
},
|
|
470
|
+
*/
|
|
471
|
+
|
|
472
|
+
const filteredBadges = await this.linkEntitiesFromServerData("badges", filter);
|
|
473
|
+
// voir si je les met dans objet { count, results }
|
|
474
|
+
return filteredBadges;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Crée une instance d'organisation et récupère son profil si nécessaire.
|
|
429
479
|
*
|
|
430
|
-
* @param {Object}
|
|
431
|
-
* @returns {Promise<
|
|
432
|
-
* @throws {Error} Si une erreur se produit lors de la création
|
|
480
|
+
* @param {Object} organizationData - Les données nécessaires pour initialiser l'organisation.
|
|
481
|
+
* @returns {Promise<Organization>} Une promesse qui résout l'objet Organisation créé.
|
|
482
|
+
* @throws {Error} Si une erreur se produit lors de la création de l'organisation.
|
|
433
483
|
*/
|
|
434
|
-
async
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
if (projectData.id || projectData.slug) {
|
|
438
|
-
await project.get();
|
|
439
|
-
}
|
|
440
|
-
return project;
|
|
441
|
-
} catch (error) {
|
|
442
|
-
this.apiClient._logger.error(`[Api.${this.__entityTag}.project] Erreur lors de la création d'une instance project :`, error.message);
|
|
443
|
-
throw error;
|
|
484
|
+
async organization(organizationData = {}) {
|
|
485
|
+
if(!this.isMe){
|
|
486
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour créer une organisation.");
|
|
444
487
|
}
|
|
488
|
+
return super.organization(organizationData);
|
|
445
489
|
}
|
|
446
490
|
|
|
447
491
|
/**
|
|
448
|
-
*
|
|
449
|
-
*
|
|
492
|
+
* Crée une instance de projet et récupère son profil si nécessaire.
|
|
493
|
+
*
|
|
494
|
+
* @param {Object} projectData - Les données nécessaires pour initialiser le projet.
|
|
495
|
+
* @returns {Promise<Project>} Une promesse qui résout l'objet Projet créé.
|
|
496
|
+
* @throws {Error} Si une erreur se produit lors de la création du projet.
|
|
450
497
|
*/
|
|
451
|
-
async
|
|
452
|
-
if
|
|
453
|
-
|
|
454
|
-
}
|
|
455
|
-
if (!this.isMe){
|
|
456
|
-
// is not me add id
|
|
457
|
-
data.pathParams = { id: this.id };
|
|
458
|
-
}
|
|
459
|
-
const arrayObjetNews = await this.endpointApi.getNews(data);
|
|
460
|
-
if(!Array.isArray(arrayObjetNews)){
|
|
461
|
-
throw new ApiResponseError("Erreur lors de la récupération des actualités.", 500, arrayObjetNews);
|
|
498
|
+
async project(projectData = {}) {
|
|
499
|
+
if(!this.isMe){
|
|
500
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour créer un projet.");
|
|
462
501
|
}
|
|
463
|
-
|
|
464
|
-
this.deps.News.fromServerData(newsData, this, { User, EndpointApi: this.deps.EndpointApi })
|
|
465
|
-
);
|
|
466
|
-
|
|
467
|
-
return this._createFilteredProxy(rawNewsList);
|
|
502
|
+
return super.project(projectData);
|
|
468
503
|
}
|
|
469
504
|
|
|
470
505
|
/**
|
|
@@ -474,64 +509,57 @@ export class User {
|
|
|
474
509
|
* @returns {Promise<News>} Une promesse qui résout l'objet News créé.
|
|
475
510
|
* @throws {Error} Si une erreur se produit lors de la création de la news.
|
|
476
511
|
*/
|
|
477
|
-
async news(newsData = {}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
if (newsData.id) {
|
|
481
|
-
await news.get();
|
|
482
|
-
}
|
|
483
|
-
return news;
|
|
484
|
-
} catch (error) {
|
|
485
|
-
this.apiClient._logger.error(`[Api.${this.__entityTag}.news] Erreur lors de la création d'une instance news :`, error.message);
|
|
486
|
-
throw error;
|
|
512
|
+
async news(newsData = {}) {
|
|
513
|
+
if(!this.isMe){
|
|
514
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour créer une actualité.");
|
|
487
515
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
_updateInitialDraftSnapshot() {
|
|
491
|
-
this.#initialDraftData = JSON.parse(JSON.stringify(this.#draftData));
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
// TODO: ne fonctionne pas
|
|
495
|
-
hasChanges() {
|
|
496
|
-
return JSON.stringify(this.#draftData) !== JSON.stringify(this.#initialDraftData);
|
|
516
|
+
return super.news(newsData);
|
|
497
517
|
}
|
|
498
518
|
|
|
499
519
|
/**
|
|
500
|
-
*
|
|
520
|
+
* Crée une instance de POI et la récupère si nécessaire.
|
|
501
521
|
*
|
|
502
|
-
* @
|
|
522
|
+
* @param {Object} poiData - Les données nécessaires pour initialiser le POI.
|
|
523
|
+
* @returns {Promise<Poi>} Une promesse qui résout l'objet POI créé.
|
|
524
|
+
* @throws {Error} Si une erreur se produit lors de la création du POI.
|
|
503
525
|
*/
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
526
|
+
async poi(poiData = {}) {
|
|
527
|
+
if(!this.isMe){
|
|
528
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour créer un POI.");
|
|
529
|
+
}
|
|
530
|
+
return super.poi(poiData);
|
|
531
|
+
}
|
|
507
532
|
|
|
508
533
|
/**
|
|
509
|
-
*
|
|
534
|
+
* Crée une instance d'événement et la récupère si nécessaire.
|
|
510
535
|
*
|
|
511
|
-
* @
|
|
536
|
+
* @param {Object} eventData - Les données nécessaires pour initialiser l'événement.
|
|
537
|
+
* @returns {Promise<Event>} Une promesse qui résout l'objet Événement créé.
|
|
538
|
+
* @throws {Error} Si une erreur se produit lors de la création de l'événement.
|
|
512
539
|
*/
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
540
|
+
async event(eventData = {}) {
|
|
541
|
+
if(!this.isMe){
|
|
542
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour créer un événement.");
|
|
543
|
+
}
|
|
544
|
+
return super.event(eventData);
|
|
545
|
+
}
|
|
546
|
+
|
|
517
547
|
/**
|
|
518
|
-
*
|
|
519
|
-
*
|
|
520
|
-
* @
|
|
548
|
+
* Crée une instance de badge et la récupère si nécessaire.
|
|
549
|
+
*
|
|
550
|
+
* @param {Object} badgeData - Les données nécessaires pour initialiser le badge.
|
|
551
|
+
* @returns {Promise<Badge>} Une promesse qui résout l'objet Badge créé.
|
|
552
|
+
* @throws {Error} Si une erreur se produit lors de la création du badge.
|
|
521
553
|
*/
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
mastodon: (val, full) => full?.socialNetwork?.mastodon,
|
|
530
|
-
telegram: (val, full) => full?.socialNetwork?.telegram,
|
|
531
|
-
signal: (val, full) => full?.socialNetwork?.signal
|
|
532
|
-
};
|
|
554
|
+
async badge(badgeData = {}) {
|
|
555
|
+
if(!this.isMe){
|
|
556
|
+
throw new ApiError("Vous devez être connecté et être l'utilisateur pour créer un badge.");
|
|
557
|
+
}
|
|
558
|
+
return super.badge(badgeData);
|
|
559
|
+
}
|
|
560
|
+
|
|
533
561
|
}
|
|
534
562
|
|
|
535
563
|
// Incorporation des mixins dans User
|
|
536
|
-
Object.assign(User.prototype,
|
|
564
|
+
Object.assign(User.prototype, UserMixin);
|
|
537
565
|
|