@communecter/cocolight-api-client 1.0.58 → 1.0.59
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/User.ts +5 -33
- package/types/api/User.d.ts +3 -1
package/package.json
CHANGED
package/src/api/User.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { ApiError
|
|
1
|
+
import { ApiError } from "../error.js";
|
|
2
2
|
import { BaseEntity } from "./BaseEntity.js";
|
|
3
|
-
import { createFromCollection } from "./EntityRegistry.js";
|
|
4
3
|
import { UserMixin } from "../mixin/UserMixin.js";
|
|
5
4
|
|
|
6
5
|
import type { Badge } from "./Badge.js";
|
|
@@ -19,7 +18,6 @@ import type {
|
|
|
19
18
|
GetFriendsAdminData
|
|
20
19
|
} from "./EndpointApi.types.js";
|
|
21
20
|
import type { Organization } from "./Organization.js";
|
|
22
|
-
import type { GetElementsKeyResponse } from "@/types/api-responses.js";
|
|
23
21
|
import type { EntityTypes } from "@/types/entities.js";
|
|
24
22
|
|
|
25
23
|
type ApiClient = import("../ApiClient.js").default;
|
|
@@ -867,40 +865,14 @@ export class User extends BaseEntity<UserItemNormalized> {
|
|
|
867
865
|
|
|
868
866
|
/**
|
|
869
867
|
* Retourne une entité à partir d'un slug.
|
|
868
|
+
* @param slug - Le slug de l'entité à récupérer.
|
|
869
|
+
* @returns L'entité correspondante au slug.
|
|
870
870
|
*/
|
|
871
|
-
async
|
|
871
|
+
override async entityBySlug(slug: string): Promise<EntityTypes> {
|
|
872
872
|
if(!this.isMe){
|
|
873
873
|
throw new ApiError("Vous devez être connecté et être l'utilisateur pour créer cet entité.", 401);
|
|
874
874
|
}
|
|
875
|
-
|
|
876
|
-
throw new ApiError("slug requis", 400);
|
|
877
|
-
}
|
|
878
|
-
try {
|
|
879
|
-
const data = await this.endpointApi.getElementsKey({
|
|
880
|
-
pathParams:{
|
|
881
|
-
slug: slug
|
|
882
|
-
}
|
|
883
|
-
}) as GetElementsKeyResponse;
|
|
884
|
-
|
|
885
|
-
if(data.contextId && data.contextType) {
|
|
886
|
-
const entity = createFromCollection(data.contextType, this, { id: data.contextId });
|
|
887
|
-
if (!entity) {
|
|
888
|
-
throw new ApiResponseError(`Le type d'entité pour le slug ${slug} n'est pas reconnu`, 200, data as object);
|
|
889
|
-
}
|
|
890
|
-
await entity.get();
|
|
891
|
-
// On sait que c'est l'un des types concrets → on caste
|
|
892
|
-
return entity as EntityTypes;
|
|
893
|
-
} else {
|
|
894
|
-
throw new ApiResponseError(`Le slug ${slug} n'est pas valide`, 200, data as object);
|
|
895
|
-
}
|
|
896
|
-
} catch (error) {
|
|
897
|
-
if(error instanceof ApiResponseError) {
|
|
898
|
-
throw new ApiResponseError(`Impossible de récupérer l'identifiant pour le slug ${slug}`, error.status, error.responseData);
|
|
899
|
-
} else {
|
|
900
|
-
throw error;
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
|
|
875
|
+
return super.entityBySlug(slug);
|
|
904
876
|
}
|
|
905
877
|
}
|
|
906
878
|
|
package/types/api/User.d.ts
CHANGED
|
@@ -331,7 +331,9 @@ export declare class User extends BaseEntity<UserItemNormalized> {
|
|
|
331
331
|
isFollowing(): boolean;
|
|
332
332
|
/**
|
|
333
333
|
* Retourne une entité à partir d'un slug.
|
|
334
|
+
* @param slug - Le slug de l'entité à récupérer.
|
|
335
|
+
* @returns L'entité correspondante au slug.
|
|
334
336
|
*/
|
|
335
|
-
|
|
337
|
+
entityBySlug(slug: string): Promise<EntityTypes>;
|
|
336
338
|
}
|
|
337
339
|
export {};
|