@communecter/cocolight-api-client 1.0.107 → 1.0.109
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 +1 -1
- package/dist/cocolight-api-client.cjs +1 -1
- package/dist/cocolight-api-client.mjs.js +1 -1
- 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/BaseEntity.ts +191 -31
- package/src/api/Event.ts +5 -2
- package/src/api/Organization.ts +4 -1
- package/src/api/Project.ts +4 -1
- package/src/api/User.ts +19 -4
- package/src/index.ts +4 -2
- package/types/api/BaseEntity.d.ts +85 -10
- package/types/api/Event.d.ts +2 -1
- package/types/api/Organization.d.ts +2 -1
- package/types/api/Project.d.ts +2 -1
- package/types/api/User.d.ts +10 -4
- package/types/index.d.ts +3 -1
package/package.json
CHANGED
package/src/api/BaseEntity.ts
CHANGED
|
@@ -124,6 +124,29 @@ type ReadableWithMeta = import("stream").Readable & { path?: string, mimeType?:
|
|
|
124
124
|
type UploadInput = File | Blob | Buffer | import("stream").Readable;
|
|
125
125
|
type ValidatedUpload = File | Buffer | ReadableWithMeta;
|
|
126
126
|
|
|
127
|
+
// Type pour le curseur de pagination utilisé dans _createPaginatorEngine
|
|
128
|
+
type PaginationCursor = {
|
|
129
|
+
searchType?: string[];
|
|
130
|
+
searchBy?: string;
|
|
131
|
+
countType?: string[];
|
|
132
|
+
ranges?: Record<string, { indexMin: number; indexMax: number }>;
|
|
133
|
+
indexMin?: number;
|
|
134
|
+
indexMax?: number;
|
|
135
|
+
indexStep?: number;
|
|
136
|
+
[key: string]: unknown; // Pour les propriétés additionnelles dynamiques
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* État interne du paginateur, utilisé pour la restauration.
|
|
141
|
+
*/
|
|
142
|
+
export type PaginatorState = {
|
|
143
|
+
cursor: PaginationCursor | null;
|
|
144
|
+
count: number;
|
|
145
|
+
index: number;
|
|
146
|
+
history: PaginationCursor[];
|
|
147
|
+
sizes: number[];
|
|
148
|
+
};
|
|
149
|
+
|
|
127
150
|
// PaginatorPage interface pour les résultats paginés
|
|
128
151
|
export interface PaginatorPage<T> {
|
|
129
152
|
count: {
|
|
@@ -136,6 +159,11 @@ export interface PaginatorPage<T> {
|
|
|
136
159
|
hasPrev: boolean;
|
|
137
160
|
next?: () => Promise<PaginatorPage<T>>;
|
|
138
161
|
prev?: () => Promise<PaginatorPage<T>>;
|
|
162
|
+
// Métadonnées pour la sérialisation/restauration
|
|
163
|
+
_initialData?: Record<string, any>;
|
|
164
|
+
_state?: PaginatorState;
|
|
165
|
+
_entity?: BaseEntity<any>;
|
|
166
|
+
_methodName?: string;
|
|
139
167
|
}
|
|
140
168
|
|
|
141
169
|
/**
|
|
@@ -207,18 +235,6 @@ type JsonSchemaProperty = Record<string, unknown> & {
|
|
|
207
235
|
const?: unknown;
|
|
208
236
|
};
|
|
209
237
|
|
|
210
|
-
// Type pour le curseur de pagination utilisé dans _createPaginatorEngine
|
|
211
|
-
type PaginationCursor = {
|
|
212
|
-
searchType?: string[];
|
|
213
|
-
searchBy?: string;
|
|
214
|
-
countType?: string[];
|
|
215
|
-
ranges?: Record<string, { indexMin: number; indexMax: number }>;
|
|
216
|
-
indexMin?: number;
|
|
217
|
-
indexMax?: number;
|
|
218
|
-
indexStep?: number;
|
|
219
|
-
[key: string]: unknown; // Pour les propriétés additionnelles dynamiques
|
|
220
|
-
};
|
|
221
|
-
|
|
222
238
|
interface FilterValueCombined {
|
|
223
239
|
$in: string[];
|
|
224
240
|
$exists: boolean;
|
|
@@ -742,7 +758,7 @@ export class BaseEntity<TServerData = any> {
|
|
|
742
758
|
...(this.parent.serverData.links && { links: this.parent.serverData.links })
|
|
743
759
|
};
|
|
744
760
|
}
|
|
745
|
-
|
|
761
|
+
|
|
746
762
|
return {
|
|
747
763
|
__entityTag: this.__entityTag,
|
|
748
764
|
__isSerializedEntity: true,
|
|
@@ -912,9 +928,7 @@ export class BaseEntity<TServerData = any> {
|
|
|
912
928
|
}
|
|
913
929
|
const { serverData } = json as { serverData: object };
|
|
914
930
|
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
return instance;
|
|
931
|
+
return this.fromServerData(this._revive(serverData, parent), parent as ApiClient | ParentLike, deps || {});
|
|
918
932
|
}
|
|
919
933
|
|
|
920
934
|
/**
|
|
@@ -3185,12 +3199,17 @@ export class BaseEntity<TServerData = any> {
|
|
|
3185
3199
|
* @param data - Paramètres (partiels) de recherche/pagination.
|
|
3186
3200
|
* @returns - Les données de réponse.
|
|
3187
3201
|
*/
|
|
3188
|
-
async getOrganizations(
|
|
3202
|
+
async getOrganizations(
|
|
3203
|
+
data: Partial<GetOrganizationsAdminData | GetOrganizationsNoAdminData> = {},
|
|
3204
|
+
options?: { restoredState?: PaginatorState }
|
|
3205
|
+
): Promise<PaginatorPage<Organization>> {
|
|
3189
3206
|
data.searchType = this._getDefaultFromEndpoint("GET_ORGANIZATIONS_NO_ADMIN", "searchType") as GetOrganizationsNoAdminData["searchType"];
|
|
3190
3207
|
// data.searchBy = "ALL";
|
|
3191
3208
|
|
|
3192
3209
|
const paginator = this._createPaginatorEngine({
|
|
3193
3210
|
initialData: data,
|
|
3211
|
+
methodName: "getOrganizations",
|
|
3212
|
+
restoredState: options?.restoredState,
|
|
3194
3213
|
finalizer: async (finalData) => {
|
|
3195
3214
|
if(this.isMe){
|
|
3196
3215
|
finalData.pathParams = { type: this.getEntityType(), id: this.id };
|
|
@@ -3226,12 +3245,17 @@ export class BaseEntity<TServerData = any> {
|
|
|
3226
3245
|
* @param data - Paramètres (partiels) de recherche/pagination.
|
|
3227
3246
|
* @returns - Les données de réponse.
|
|
3228
3247
|
*/
|
|
3229
|
-
async getProjects(
|
|
3248
|
+
async getProjects(
|
|
3249
|
+
data: Partial<GetProjectsAdminData | GetProjectsNoAdminData> = {},
|
|
3250
|
+
options?: { restoredState?: PaginatorState }
|
|
3251
|
+
): Promise<PaginatorPage<Project>> {
|
|
3230
3252
|
data.searchType = this._getDefaultFromEndpoint("GET_PROJECTS_ADMIN", "searchType") as GetProjectsAdminData["searchType"];
|
|
3231
3253
|
// data.searchBy = "ALL";
|
|
3232
3254
|
|
|
3233
3255
|
const paginator = this._createPaginatorEngine({
|
|
3234
3256
|
initialData: data,
|
|
3257
|
+
methodName: "getProjects",
|
|
3258
|
+
restoredState: options?.restoredState,
|
|
3235
3259
|
finalizer: async (finalData) => {
|
|
3236
3260
|
if(this.isMe){
|
|
3237
3261
|
finalData.pathParams = { type: this.getEntityType(), id: this.id };
|
|
@@ -3271,10 +3295,15 @@ export class BaseEntity<TServerData = any> {
|
|
|
3271
3295
|
* @param data - Paramètres (partiels) de recherche/pagination.
|
|
3272
3296
|
* @returns - Les données de réponse.
|
|
3273
3297
|
*/
|
|
3274
|
-
async getEvents(
|
|
3298
|
+
async getEvents(
|
|
3299
|
+
data: Partial<GetEventsData> = {},
|
|
3300
|
+
options?: { restoredState?: PaginatorState }
|
|
3301
|
+
): Promise<PaginatorPage<EventEntity>> {
|
|
3275
3302
|
data.searchType = this._getDefaultFromEndpoint("GET_EVENTS", "searchType") as GetEventsData["searchType"];
|
|
3276
3303
|
const paginator = this._createPaginatorEngine({
|
|
3277
3304
|
initialData: data,
|
|
3305
|
+
methodName: "getEvents",
|
|
3306
|
+
restoredState: options?.restoredState,
|
|
3278
3307
|
finalizer: async (finalData) => {
|
|
3279
3308
|
delete finalData?.pathParams;
|
|
3280
3309
|
finalData.filters = {
|
|
@@ -3297,12 +3326,17 @@ export class BaseEntity<TServerData = any> {
|
|
|
3297
3326
|
* @param data - Paramètres (partiels) de recherche/pagination.
|
|
3298
3327
|
* @returns - Les données de réponse.
|
|
3299
3328
|
*/
|
|
3300
|
-
async getPois(
|
|
3329
|
+
async getPois(
|
|
3330
|
+
data: Partial<GetPoisAdminData | GetPoisNoAdminData> = {},
|
|
3331
|
+
options?: { restoredState?: PaginatorState }
|
|
3332
|
+
): Promise<PaginatorPage<Poi>> {
|
|
3301
3333
|
data.searchType = this._getDefaultFromEndpoint("GET_POIS_ADMIN", "searchType") as GetPoisAdminData["searchType"];
|
|
3302
3334
|
// data.searchBy = "ALL";
|
|
3303
3335
|
|
|
3304
3336
|
const paginator = this._createPaginatorEngine({
|
|
3305
3337
|
initialData: data,
|
|
3338
|
+
methodName: "getPois",
|
|
3339
|
+
restoredState: options?.restoredState,
|
|
3306
3340
|
finalizer: async (finalData) => {
|
|
3307
3341
|
if(this.isMe){
|
|
3308
3342
|
finalData.pathParams = { type: this.getEntityType(), id: this.id };
|
|
@@ -3334,12 +3368,17 @@ export class BaseEntity<TServerData = any> {
|
|
|
3334
3368
|
* @param data - Paramètres (partiels) de recherche/pagination.
|
|
3335
3369
|
* @returns - Les données de réponse.
|
|
3336
3370
|
*/
|
|
3337
|
-
async getSubscribers(
|
|
3371
|
+
async getSubscribers(
|
|
3372
|
+
data: Partial<GetSubscribersData> = {},
|
|
3373
|
+
options?: { restoredState?: PaginatorState }
|
|
3374
|
+
): Promise<PaginatorPage<User>> {
|
|
3338
3375
|
data.searchType = this._getDefaultFromEndpoint("GET_SUBSCRIBERS", "searchType") as GetSubscribersData["searchType"];
|
|
3339
3376
|
// data.searchBy = "ALL";
|
|
3340
3377
|
|
|
3341
3378
|
const paginator = this._createPaginatorEngine({
|
|
3342
3379
|
initialData: data,
|
|
3380
|
+
methodName: "getSubscribers",
|
|
3381
|
+
restoredState: options?.restoredState,
|
|
3343
3382
|
finalizer: async (finalData) => {
|
|
3344
3383
|
delete finalData?.pathParams;
|
|
3345
3384
|
|
|
@@ -3362,12 +3401,17 @@ export class BaseEntity<TServerData = any> {
|
|
|
3362
3401
|
* @param data - Paramètres (partiels) de recherche/pagination.
|
|
3363
3402
|
* @returns - Les données de réponse.
|
|
3364
3403
|
*/
|
|
3365
|
-
async getBadgesIssuer(
|
|
3404
|
+
async getBadgesIssuer(
|
|
3405
|
+
data: Partial<GetBadgesData> = {},
|
|
3406
|
+
options?: { restoredState?: PaginatorState }
|
|
3407
|
+
): Promise<PaginatorPage<Badge>> {
|
|
3366
3408
|
data.searchType = this._getDefaultFromEndpoint("GET_BADGES", "searchType") as GetBadgesData["searchType"];
|
|
3367
3409
|
// data.searchBy = "ALL";
|
|
3368
3410
|
|
|
3369
3411
|
const paginator = this._createPaginatorEngine({
|
|
3370
3412
|
initialData: data,
|
|
3413
|
+
methodName: "getBadgesIssuer",
|
|
3414
|
+
restoredState: options?.restoredState,
|
|
3371
3415
|
finalizer: async (finalData) => {
|
|
3372
3416
|
delete finalData?.pathParams;
|
|
3373
3417
|
|
|
@@ -3749,10 +3793,12 @@ export class BaseEntity<TServerData = any> {
|
|
|
3749
3793
|
/**
|
|
3750
3794
|
* Vérifie si l'utilisateur est administrateur de l'entité.
|
|
3751
3795
|
*
|
|
3796
|
+
* @param options - Options de vérification.
|
|
3797
|
+
* @param options.checkHierarchy - Si `true`, vérifie également si l'utilisateur est admin via la hiérarchie parent. Par défaut `false`.
|
|
3752
3798
|
* @returns - `true` si l'utilisateur est administrateur, `false` sinon.
|
|
3753
3799
|
* @throws {ApiError}
|
|
3754
3800
|
*/
|
|
3755
|
-
isAdmin(): boolean {
|
|
3801
|
+
isAdmin(options?: { checkHierarchy?: boolean }): boolean {
|
|
3756
3802
|
this._checkAccess("vérifier l'administrateur.");
|
|
3757
3803
|
this._assertEntityType("organizations", "projects", "events");
|
|
3758
3804
|
|
|
@@ -3762,8 +3808,13 @@ export class BaseEntity<TServerData = any> {
|
|
|
3762
3808
|
return true;
|
|
3763
3809
|
}
|
|
3764
3810
|
|
|
3765
|
-
// 2. Si pas de lien direct, remonter la hiérarchie parent
|
|
3766
|
-
|
|
3811
|
+
// 2. Si pas de lien direct, remonter la hiérarchie parent (si activé)
|
|
3812
|
+
const checkHierarchy = options?.checkHierarchy ?? false;
|
|
3813
|
+
if (checkHierarchy) {
|
|
3814
|
+
return this._isAdminViaHierarchy();
|
|
3815
|
+
}
|
|
3816
|
+
|
|
3817
|
+
return false;
|
|
3767
3818
|
}
|
|
3768
3819
|
|
|
3769
3820
|
/**
|
|
@@ -3917,14 +3968,18 @@ export class BaseEntity<TServerData = any> {
|
|
|
3917
3968
|
/**
|
|
3918
3969
|
* Coeur de pagination stateless et réutilisable.
|
|
3919
3970
|
*/
|
|
3920
|
-
_createPaginatorEngine<TData extends Record<string, any>, TOut>({ initialData, finalizer }: {
|
|
3971
|
+
_createPaginatorEngine<TData extends Record<string, any>, TOut>({ initialData, finalizer, methodName, restoredState }: {
|
|
3921
3972
|
initialData: Partial<TData>,
|
|
3922
|
-
finalizer: (data: TData) => Promise<FinalizerResult<TOut
|
|
3973
|
+
finalizer: (data: TData) => Promise<FinalizerResult<TOut>>,
|
|
3974
|
+
methodName: string,
|
|
3975
|
+
restoredState?: PaginatorState
|
|
3923
3976
|
}): { next: () => Promise<PaginatorPage<TOut>> } {
|
|
3924
3977
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
3925
3978
|
const Entity = this;
|
|
3926
3979
|
|
|
3927
|
-
const state:
|
|
3980
|
+
const state: PaginatorState = restoredState
|
|
3981
|
+
? { ...restoredState }
|
|
3982
|
+
: { cursor: null, count: 0, index: 0, history: [], sizes: [] };
|
|
3928
3983
|
|
|
3929
3984
|
const hasStep = (d: PaginationCursor | null | undefined) => Boolean(d?.indexStep && d.indexStep > 0);
|
|
3930
3985
|
|
|
@@ -4018,7 +4073,12 @@ export class BaseEntity<TServerData = any> {
|
|
|
4018
4073
|
state.cursor = { ...previous };
|
|
4019
4074
|
return getPage(false);
|
|
4020
4075
|
}
|
|
4021
|
-
: undefined
|
|
4076
|
+
: undefined,
|
|
4077
|
+
// Métadonnées pour la restauration
|
|
4078
|
+
_initialData: { ...initialData },
|
|
4079
|
+
_state: state,
|
|
4080
|
+
_entity: Entity,
|
|
4081
|
+
_methodName: methodName
|
|
4022
4082
|
};
|
|
4023
4083
|
}
|
|
4024
4084
|
|
|
@@ -4107,9 +4167,14 @@ export class BaseEntity<TServerData = any> {
|
|
|
4107
4167
|
* console.log(nextPage.pageNumber, nextPage.results.length);
|
|
4108
4168
|
* }
|
|
4109
4169
|
*/
|
|
4110
|
-
async searchCostum(
|
|
4170
|
+
async searchCostum(
|
|
4171
|
+
data: Partial<GlobalAutocompleteCostumData> = {},
|
|
4172
|
+
options?: { restoredState?: PaginatorState }
|
|
4173
|
+
): Promise<PaginatorPage<any>> {
|
|
4111
4174
|
const paginator = this._createPaginatorEngine({
|
|
4112
4175
|
initialData: data,
|
|
4176
|
+
methodName: "searchCostum",
|
|
4177
|
+
restoredState: options?.restoredState,
|
|
4113
4178
|
finalizer: this._withCostumContext(
|
|
4114
4179
|
(finalData: GlobalAutocompleteCostumData) => this.endpointApi.globalAutocompleteCostum(finalData)
|
|
4115
4180
|
),
|
|
@@ -4387,9 +4452,14 @@ export class BaseEntity<TServerData = any> {
|
|
|
4387
4452
|
}
|
|
4388
4453
|
|
|
4389
4454
|
|
|
4390
|
-
async coformAnswersSearch(
|
|
4455
|
+
async coformAnswersSearch(
|
|
4456
|
+
data: Partial<CoformAnswersSearchData> = {},
|
|
4457
|
+
options?: { restoredState?: PaginatorState }
|
|
4458
|
+
): Promise<PaginatorPage<any>> {
|
|
4391
4459
|
const paginator = this._createPaginatorEngine({
|
|
4392
4460
|
initialData: data,
|
|
4461
|
+
methodName: "coformAnswersSearch",
|
|
4462
|
+
restoredState: options?.restoredState,
|
|
4393
4463
|
finalizer: this._withCostumContext(
|
|
4394
4464
|
(finalData: CoformAnswersSearchData) => this.endpointApi.coformAnswersSearch(finalData)
|
|
4395
4465
|
),
|
|
@@ -4397,6 +4467,96 @@ export class BaseEntity<TServerData = any> {
|
|
|
4397
4467
|
return paginator.next() as Promise<PaginatorPage<any>>;
|
|
4398
4468
|
}
|
|
4399
4469
|
|
|
4470
|
+
/**
|
|
4471
|
+
* ───────────────────────────────
|
|
4472
|
+
* Pagination restoration methods
|
|
4473
|
+
* ───────────────────────────────
|
|
4474
|
+
*/
|
|
4475
|
+
|
|
4476
|
+
/**
|
|
4477
|
+
* Restaure une pagination depuis des données JSON sérialisées.
|
|
4478
|
+
* Ne fait PAS d'appel API - utilise les results déjà présents.
|
|
4479
|
+
* Les fonctions next() et prev() font des appels API quand appelées.
|
|
4480
|
+
*
|
|
4481
|
+
* @param paginationJson - Les données JSON sérialisées d'une pagination
|
|
4482
|
+
* @param apiClientOrEntity - ApiClient ou entité parente pour la reconstruction des entités
|
|
4483
|
+
* @returns Une page de pagination hydratée avec next() et prev() fonctionnels
|
|
4484
|
+
*
|
|
4485
|
+
* @example
|
|
4486
|
+
* // Sérialiser une pagination
|
|
4487
|
+
* const firstPage = await user.getPois();
|
|
4488
|
+
* const json = JSON.stringify(firstPage);
|
|
4489
|
+
*
|
|
4490
|
+
* // Restaurer la pagination (sans appel API) - passer l'ApiClient
|
|
4491
|
+
* const restored = BaseEntity.restorePaginationFromJSON(JSON.parse(json), api.getClientInstance());
|
|
4492
|
+
*
|
|
4493
|
+
* // next() fait un appel API pour récupérer la page suivante
|
|
4494
|
+
* const secondPage = await restored.next?.();
|
|
4495
|
+
*/
|
|
4496
|
+
static restorePaginationFromJSON<T>(
|
|
4497
|
+
paginationJson: any,
|
|
4498
|
+
apiClientOrEntity: ApiClient | BaseEntity<any>
|
|
4499
|
+
): PaginatorPage<T> {
|
|
4500
|
+
// 1. Déterminer l'entité parent
|
|
4501
|
+
// Si c'est déjà une entité, l'utiliser directement
|
|
4502
|
+
// Sinon (ApiClient), restaurer depuis le JSON
|
|
4503
|
+
const entity = apiClientOrEntity instanceof BaseEntity
|
|
4504
|
+
? apiClientOrEntity
|
|
4505
|
+
: fromEntityJSON(paginationJson._entity, apiClientOrEntity) as BaseEntity<any>;
|
|
4506
|
+
|
|
4507
|
+
// 2. Restaurer les results (sans appel API)
|
|
4508
|
+
const results = paginationJson.results.map((r: any) =>
|
|
4509
|
+
fromEntityJSON(r, entity)
|
|
4510
|
+
) as T[];
|
|
4511
|
+
|
|
4512
|
+
// 3. Récupérer les métadonnées
|
|
4513
|
+
const methodName = paginationJson._methodName;
|
|
4514
|
+
const initialData = paginationJson._initialData;
|
|
4515
|
+
const savedState: PaginatorState = paginationJson._state;
|
|
4516
|
+
|
|
4517
|
+
// 4. Construire l'objet pagination restauré
|
|
4518
|
+
return {
|
|
4519
|
+
results,
|
|
4520
|
+
count: paginationJson.count,
|
|
4521
|
+
hasNext: paginationJson.hasNext,
|
|
4522
|
+
hasPrev: paginationJson.hasPrev,
|
|
4523
|
+
pageIndex: paginationJson.pageIndex,
|
|
4524
|
+
pageNumber: paginationJson.pageNumber,
|
|
4525
|
+
next: paginationJson.hasNext
|
|
4526
|
+
? async () => {
|
|
4527
|
+
const method = (entity as any)[methodName];
|
|
4528
|
+
if (typeof method !== "function") {
|
|
4529
|
+
throw new Error(`Méthode ${methodName} non trouvée sur l'entité`);
|
|
4530
|
+
}
|
|
4531
|
+
// Appeler la méthode avec restoredState pour recréer le paginateur
|
|
4532
|
+
// puis appeler next() pour obtenir la page suivante
|
|
4533
|
+
const paginator = await method.call(entity, initialData, {
|
|
4534
|
+
restoredState: savedState
|
|
4535
|
+
});
|
|
4536
|
+
return paginator.next?.() ?? paginator;
|
|
4537
|
+
}
|
|
4538
|
+
: undefined,
|
|
4539
|
+
prev: paginationJson.hasPrev
|
|
4540
|
+
? async () => {
|
|
4541
|
+
const method = (entity as any)[methodName];
|
|
4542
|
+
if (typeof method !== "function") {
|
|
4543
|
+
throw new Error(`Méthode ${methodName} non trouvée sur l'entité`);
|
|
4544
|
+
}
|
|
4545
|
+
// Appeler la méthode avec restoredState pour recréer le paginateur
|
|
4546
|
+
// puis appeler prev() pour obtenir la page précédente
|
|
4547
|
+
const paginator = await method.call(entity, initialData, {
|
|
4548
|
+
restoredState: savedState
|
|
4549
|
+
});
|
|
4550
|
+
return paginator.prev?.() ?? paginator;
|
|
4551
|
+
}
|
|
4552
|
+
: undefined,
|
|
4553
|
+
_initialData: initialData,
|
|
4554
|
+
_state: savedState,
|
|
4555
|
+
_entity: entity,
|
|
4556
|
+
_methodName: methodName
|
|
4557
|
+
};
|
|
4558
|
+
}
|
|
4559
|
+
|
|
4400
4560
|
}
|
|
4401
4561
|
|
|
4402
4562
|
export default BaseEntity;
|
package/src/api/Event.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ApiError } from "../error.js";
|
|
2
|
-
import { BaseEntity, PaginatorPage } from "./BaseEntity.js";
|
|
2
|
+
import { BaseEntity, PaginatorPage, PaginatorState } from "./BaseEntity.js";
|
|
3
3
|
import { transformEntityRefs } from "../types/transforms.js";
|
|
4
4
|
|
|
5
5
|
import type { AddEventData, GetAttendeesAdminData, GetAttendeesNoAdminData } from "./EndpointApi.types.js";
|
|
@@ -75,7 +75,7 @@ export class Event extends BaseEntity<EventItemNormalized> {
|
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
override _update = async (payload: Record<string, any>): Promise<boolean> => {
|
|
78
|
-
if(!this.isAdmin()){
|
|
78
|
+
if(!this.isAdmin({ checkHierarchy: true })){
|
|
79
79
|
throw new ApiError("Vous n'avez pas les droits pour modifier cet événement", 403);
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -210,6 +210,7 @@ export class Event extends BaseEntity<EventItemNormalized> {
|
|
|
210
210
|
isAdminPending?: boolean;
|
|
211
211
|
isInviting?: boolean;
|
|
212
212
|
roles?: any[];
|
|
213
|
+
restoredState?: PaginatorState;
|
|
213
214
|
} = {}
|
|
214
215
|
): Promise<PaginatorPage<User>> {
|
|
215
216
|
data.searchType = this._getDefaultFromEndpoint("GET_ATTENDEES_NO_ADMIN", "searchType") as GetAttendeesNoAdminData["searchType"];
|
|
@@ -217,6 +218,8 @@ export class Event extends BaseEntity<EventItemNormalized> {
|
|
|
217
218
|
|
|
218
219
|
const paginator = this._createPaginatorEngine({
|
|
219
220
|
initialData: data,
|
|
221
|
+
methodName: "getAttendees",
|
|
222
|
+
restoredState: options?.restoredState,
|
|
220
223
|
finalizer: async (finalData) => {
|
|
221
224
|
|
|
222
225
|
const { toBeValidated, isAdmin, isInviting, isAdminPending, roles = [] } = options;
|
package/src/api/Organization.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ApiError } from "../error.js";
|
|
|
2
2
|
import { BaseEntity } from "./BaseEntity.js";
|
|
3
3
|
import { createSocialTransform } from "../types/transforms.js";
|
|
4
4
|
|
|
5
|
-
import type { PaginatorPage } from "./BaseEntity.js";
|
|
5
|
+
import type { PaginatorPage, PaginatorState } from "./BaseEntity.js";
|
|
6
6
|
import type {
|
|
7
7
|
AddOrganizationData,
|
|
8
8
|
GetMembersAdminData,
|
|
@@ -320,6 +320,7 @@ export class Organization extends BaseEntity<OrganizationItemNormalized> {
|
|
|
320
320
|
isAdminPending?: boolean;
|
|
321
321
|
isInviting?: boolean;
|
|
322
322
|
roles?: any[];
|
|
323
|
+
restoredState?: PaginatorState;
|
|
323
324
|
} = {}
|
|
324
325
|
): Promise<PaginatorPage<User | Organization>> {
|
|
325
326
|
|
|
@@ -335,6 +336,8 @@ export class Organization extends BaseEntity<OrganizationItemNormalized> {
|
|
|
335
336
|
|
|
336
337
|
const paginator = this._createPaginatorEngine({
|
|
337
338
|
initialData: data,
|
|
339
|
+
methodName: "getMembers",
|
|
340
|
+
restoredState: options?.restoredState,
|
|
338
341
|
finalizer: async (finalData) => {
|
|
339
342
|
|
|
340
343
|
const { toBeValidated, isAdmin, isAdminPending, isInviting, roles = [] } = options;
|
package/src/api/Project.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { BaseEntity } from "./BaseEntity.js";
|
|
|
3
3
|
import { createSocialTransform, transformEntityRefs } from "../types/transforms.js";
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import type { PaginatorPage } from "./BaseEntity.js";
|
|
6
|
+
import type { PaginatorPage, PaginatorState } from "./BaseEntity.js";
|
|
7
7
|
import type { AddProjectData, GetContributorsAdminData, GetContributorsNoAdminData } from "./EndpointApi.types.js";
|
|
8
8
|
import type { Organization } from "./Organization.js";
|
|
9
9
|
import type { User } from "./User.js";
|
|
@@ -235,6 +235,7 @@ export class Project extends BaseEntity<ProjectItemNormalized> {
|
|
|
235
235
|
isAdminPending?: boolean;
|
|
236
236
|
isInviting?: boolean;
|
|
237
237
|
roles?: any[];
|
|
238
|
+
restoredState?: PaginatorState;
|
|
238
239
|
} = {}
|
|
239
240
|
): Promise<PaginatorPage<User | Organization>> {
|
|
240
241
|
data.searchType = this._getDefaultFromEndpoint("GET_CONTRIBUTORS_ADMIN", "searchType") as GetContributorsAdminData["searchType"];
|
|
@@ -242,6 +243,8 @@ export class Project extends BaseEntity<ProjectItemNormalized> {
|
|
|
242
243
|
|
|
243
244
|
const paginator = this._createPaginatorEngine({
|
|
244
245
|
initialData: data,
|
|
246
|
+
methodName: "getContributors",
|
|
247
|
+
restoredState: options?.restoredState,
|
|
245
248
|
finalizer: async (finalData) => {
|
|
246
249
|
|
|
247
250
|
const { toBeValidated, isAdmin, isInviting, isAdminPending, roles = [] } = options;
|
package/src/api/User.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { UserMixin } from "../mixin/UserMixin.js";
|
|
|
4
4
|
import { createSocialTransform } from "../types/transforms.js";
|
|
5
5
|
|
|
6
6
|
import type { Badge } from "./Badge.js";
|
|
7
|
-
import type { PaginatorPage } from "./BaseEntity.js";
|
|
7
|
+
import type { PaginatorPage, PaginatorState } from "./BaseEntity.js";
|
|
8
8
|
import type {
|
|
9
9
|
ConnectData,
|
|
10
10
|
DisconnectData,
|
|
@@ -366,12 +366,17 @@ export class User extends BaseEntity<UserItemNormalized> {
|
|
|
366
366
|
* Récupérer les organisations d'un utilisateur : Récupère la liste des organisations auxquelles l'utilisateur appartient.
|
|
367
367
|
* Constant : GET_ORGANIZATIONS_ADMIN | GET_ORGANIZATIONS_NO_ADMIN
|
|
368
368
|
*/
|
|
369
|
-
override async getOrganizations(
|
|
369
|
+
override async getOrganizations(
|
|
370
|
+
data: Partial<GetOrganizationsAdminData | GetOrganizationsNoAdminData> = {},
|
|
371
|
+
options?: { restoredState?: PaginatorState }
|
|
372
|
+
) {
|
|
370
373
|
data.searchType = this._getDefaultFromEndpoint("GET_ORGANIZATIONS_NO_ADMIN", "searchType") as GetOrganizationsNoAdminData["searchType"];
|
|
371
374
|
// data.searchBy = "ALL";
|
|
372
375
|
|
|
373
376
|
const paginator = this._createPaginatorEngine({
|
|
374
377
|
initialData: data,
|
|
378
|
+
methodName: "getOrganizations",
|
|
379
|
+
restoredState: options?.restoredState,
|
|
375
380
|
finalizer: async (finalData) => {
|
|
376
381
|
delete finalData?.pathParams;
|
|
377
382
|
|
|
@@ -436,12 +441,17 @@ export class User extends BaseEntity<UserItemNormalized> {
|
|
|
436
441
|
* question : qui peut voir la liste d'amis, seulement l'utilisateur connecté ? ou tous les utilisateurs connectés ?
|
|
437
442
|
* actuellement, c'est tous les utilisateurs connectés
|
|
438
443
|
*/
|
|
439
|
-
async getFriends(
|
|
444
|
+
async getFriends(
|
|
445
|
+
data: Partial<GetFriendsAdminData> = {},
|
|
446
|
+
options?: { restoredState?: PaginatorState }
|
|
447
|
+
): Promise<PaginatorPage<User>> {
|
|
440
448
|
data.searchType = this._getDefaultFromEndpoint("GET_FRIENDS_ADMIN", "searchType") as GetFriendsAdminData["searchType"];
|
|
441
449
|
// data.searchBy = "ALL";
|
|
442
450
|
|
|
443
451
|
const paginator = this._createPaginatorEngine({
|
|
444
452
|
initialData: data,
|
|
453
|
+
methodName: "getFriends",
|
|
454
|
+
restoredState: options?.restoredState,
|
|
445
455
|
finalizer: async (finalData) => {
|
|
446
456
|
|
|
447
457
|
delete finalData?.pathParams;
|
|
@@ -462,12 +472,17 @@ export class User extends BaseEntity<UserItemNormalized> {
|
|
|
462
472
|
* Récupérer les suivis
|
|
463
473
|
* Constant : GET_SUBSCRIPTIONS / GET_SUBSCRIPTIONS_ADMIN
|
|
464
474
|
*/
|
|
465
|
-
async getSubscriptions(
|
|
475
|
+
async getSubscriptions(
|
|
476
|
+
data: Partial<GetSubscriptionsAdminData | GetSubscriptionsData> = {},
|
|
477
|
+
options?: { restoredState?: PaginatorState }
|
|
478
|
+
): Promise<PaginatorPage<BaseEntity<any>>> {
|
|
466
479
|
data.searchType = this._getDefaultFromEndpoint("GET_SUBSCRIPTIONS", "searchType") as GetSubscriptionsAdminData["searchType"];
|
|
467
480
|
// data.searchBy = "ALL";
|
|
468
481
|
|
|
469
482
|
const paginator = this._createPaginatorEngine({
|
|
470
483
|
initialData: data,
|
|
484
|
+
methodName: "getSubscriptions",
|
|
485
|
+
restoredState: options?.restoredState,
|
|
471
486
|
finalizer: async (finalData) => {
|
|
472
487
|
|
|
473
488
|
delete finalData?.pathParams;
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BaseEntity } from "./api/BaseEntity.js";
|
|
1
2
|
import { fromEntityJSON } from "./api/EntityRegistry.js";
|
|
2
3
|
import Api from "./Api.js";
|
|
3
4
|
import ApiClient from "./ApiClient.js";
|
|
@@ -31,7 +32,8 @@ const cocolightApiClient = {
|
|
|
31
32
|
MultiServerTokenStorageStrategy
|
|
32
33
|
},
|
|
33
34
|
helper: {
|
|
34
|
-
fromEntityJSON
|
|
35
|
+
fromEntityJSON,
|
|
36
|
+
restorePaginationFromJSON: BaseEntity.restorePaginationFromJSON
|
|
35
37
|
},
|
|
36
38
|
OfflineClientManager
|
|
37
39
|
};
|
|
@@ -90,7 +92,7 @@ export type * from "./api/serverDataType/Answer.js";
|
|
|
90
92
|
export type * from "./api/serverDataType/common.js";
|
|
91
93
|
|
|
92
94
|
// Types utilitaires
|
|
93
|
-
export type { PaginatorPage } from "./api/BaseEntity.js";
|
|
95
|
+
export type { PaginatorPage, PaginatorState } from "./api/BaseEntity.js";
|
|
94
96
|
|
|
95
97
|
// Types de réponses, payloads, entités, et transforms
|
|
96
98
|
export type * from "./types/index.js";
|