@communecter/cocolight-api-client 1.0.29 → 1.0.30

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