@communecter/cocolight-api-client 1.0.29 → 1.0.31

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/src/api/Event.js CHANGED
@@ -4,6 +4,8 @@ import BaseEntity from "./BaseEntity.js";
4
4
  export class Event extends BaseEntity {
5
5
  static entityType = "events";
6
6
 
7
+ static entityTag = "Event";
8
+
7
9
  static SCHEMA_CONSTANTS = [
8
10
  "ADD_EVENT",
9
11
  // "UPDATE_BLOCK_DESCRIPTION",
package/src/api/News.js CHANGED
@@ -4,6 +4,8 @@ import BaseEntity from "./BaseEntity.js";
4
4
  export class News extends BaseEntity {
5
5
  static entityType = "news";
6
6
 
7
+ static entityTag = "News";
8
+
7
9
  static SCHEMA_CONSTANTS = [
8
10
  "ADD_NEWS"
9
11
  ];
@@ -1,9 +1,11 @@
1
- import { ApiError, ApiResponseError } from "../error.js";
1
+ import { ApiError } from "../error.js";
2
2
  import BaseEntity from "./BaseEntity.js";
3
3
 
4
4
  export class Organization extends BaseEntity {
5
5
  static entityType = "organizations";
6
6
 
7
+ static entityTag = "Organization";
8
+
7
9
  static SCHEMA_CONSTANTS = [
8
10
  "ADD_ORGANIZATION",
9
11
  "UPDATE_BLOCK_DESCRIPTION",
@@ -147,6 +149,7 @@ export class Organization extends BaseEntity {
147
149
  * @param {boolean} options.isAdminPending - Indique si l'utilisateur est en attente de validation pour être admin.
148
150
  * @param {boolean} options.isInviting - Indique si l'utilisateur est en attente d'invitation.
149
151
  * @param {Array} options.roles - Liste des rôles à filtrer.
152
+ * @param {boolean} isNext - Indique si c'est une recherche suivante (pagination).
150
153
  * @returns {Promise<Object>} - Un objet contenant le nombre de membres et la liste des membres.
151
154
  * @throws {ApiResponseError} - Si une erreur se produit lors de la récupération des contributeurs.
152
155
  *
@@ -177,38 +180,32 @@ export class Organization extends BaseEntity {
177
180
  *
178
181
  *
179
182
  */
180
- async getMembers(data = {}, options = {}) {
181
- const { toBeValidated, isAdmin, isAdminPending, isInviting, roles = [] } = options;
182
-
183
- if(this.isMe){
184
- data.pathParams = { type: this.getEntityType(), id: this.id };
185
- // data.filters = {
186
- // [`links.memberOf.${this.id}`]: { "$exists": true },
187
- // [`links.memberOf.${this.id}.toBeValidated`]: { "$exists": false },
188
- // [`links.memberOf.${this.id}.isInviting`]: { "$exists": false }
189
- // };
190
- data.filters = this._buildLinkFilters(this.id, { linkType: "memberOf", toBeValidated, isAdmin, isAdminPending, isInviting, roles });
191
- } else {
192
- delete data?.pathParams;
193
- data.filters = this._buildLinkFilters(this.id, { linkType: "memberOf", toBeValidated: "false", isAdmin, isInviting, roles });
194
- }
195
-
196
- const fetchFn = this.isMe
197
- ? () => this.callIsMe(() => this.endpointApi.getMembersAdmin(data))
198
- : () => this.endpointApi.getMembersNoAdmin(data);
183
+ async getMembers(data = {}, options = {}, isNext = false) {
184
+ data.searchType = this._getDefaultFromEndpoint("GET_MEMBERS_ADMIN", "searchType");
185
+ // data.searchBy = "ALL";
186
+ return this._paginateWith(data, isNext, async (finalData) => {
187
+
188
+ const { toBeValidated, isAdmin, isAdminPending, isInviting, roles = [] } = options;
189
+
190
+ if(this.isMe){
191
+ finalData.pathParams = { type: this.getEntityType(), id: this.id };
192
+ // finalData.filters = {
193
+ // [`links.memberOf.${this.id}`]: { "$exists": true },
194
+ // [`links.memberOf.${this.id}.toBeValidated`]: { "$exists": false },
195
+ // [`links.memberOf.${this.id}.isInviting`]: { "$exists": false }
196
+ // };
197
+ finalData.filters = this._buildLinkFilters(this.id, { linkType: "memberOf", toBeValidated, isAdmin, isAdminPending, isInviting, roles });
198
+ } else {
199
+ delete finalData?.pathParams;
200
+ finalData.filters = this._buildLinkFilters(this.id, { linkType: "memberOf", toBeValidated: false, isAdmin, isInviting, roles });
201
+ }
199
202
 
200
- const arrayObjet = await fetchFn();
201
- if (!Array.isArray(arrayObjet.results)) {
202
- throw new ApiResponseError("Erreur lors de la récupération des membres", 500, arrayObjet.results);
203
- }
204
-
205
- // lier les entités au objets
206
- const rawList = this._linkEntities(arrayObjet.results);
203
+ const fetchFn = this.isMe
204
+ ? () => this.callIsMe(() => this.endpointApi.getMembersAdmin(finalData))
205
+ : () => this.endpointApi.getMembersNoAdmin(finalData);
207
206
 
208
- return {
209
- count: arrayObjet.count,
210
- results: rawList
211
- };
207
+ return fetchFn();
208
+ });
212
209
  }
213
210
 
214
211
  /**
@@ -352,4 +349,31 @@ export class Organization extends BaseEntity {
352
349
  return super.unfollow();
353
350
  }
354
351
 
352
+ /**
353
+ * ───────────────────────────────
354
+ * costum
355
+ * ───────────────────────────────
356
+ */
357
+
358
+ /**
359
+ * Récupère le JSON personnalisé de l'organisation.
360
+ *
361
+ * @returns {Promise<Object>} - Le JSON personnalisé de l'organisation.
362
+ * @throws {ApiError} - Si le slug de l'organisation n'est pas défini.
363
+ */
364
+ async getCostumJson() {
365
+ return super.getCostumJson();
366
+ }
367
+
368
+ /**
369
+ * recherche lié à l'organisation
370
+ *
371
+ * @param {Object} data - Les données de recherche.
372
+ * @returns {Promise<Object>} - Résultat de la recherche.
373
+ * @throws {ApiError} - Si le slug ou l'id de l'organisation n'est pas défini.
374
+ */
375
+ async searchCostum(data = {}, isNext = false) {
376
+ return super.searchCostum(data, isNext);
377
+ }
378
+
355
379
  }
package/src/api/Poi.js CHANGED
@@ -4,6 +4,8 @@ import BaseEntity from "./BaseEntity.js";
4
4
  export class Poi extends BaseEntity {
5
5
  static entityType = "poi";
6
6
 
7
+ static entityTag = "Poi";
8
+
7
9
  static SCHEMA_CONSTANTS = [
8
10
  "ADD_POI",
9
11
  "UPDATE_BLOCK_DESCRIPTION",
@@ -1,9 +1,11 @@
1
- import { ApiError, ApiResponseError } from "../error.js";
1
+ import { ApiError } from "../error.js";
2
2
  import BaseEntity from "./BaseEntity.js";
3
3
 
4
4
  export class Project extends BaseEntity {
5
5
  static entityType = "projects";
6
6
 
7
+ static entityTag = "Project";
8
+
7
9
  static SCHEMA_CONSTANTS = [
8
10
  "ADD_PROJECT",
9
11
  "UPDATE_BLOCK_DESCRIPTION",
@@ -167,6 +169,7 @@ export class Project extends BaseEntity {
167
169
  * @param {boolean} options.isAdmin - Indique si l'utilisateur est admin.
168
170
  * @param {boolean} options.isInviting - Indique si l'utilisateur est en attente d'invitation.
169
171
  * @param {Array} options.roles - Liste des rôles à filtrer.
172
+ * @param {boolean} isNext - Indique si c'est une recherche suivante (pagination).
170
173
  * @returns {Promise<Object>} - Un objet contenant le nombre de contributeurs et la liste des contributeurs.
171
174
  * @throws {ApiResponseError} - Si une erreur se produit lors de la récupération des contributeurs.
172
175
  *
@@ -187,39 +190,33 @@ export class Project extends BaseEntity {
187
190
  * const invitingContributors = await project.getContributors({}, { isInviting: true });
188
191
  *
189
192
  */
190
- async getContributors(data = {}, options = {}) {
191
- const { toBeValidated, isAdmin, isInviting, isAdminPending, roles = [] } = options;
192
-
193
- if(this.isMe){
194
- data.pathParams = { type: this.getEntityType(), id: this.id };
195
- // NOTE : dans le schema je crois que si pas de data.filters alors le default ce fait avec data.pathParams
196
- // data.filters = {
197
- // [`links.projects.${this.id}`]: { "$exists": true },
198
- // [`links.projects.${this.id}.toBeValidated`]: { "$exists": false },
199
- // [`links.projects.${this.id}.isInviting`]: { "$exists": false }
200
- // };
201
- data.filters = this._buildLinkFilters(this.id, { linkType: "projects", toBeValidated, isAdmin, isAdminPending, isInviting, roles });
202
- } else {
203
- delete data?.pathParams;
204
- data.filters = this._buildLinkFilters(this.id, { linkType: "projects", toBeValidated: "false", isAdmin, isInviting, roles });
205
- }
206
-
207
- const fetchFn = this.isMe
208
- ? () => this.callIsMe(() => this.endpointApi.getContributorsAdmin(data))
209
- : () => this.endpointApi.getContributorsNoAdmin(data);
193
+ async getContributors(data = {}, options = {}, isNext = false) {
194
+ data.searchType = this._getDefaultFromEndpoint("GET_CONTRIBUTORS_ADMIN", "searchType");
195
+ // data.searchBy = "ALL";
196
+ return this._paginateWith(data, isNext, async (finalData) => {
197
+
198
+ const { toBeValidated, isAdmin, isInviting, isAdminPending, roles = [] } = options;
199
+
200
+ if(this.isMe){
201
+ finalData.pathParams = { type: this.getEntityType(), id: this.id };
202
+ // NOTE : dans le schema je crois que si pas de finalData.filters alors le default ce fait avec finalData.pathParams
203
+ // finalData.filters = {
204
+ // [`links.projects.${this.id}`]: { "$exists": true },
205
+ // [`links.projects.${this.id}.toBeValidated`]: { "$exists": false },
206
+ // [`links.projects.${this.id}.isInviting`]: { "$exists": false }
207
+ // };
208
+ finalData.filters = this._buildLinkFilters(this.id, { linkType: "projects", toBeValidated, isAdmin, isAdminPending, isInviting, roles });
209
+ } else {
210
+ delete finalData?.pathParams;
211
+ finalData.filters = this._buildLinkFilters(this.id, { linkType: "projects", toBeValidated: false, isAdmin, isInviting, roles });
212
+ }
210
213
 
211
- const arrayObjet = await fetchFn();
212
- if (!Array.isArray(arrayObjet.results)) {
213
- throw new ApiResponseError("Erreur lors de la récupération des contributeurs", 500, arrayObjet.results);
214
- }
215
-
216
- // lier les entités au objets
217
- const rawList = this._linkEntities(arrayObjet.results);
214
+ const fetchFn = this.isMe
215
+ ? () => this.callIsMe(() => this.endpointApi.getContributorsAdmin(finalData))
216
+ : () => this.endpointApi.getContributorsNoAdmin(finalData);
218
217
 
219
- return {
220
- count: arrayObjet.count,
221
- results: rawList
222
- };
218
+ return fetchFn();
219
+ });
223
220
  }
224
221
 
225
222
  /**
package/src/api/User.js CHANGED
@@ -7,6 +7,8 @@ export class User extends BaseEntity {
7
7
 
8
8
  static entityType = "citoyens";
9
9
 
10
+ static entityTag = "User";
11
+
10
12
  static SCHEMA_CONSTANTS = [
11
13
  "UPDATE_BLOCK_DESCRIPTION",
12
14
  "UPDATE_BLOCK_INFO",
@@ -71,7 +73,7 @@ export class User extends BaseEntity {
71
73
  if (!data?.id && !data?.slug) {
72
74
  throw new ApiError("Vous devez fournir un id ou un slug pour créer un User.");
73
75
  }
74
-
76
+
75
77
  if (!deps.Organization) throw new ApiError("Organization class must be injected.");
76
78
  if (!deps.Project) throw new ApiError("Project class must be injected.");
77
79
  if (!deps.Event) throw new ApiError("Event class must be injected.");
@@ -189,7 +191,11 @@ export class User extends BaseEntity {
189
191
  }
190
192
 
191
193
  static fromServerData(data, parent, deps) {
192
- return new User(parent.apiClient, data, deps);
194
+ const instance = new User(parent.apiClient, data, deps);
195
+ if (typeof data === "object" || Object.keys(data).length > 0) {
196
+ instance._setData(data);
197
+ }
198
+ return instance;
193
199
  }
194
200
 
195
201
  /**
@@ -278,40 +284,26 @@ export class User extends BaseEntity {
278
284
  * Récupérer les organisations d'un utilisateur : Récupère la liste des organisations auxquelles l'utilisateur appartient.
279
285
  * Constant : GET_ORGANIZATIONS_ADMIN | GET_ORGANIZATIONS_NO_ADMIN
280
286
  */
281
- async getOrganizations(data = {}) {
282
- delete data?.pathParams;
283
-
284
- const fetchFn = this.isMe
285
- ? () => this.callIsMe(() => this.endpointApi.getOrganizationsAdmin(data))
286
- : () => this.endpointApi.getOrganizationsNoAdmin(data);
287
-
288
- if (!this.isMe && !data.filters) {
289
- data.filters = {
290
- [`links.members.${this.id}`]: { "$exists": true },
291
- [`links.members.${this.id}.toBeValidated`]: { "$exists": false },
292
- [`links.members.${this.id}.isInviting`]: { "$exists": false }
293
- };
294
- }
295
-
296
- const arrayObjet = await fetchFn();
297
-
298
- if (!Array.isArray(arrayObjet.results)) {
299
- throw new ApiResponseError("Erreur lors de la récupération des organisations.", 500, arrayObjet.results);
300
- }
301
-
302
- // nettoyage du count
303
- delete arrayObjet?.count?.spam;
304
-
305
- // calcul du total
306
- const totalCount = Object.values(arrayObjet.count || {}).reduce((acc, val) => acc + val, 0);
307
- arrayObjet.count.total = totalCount;
308
-
309
- const rawList = this._linkEntities(arrayObjet.results);
287
+ async getOrganizations(data = {}, isNext = false) {
288
+ data.searchType = this._getDefaultFromEndpoint("GET_ORGANIZATIONS_NO_ADMIN", "searchType");
289
+ // data.searchBy = "ALL";
290
+ return this._paginateWith(data, isNext, async (finalData) => {
291
+ delete finalData?.pathParams;
292
+
293
+ const fetchFn = this.isMe
294
+ ? () => this.callIsMe(() => this.endpointApi.getOrganizationsAdmin(finalData))
295
+ : () => this.endpointApi.getOrganizationsNoAdmin(finalData);
310
296
 
311
- return {
312
- count: arrayObjet.count,
313
- results: rawList
314
- };
297
+ if (!this.isMe && !finalData.filters) {
298
+ finalData.filters = {
299
+ [`links.members.${this.id}`]: { "$exists": true },
300
+ [`links.members.${this.id}.toBeValidated`]: { "$exists": false },
301
+ [`links.members.${this.id}.isInviting`]: { "$exists": false }
302
+ };
303
+ }
304
+
305
+ return fetchFn();
306
+ });
315
307
  }
316
308
 
317
309
  /**
@@ -353,7 +345,7 @@ export class User extends BaseEntity {
353
345
  }
354
346
 
355
347
  const arrayObjet = await this.endpointApi.getFriendsAdmin(data);
356
- if(!Array.isArray(arrayObjet.results)){
348
+ if (!Array.isArray(arrayObjet.results)){
357
349
  throw new ApiResponseError("Erreur lors de la récupération des amis administrables.", 500, arrayObjet);
358
350
 
359
351
  }
@@ -370,32 +362,26 @@ export class User extends BaseEntity {
370
362
  * Récupérer les suivis
371
363
  * Constant : GET_SUBSCRIPTIONS / GET_SUBSCRIPTIONS_ADMIN
372
364
  */
373
- async getSubscriptions(data = {}) {
374
- delete data?.pathParams;
375
-
376
- const fetchFn = this.isMe
377
- ? () => this.callIsMe(() => this.endpointApi.getSubscriptionsAdmin(data))
378
- : () => this.endpointApi.getSubscriptions(data);
365
+ async getSubscriptions(data = {}, isNext = false) {
366
+ data.searchType = this._getDefaultFromEndpoint("GET_SUBSCRIPTIONS", "searchType");
367
+ // data.searchBy = "ALL";
368
+ return this._paginateWith(data, isNext, async (finalData) => {
369
+
370
+ delete finalData?.pathParams;
379
371
 
380
- if (!this.isMe && !data.filters) {
381
- data.filters = {
382
- [`links.followers.${this.id}`]: { "$exists": true },
383
- };
384
- }
372
+ const fetchFn = this.isMe
373
+ ? () => this.callIsMe(() => this.endpointApi.getSubscriptionsAdmin(finalData))
374
+ : () => this.endpointApi.getSubscriptions(finalData);
385
375
 
386
- const arrayObjet = await fetchFn();
387
- if (!Array.isArray(arrayObjet.results)) {
388
- throw new ApiResponseError("Erreur lors de la récupération des abonnements.", 500, arrayObjet.results);
389
- }
390
-
391
- // lier les entités au objets
392
- const rawList = this._linkEntities(arrayObjet.results);
376
+ if (!this.isMe && !finalData.filters) {
377
+ finalData.filters = {
378
+ [`links.followers.${this.id}`]: { "$exists": true },
379
+ };
380
+ }
393
381
 
394
- return {
395
- count: arrayObjet.count,
396
- results: rawList
397
- };
398
- }
382
+ return fetchFn();
383
+ });
384
+ }
399
385
 
400
386
  /**
401
387
  * Récupérer les abonnés