@communecter/cocolight-api-client 1.0.114 → 1.0.115

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@communecter/cocolight-api-client",
3
- "version": "1.0.114",
3
+ "version": "1.0.115",
4
4
  "description": "Client Axios simplifié pour l'API cocolight",
5
5
  "repository": {
6
6
  "type": "git",
@@ -3585,6 +3585,73 @@ export class BaseEntity<TServerData = any> {
3585
3585
  return this._submitLinkRequestAdmin();
3586
3586
  }
3587
3587
 
3588
+ /**
3589
+ * Envoie une demande de promotion en tant qu'administrateur pour l'utilisateur connecté.
3590
+ *
3591
+ * L'utilisateur doit déjà être membre de l'entité (organisation, projet, événement).
3592
+ * Cette méthode envoie une demande pour obtenir les droits d'administration.
3593
+ *
3594
+ * @returns - Résultat de l'API.
3595
+ * @throws {ApiError} 401 - Si l'utilisateur n'est pas connecté.
3596
+ * @throws {ApiError} 404 - Si l'entité n'est pas enregistrée.
3597
+ * @throws {ApiError} 400 - Si l'utilisateur n'est pas membre de l'entité.
3598
+ * @throws {ApiError} 400 - Si l'utilisateur est déjà en cours d'invitation admin.
3599
+ * @throws {ApiError} 400 - Si l'utilisateur est déjà administrateur.
3600
+ * @throws {ApiError} 400 - Si le type d'entité ne supporte pas cette opération.
3601
+ */
3602
+ async requestPromoteToAdmin(): Promise<unknown> {
3603
+ if (!this.isMe) {
3604
+ throw new ApiError("Vous devez être connecté pour envoyer une demande de participation.", 401);
3605
+ }
3606
+
3607
+ this._checkLinkableEntity();
3608
+
3609
+ if (!this.id) {
3610
+ throw new ApiError(`${this.constructor.name} non enregistrée.`, 404);
3611
+ }
3612
+
3613
+ if (!this.userId) {
3614
+ throw new ApiError("L'utilisateur connecté n'est pas défini.", 400);
3615
+ }
3616
+
3617
+ const userLink = this._getLinkFromConnectedUser();
3618
+
3619
+ if (!userLink) {
3620
+ throw new ApiError("vous n'êtes pas membre de cette entité.", 400);
3621
+ }
3622
+
3623
+ if (userLink?.isAdmin && (userLink?.isInviting || userLink?.isAdminInviting)) {
3624
+ throw new ApiError("Cet utilisateur est déjà en cours d'invitation en tant qu'admin.", 400);
3625
+ }
3626
+
3627
+ if (userLink?.isAdmin && !userLink?.isInviting && !userLink?.isAdminInviting) {
3628
+ throw new ApiError("Cet utilisateur est déjà admin.", 400);
3629
+ }
3630
+
3631
+ const t = this.getEntityType();
3632
+
3633
+ const expectedTypes = ["organizations", "projects"];
3634
+
3635
+ if (!expectedTypes.includes(t)) {
3636
+ throw new ApiError(`L'entité doit être de type : ${expectedTypes.join(", ")}, reçu : ${t}`, 400);
3637
+ }
3638
+
3639
+ // 2) Narrow de type pour TypeScript
3640
+ const parentType = t as ConnectData["parentType"];
3641
+
3642
+ const data: ConnectData = {
3643
+ childId: this.userId,
3644
+ childType: "citoyens",
3645
+ parentType,
3646
+ parentId: this.id,
3647
+ connectType: "admin"
3648
+ };
3649
+
3650
+ const retour = await this.callIsMe(() => this.endpointApi.connect(data));
3651
+ await this.userContext?.refresh();
3652
+ return retour;
3653
+ }
3654
+
3588
3655
  /**
3589
3656
  * Accepte une invitation à rejoindre l'entité courante.
3590
3657
  * Ne fonctionne que si un lien avec `isInviting` est détecté.
@@ -1205,6 +1205,21 @@ export declare class BaseEntity<TServerData = any> {
1205
1205
  * @throws {ApiError} - Si l'entité ne supporte pas l'action ou si une demande est déjà en cours.
1206
1206
  */
1207
1207
  requestToJoinAdmin(): Promise<unknown>;
1208
+ /**
1209
+ * Envoie une demande de promotion en tant qu'administrateur pour l'utilisateur connecté.
1210
+ *
1211
+ * L'utilisateur doit déjà être membre de l'entité (organisation, projet, événement).
1212
+ * Cette méthode envoie une demande pour obtenir les droits d'administration.
1213
+ *
1214
+ * @returns - Résultat de l'API.
1215
+ * @throws {ApiError} 401 - Si l'utilisateur n'est pas connecté.
1216
+ * @throws {ApiError} 404 - Si l'entité n'est pas enregistrée.
1217
+ * @throws {ApiError} 400 - Si l'utilisateur n'est pas membre de l'entité.
1218
+ * @throws {ApiError} 400 - Si l'utilisateur est déjà en cours d'invitation admin.
1219
+ * @throws {ApiError} 400 - Si l'utilisateur est déjà administrateur.
1220
+ * @throws {ApiError} 400 - Si le type d'entité ne supporte pas cette opération.
1221
+ */
1222
+ requestPromoteToAdmin(): Promise<unknown>;
1208
1223
  /**
1209
1224
  * Accepte une invitation à rejoindre l'entité courante.
1210
1225
  * Ne fonctionne que si un lien avec `isInviting` est détecté.