@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/dist/cocolight-api-client.browser.js +3 -3
- package/dist/cocolight-api-client.cjs +1 -1
- package/dist/cocolight-api-client.cjs.LICENSE.txt +5 -0
- package/dist/cocolight-api-client.mjs.js +1 -1
- package/dist/cocolight-api-client.mjs.js.LICENSE.txt +5 -0
- package/dist/cocolight-api-client.vite.mjs.js +1 -1
- package/dist/cocolight-api-client.vite.mjs.js.map +1 -1
- package/package.json +1 -1
- package/src/Api.js +1 -1
- package/src/api/Badge.js +2 -0
- package/src/api/BaseEntity.js +322 -143
- package/src/api/EndpointApi.js +15 -0
- package/src/api/EndpointApi.types.d.ts +626 -93
- package/src/api/Event.js +2 -0
- package/src/api/News.js +2 -0
- package/src/api/Organization.js +55 -31
- package/src/api/Poi.js +2 -0
- package/src/api/Project.js +29 -32
- package/src/api/User.js +45 -59
- package/src/endpoints.module.js +2 -2
package/src/api/Event.js
CHANGED
package/src/api/News.js
CHANGED
package/src/api/Organization.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { ApiError
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
209
|
-
|
|
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
package/src/api/Project.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { ApiError
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
220
|
-
|
|
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
|
-
|
|
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
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
};
|
|
384
|
-
}
|
|
372
|
+
const fetchFn = this.isMe
|
|
373
|
+
? () => this.callIsMe(() => this.endpointApi.getSubscriptionsAdmin(finalData))
|
|
374
|
+
: () => this.endpointApi.getSubscriptions(finalData);
|
|
385
375
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
};
|
|
398
|
-
}
|
|
382
|
+
return fetchFn();
|
|
383
|
+
});
|
|
384
|
+
}
|
|
399
385
|
|
|
400
386
|
/**
|
|
401
387
|
* Récupérer les abonnés
|