@communecter/cocolight-api-client 1.0.155 → 1.0.156
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/1035.cocolight-api-client.browser.js +1 -1
- package/dist/1035.cocolight-api-client.cjs +1 -1
- package/dist/1483.cocolight-api-client.browser.js +1 -1
- package/dist/1483.cocolight-api-client.cjs +1 -1
- package/dist/1491.cocolight-api-client.browser.js +1 -1
- package/dist/1491.cocolight-api-client.cjs +1 -1
- package/dist/1494.cocolight-api-client.browser.js +1 -1
- package/dist/1494.cocolight-api-client.cjs +1 -1
- package/dist/1641.cocolight-api-client.browser.js +1 -1
- package/dist/1641.cocolight-api-client.cjs +1 -1
- package/dist/1678.cocolight-api-client.browser.js +1 -1
- package/dist/1678.cocolight-api-client.cjs +1 -1
- package/dist/2041.cocolight-api-client.browser.js +1 -1
- package/dist/2041.cocolight-api-client.cjs +1 -1
- package/dist/2302.cocolight-api-client.browser.js +1 -1
- package/dist/2302.cocolight-api-client.cjs +1 -1
- package/dist/2313.cocolight-api-client.browser.js +1 -1
- package/dist/2313.cocolight-api-client.cjs +1 -1
- package/dist/2379.cocolight-api-client.browser.js +1 -1
- package/dist/2379.cocolight-api-client.cjs +1 -1
- package/dist/2439.cocolight-api-client.browser.js +1 -1
- package/dist/2439.cocolight-api-client.cjs +1 -1
- package/dist/2594.cocolight-api-client.browser.js +1 -1
- package/dist/2594.cocolight-api-client.cjs +1 -1
- package/dist/2766.cocolight-api-client.browser.js +1 -1
- package/dist/2766.cocolight-api-client.cjs +1 -1
- package/dist/2812.cocolight-api-client.browser.js +1 -1
- package/dist/2812.cocolight-api-client.cjs +1 -1
- package/dist/2918.cocolight-api-client.browser.js +1 -1
- package/dist/2918.cocolight-api-client.cjs +1 -1
- package/dist/3028.cocolight-api-client.browser.js +1 -1
- package/dist/3028.cocolight-api-client.cjs +1 -1
- package/dist/3330.cocolight-api-client.browser.js +1 -1
- package/dist/3330.cocolight-api-client.cjs +1 -1
- package/dist/3371.cocolight-api-client.browser.js +1 -1
- package/dist/3371.cocolight-api-client.cjs +1 -1
- package/dist/3401.cocolight-api-client.browser.js +1 -1
- package/dist/3401.cocolight-api-client.cjs +1 -1
- package/dist/3516.cocolight-api-client.browser.js +1 -1
- package/dist/3516.cocolight-api-client.cjs +1 -1
- package/dist/3593.cocolight-api-client.browser.js +1 -1
- package/dist/3593.cocolight-api-client.cjs +1 -1
- package/dist/3764.cocolight-api-client.browser.js +1 -1
- package/dist/3764.cocolight-api-client.cjs +1 -1
- package/dist/3873.cocolight-api-client.browser.js +1 -1
- package/dist/3873.cocolight-api-client.cjs +1 -1
- package/dist/3911.cocolight-api-client.browser.js +1 -1
- package/dist/3911.cocolight-api-client.cjs +1 -1
- package/dist/4031.cocolight-api-client.browser.js +1 -1
- package/dist/4031.cocolight-api-client.cjs +1 -1
- package/dist/4152.cocolight-api-client.browser.js +1 -1
- package/dist/4152.cocolight-api-client.cjs +1 -1
- package/dist/4203.cocolight-api-client.browser.js +1 -1
- package/dist/4203.cocolight-api-client.cjs +1 -1
- package/dist/424.cocolight-api-client.browser.js +1 -1
- package/dist/424.cocolight-api-client.cjs +1 -1
- package/dist/435.cocolight-api-client.browser.js +1 -1
- package/dist/435.cocolight-api-client.cjs +1 -1
- package/dist/4402.cocolight-api-client.browser.js +1 -1
- package/dist/4402.cocolight-api-client.cjs +1 -1
- package/dist/4425.cocolight-api-client.browser.js +1 -1
- package/dist/4425.cocolight-api-client.cjs +1 -1
- package/dist/4472.cocolight-api-client.browser.js +1 -1
- package/dist/4472.cocolight-api-client.cjs +1 -1
- package/dist/4914.cocolight-api-client.browser.js +1 -1
- package/dist/4914.cocolight-api-client.cjs +1 -1
- package/dist/4959.cocolight-api-client.browser.js +1 -1
- package/dist/4959.cocolight-api-client.cjs +1 -1
- package/dist/5100.cocolight-api-client.browser.js +1 -1
- package/dist/5100.cocolight-api-client.cjs +1 -1
- package/dist/5111.cocolight-api-client.browser.js +1 -1
- package/dist/5111.cocolight-api-client.cjs +1 -1
- package/dist/5286.cocolight-api-client.browser.js +1 -1
- package/dist/5286.cocolight-api-client.cjs +1 -1
- package/dist/5380.cocolight-api-client.browser.js +1 -1
- package/dist/5380.cocolight-api-client.cjs +1 -1
- package/dist/5383.cocolight-api-client.browser.js +1 -1
- package/dist/5383.cocolight-api-client.cjs +1 -1
- package/dist/5480.cocolight-api-client.browser.js +1 -1
- package/dist/5480.cocolight-api-client.cjs +1 -1
- package/dist/5541.cocolight-api-client.browser.js +1 -1
- package/dist/5541.cocolight-api-client.cjs +1 -1
- package/dist/5839.cocolight-api-client.browser.js +1 -1
- package/dist/5839.cocolight-api-client.cjs +1 -1
- package/dist/5862.cocolight-api-client.browser.js +1 -1
- package/dist/5862.cocolight-api-client.cjs +1 -1
- package/dist/5869.cocolight-api-client.browser.js +1 -1
- package/dist/5869.cocolight-api-client.cjs +1 -1
- package/dist/588.cocolight-api-client.browser.js +1 -1
- package/dist/588.cocolight-api-client.cjs +1 -1
- package/dist/601.cocolight-api-client.browser.js +1 -1
- package/dist/601.cocolight-api-client.cjs +1 -1
- package/dist/6012.cocolight-api-client.browser.js +1 -1
- package/dist/6012.cocolight-api-client.cjs +1 -1
- package/dist/6200.cocolight-api-client.browser.js +1 -1
- package/dist/6200.cocolight-api-client.cjs +1 -1
- package/dist/6369.cocolight-api-client.browser.js +1 -1
- package/dist/6369.cocolight-api-client.cjs +1 -1
- package/dist/7009.cocolight-api-client.browser.js +1 -1
- package/dist/7009.cocolight-api-client.cjs +1 -1
- package/dist/725.cocolight-api-client.browser.js +1 -1
- package/dist/725.cocolight-api-client.cjs +1 -1
- package/dist/7320.cocolight-api-client.browser.js +1 -1
- package/dist/7339.cocolight-api-client.browser.js +1 -1
- package/dist/7339.cocolight-api-client.cjs +1 -1
- package/dist/7398.cocolight-api-client.browser.js +1 -1
- package/dist/7398.cocolight-api-client.cjs +1 -1
- package/dist/7888.cocolight-api-client.browser.js +1 -1
- package/dist/7888.cocolight-api-client.cjs +1 -1
- package/dist/7975.cocolight-api-client.browser.js +1 -1
- package/dist/7975.cocolight-api-client.cjs +1 -1
- package/dist/809.cocolight-api-client.browser.js +1 -1
- package/dist/809.cocolight-api-client.cjs +1 -1
- package/dist/8300.cocolight-api-client.browser.js +1 -1
- package/dist/8300.cocolight-api-client.cjs +1 -1
- package/dist/8317.cocolight-api-client.browser.js +1 -1
- package/dist/8317.cocolight-api-client.cjs +1 -1
- package/dist/8525.cocolight-api-client.browser.js +1 -1
- package/dist/8525.cocolight-api-client.cjs +1 -1
- package/dist/8894.cocolight-api-client.browser.js +1 -1
- package/dist/8894.cocolight-api-client.cjs +1 -1
- package/dist/9301.cocolight-api-client.browser.js +1 -1
- package/dist/9301.cocolight-api-client.cjs +1 -1
- package/dist/9438.cocolight-api-client.browser.js +1 -1
- package/dist/9438.cocolight-api-client.cjs +1 -1
- package/dist/9478.cocolight-api-client.browser.js +1 -1
- package/dist/9478.cocolight-api-client.cjs +1 -1
- package/dist/9568.cocolight-api-client.browser.js +1 -1
- package/dist/9568.cocolight-api-client.cjs +1 -1
- package/dist/cocolight-api-client.browser.js +6 -6
- package/dist/cocolight-api-client.cjs +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 +7 -17
- package/types/Api.d.ts +1 -0
- package/types/ApiClient.d.ts +10 -1
- package/types/api/BaseEntity.d.ts +2 -0
- package/types/utils/OfflineClientManager.d.ts +8 -0
- package/dist/1035.cocolight-api-client.mjs.js +0 -1
- package/dist/1483.cocolight-api-client.mjs.js +0 -1
- package/dist/1491.cocolight-api-client.mjs.js +0 -1
- package/dist/1494.cocolight-api-client.mjs.js +0 -1
- package/dist/1641.cocolight-api-client.mjs.js +0 -1
- package/dist/1678.cocolight-api-client.mjs.js +0 -1
- package/dist/2041.cocolight-api-client.mjs.js +0 -1
- package/dist/2302.cocolight-api-client.mjs.js +0 -1
- package/dist/2313.cocolight-api-client.mjs.js +0 -1
- package/dist/2379.cocolight-api-client.mjs.js +0 -1
- package/dist/2439.cocolight-api-client.mjs.js +0 -1
- package/dist/2594.cocolight-api-client.mjs.js +0 -1
- package/dist/2766.cocolight-api-client.mjs.js +0 -1
- package/dist/2812.cocolight-api-client.mjs.js +0 -1
- package/dist/2918.cocolight-api-client.mjs.js +0 -1
- package/dist/3028.cocolight-api-client.mjs.js +0 -1
- package/dist/3330.cocolight-api-client.mjs.js +0 -1
- package/dist/3371.cocolight-api-client.mjs.js +0 -1
- package/dist/3401.cocolight-api-client.mjs.js +0 -1
- package/dist/3516.cocolight-api-client.mjs.js +0 -1
- package/dist/3593.cocolight-api-client.mjs.js +0 -1
- package/dist/3764.cocolight-api-client.mjs.js +0 -1
- package/dist/3873.cocolight-api-client.mjs.js +0 -1
- package/dist/3911.cocolight-api-client.mjs.js +0 -1
- package/dist/4031.cocolight-api-client.mjs.js +0 -1
- package/dist/4152.cocolight-api-client.mjs.js +0 -1
- package/dist/4203.cocolight-api-client.mjs.js +0 -1
- package/dist/424.cocolight-api-client.mjs.js +0 -1
- package/dist/435.cocolight-api-client.mjs.js +0 -1
- package/dist/4402.cocolight-api-client.mjs.js +0 -1
- package/dist/4425.cocolight-api-client.mjs.js +0 -1
- package/dist/4472.cocolight-api-client.mjs.js +0 -1
- package/dist/4914.cocolight-api-client.mjs.js +0 -1
- package/dist/4959.cocolight-api-client.mjs.js +0 -1
- package/dist/5100.cocolight-api-client.mjs.js +0 -1
- package/dist/5111.cocolight-api-client.mjs.js +0 -1
- package/dist/5286.cocolight-api-client.mjs.js +0 -1
- package/dist/5380.cocolight-api-client.mjs.js +0 -1
- package/dist/5383.cocolight-api-client.mjs.js +0 -1
- package/dist/5480.cocolight-api-client.mjs.js +0 -1
- package/dist/5541.cocolight-api-client.mjs.js +0 -1
- package/dist/5839.cocolight-api-client.mjs.js +0 -1
- package/dist/5862.cocolight-api-client.mjs.js +0 -1
- package/dist/5869.cocolight-api-client.mjs.js +0 -1
- package/dist/588.cocolight-api-client.mjs.js +0 -1
- package/dist/601.cocolight-api-client.mjs.js +0 -1
- package/dist/6012.cocolight-api-client.mjs.js +0 -1
- package/dist/6200.cocolight-api-client.mjs.js +0 -1
- package/dist/6369.cocolight-api-client.mjs.js +0 -1
- package/dist/7009.cocolight-api-client.mjs.js +0 -1
- package/dist/725.cocolight-api-client.mjs.js +0 -1
- package/dist/7339.cocolight-api-client.mjs.js +0 -1
- package/dist/7398.cocolight-api-client.mjs.js +0 -1
- package/dist/7888.cocolight-api-client.mjs.js +0 -1
- package/dist/7975.cocolight-api-client.mjs.js +0 -1
- package/dist/809.cocolight-api-client.mjs.js +0 -1
- package/dist/8300.cocolight-api-client.mjs.js +0 -1
- package/dist/8317.cocolight-api-client.mjs.js +0 -1
- package/dist/8525.cocolight-api-client.mjs.js +0 -1
- package/dist/8894.cocolight-api-client.mjs.js +0 -1
- package/dist/9301.cocolight-api-client.mjs.js +0 -1
- package/dist/9438.cocolight-api-client.mjs.js +0 -1
- package/dist/9478.cocolight-api-client.mjs.js +0 -1
- package/dist/9568.cocolight-api-client.mjs.js +0 -1
- package/dist/cocolight-api-client.mjs.js +0 -1
- package/src/Api.ts +0 -348
- package/src/ApiClient.ts +0 -1994
- package/src/EJSONType.ts +0 -103
- package/src/api/Action.ts +0 -665
- package/src/api/Answer.ts +0 -1392
- package/src/api/Badge.ts +0 -143
- package/src/api/BaseEntity.ts +0 -6384
- package/src/api/Classified.ts +0 -175
- package/src/api/Comment.ts +0 -280
- package/src/api/EndpointApi.ts +0 -2270
- package/src/api/EndpointApi.types.ts +0 -6566
- package/src/api/EntityRegistry.ts +0 -324
- package/src/api/Event.ts +0 -360
- package/src/api/Form.ts +0 -282
- package/src/api/News.ts +0 -547
- package/src/api/Notifications.ts +0 -196
- package/src/api/Organization.ts +0 -771
- package/src/api/Poi.ts +0 -242
- package/src/api/Project.ts +0 -545
- package/src/api/User.ts +0 -1889
- package/src/api/UserApi.ts +0 -192
- package/src/api/serverDataType/Action.ts +0 -177
- package/src/api/serverDataType/Answer.ts +0 -106
- package/src/api/serverDataType/Classified.ts +0 -152
- package/src/api/serverDataType/Comment.ts +0 -88
- package/src/api/serverDataType/Country.ts +0 -1
- package/src/api/serverDataType/Event.ts +0 -112
- package/src/api/serverDataType/Form.ts +0 -157
- package/src/api/serverDataType/News.ts +0 -138
- package/src/api/serverDataType/Notification.ts +0 -81
- package/src/api/serverDataType/Organization.ts +0 -111
- package/src/api/serverDataType/Poi.ts +0 -75
- package/src/api/serverDataType/Project.ts +0 -115
- package/src/api/serverDataType/User.ts +0 -112
- package/src/api/serverDataType/Zone.ts +0 -33
- package/src/api/serverDataType/common.ts +0 -84
- package/src/costum/normalize.ts +0 -7
- package/src/costum/registry.ts +0 -138
- package/src/costum/runtime-map.ts +0 -221
- package/src/costum/runtime.ts +0 -274
- package/src/costum/schemas/CercleTravailleursSociauxLiberauxLaPlumeSociale.ts +0 -19
- package/src/costum/schemas/FabEn.ts +0 -19
- package/src/costum/schemas/LivingLabInnovationSocialeBraspanon.ts +0 -19
- package/src/costum/schemas/alfph.ts +0 -27
- package/src/costum/schemas/campagne.ts +0 -19
- package/src/costum/schemas/chtitube.ts +0 -19
- package/src/costum/schemas/circuitCourt.ts +0 -19
- package/src/costum/schemas/cmcasHauteBretagne.ts +0 -19
- package/src/costum/schemas/coFinancementTierslieux.ts +0 -27
- package/src/costum/schemas/coeurNumerique.ts +0 -19
- package/src/costum/schemas/communLundi.ts +0 -19
- package/src/costum/schemas/cressReunion.ts +0 -35
- package/src/costum/schemas/cressReunionNetwork.ts +0 -35
- package/src/costum/schemas/ctenat.ts +0 -43
- package/src/costum/schemas/cyberReunion.ts +0 -19
- package/src/costum/schemas/ekisphere.ts +0 -35
- package/src/costum/schemas/equipementsSportifs974.ts +0 -19
- package/src/costum/schemas/federationDesCae.ts +0 -19
- package/src/costum/schemas/formationGenerique.ts +0 -35
- package/src/costum/schemas/franceTierslieux.ts +0 -19
- package/src/costum/schemas/hinaura.ts +0 -27
- package/src/costum/schemas/hubmayotte.ts +0 -19
- package/src/costum/schemas/hubnouvellecaledonie.ts +0 -19
- package/src/costum/schemas/hubpolynesiefrancaise.ts +0 -19
- package/src/costum/schemas/hubreunion.ts +0 -19
- package/src/costum/schemas/hubterritoires.ts +0 -19
- package/src/costum/schemas/hubwallisetfutuna.ts +0 -19
- package/src/costum/schemas/hva.ts +0 -27
- package/src/costum/schemas/ibv2.ts +0 -19
- package/src/costum/schemas/institutBleu.ts +0 -19
- package/src/costum/schemas/journalInsoumisChambery.ts +0 -27
- package/src/costum/schemas/kpacite.ts +0 -19
- package/src/costum/schemas/laCompagnieDesTierslieux.ts +0 -43
- package/src/costum/schemas/laMaisonDesFaiseurs.ts +0 -19
- package/src/costum/schemas/laReunionPourUnNumeriqueInclusif.ts +0 -19
- package/src/costum/schemas/laSemaineDesTierslieux.ts +0 -19
- package/src/costum/schemas/labEnCommuns.ts +0 -19
- package/src/costum/schemas/lakou.ts +0 -27
- package/src/costum/schemas/lesCommunsDesTierslieux.ts +0 -19
- package/src/costum/schemas/mayottePourUnNumeriqueInclusif.ts +0 -19
- package/src/costum/schemas/meir.ts +0 -27
- package/src/costum/schemas/navigatorDesTierslieux.ts +0 -19
- package/src/costum/schemas/notragora.ts +0 -27
- package/src/costum/schemas/nouvellecaledoniePourUnNumeriqueInclusif.ts +0 -19
- package/src/costum/schemas/openAtlas.ts +0 -19
- package/src/costum/schemas/polynesieFrancaisePourUnNumeriqueInclusif.ts +0 -19
- package/src/costum/schemas/prdr.ts +0 -19
- package/src/costum/schemas/reseauTierslieux.ts +0 -19
- package/src/costum/schemas/rfflabs.ts +0 -19
- package/src/costum/schemas/ries.ts +0 -19
- package/src/costum/schemas/siteDuPactePourLaTransition.ts +0 -27
- package/src/costum/schemas/sportSanteBienetre.ts +0 -43
- package/src/costum/schemas/suppa.ts +0 -19
- package/src/costum/schemas/terramies.ts +0 -19
- package/src/costum/schemas/testeTplFormation.ts +0 -35
- package/src/costum/schemas/tierslieuxbelgique.ts +0 -19
- package/src/costum/schemas/tierslieuxorg1.ts +0 -35
- package/src/costum/schemas/transiter.ts +0 -35
- package/src/costum/schemas/vhelioPeiTour2025.ts +0 -19
- package/src/costum/schemas/wallisetfutunaPourUnNumeriqueInclusif.ts +0 -19
- package/src/costum/symbol.ts +0 -26
- package/src/costum/types.ts +0 -895
- package/src/endpoints.module.ts +0 -4253
- package/src/error.ts +0 -86
- package/src/forms/entityForm.ts +0 -142
- package/src/index.ts +0 -161
- package/src/mixin/UserMixin.ts +0 -4
- package/src/types/api-responses.ts +0 -217
- package/src/types/entities.ts +0 -58
- package/src/types/error-guards.ts +0 -230
- package/src/types/index.ts +0 -41
- package/src/types/payloads.ts +0 -21
- package/src/types/transforms.ts +0 -119
- package/src/utils/FileOfflineStorageStrategy.node.ts +0 -50
- package/src/utils/FileStorageStrategy.node.ts +0 -63
- package/src/utils/MultiServerFileStorageStrategy.node.ts +0 -67
- package/src/utils/MultiServerTokenStorageStrategy.ts +0 -139
- package/src/utils/OfflineClientManager.ts +0 -216
- package/src/utils/OfflineQueueStorageStrategy.ts +0 -47
- package/src/utils/TokenStorage.ts +0 -77
- package/src/utils/compat.ts +0 -12
- package/src/utils/createDefaultMultiServerTokenStorageStrategy.ts +0 -35
- package/src/utils/createDefaultOfflineStrategy.ts +0 -34
- package/src/utils/createDefaultTokenStorageStrategy.ts +0 -33
- package/src/utils/reactive.ts +0 -243
- package/src/utils/stream-utils.node.ts +0 -12
package/src/api/News.ts
DELETED
|
@@ -1,547 +0,0 @@
|
|
|
1
|
-
import { ApiError, ApiResponseError } from "../error.js";
|
|
2
|
-
import { BaseEntity } from "./BaseEntity.js";
|
|
3
|
-
|
|
4
|
-
import type { Comment } from "./Comment.js";
|
|
5
|
-
import type { AddNewsData, UpdateNewsData, DeleteNewsData, AddImageNewsData, AddFileNewsData, GetCommentsData, AddVoteData, AddReportAbuseData, ShareNewsData, ShowVoteData } from "./EndpointApi.types.js";
|
|
6
|
-
import type { NewsItemNormalized } from "./serverDataType/News.js";
|
|
7
|
-
|
|
8
|
-
export class News extends BaseEntity<NewsItemNormalized> {
|
|
9
|
-
static override entityType = "news";
|
|
10
|
-
|
|
11
|
-
static override entityTag = "News";
|
|
12
|
-
|
|
13
|
-
static override SCHEMA_CONSTANTS: string[] = [
|
|
14
|
-
"ADD_NEWS"
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
static ADD_BLOCKS = new Map([
|
|
18
|
-
["ADD_NEWS", "addNews"]
|
|
19
|
-
] as const);
|
|
20
|
-
|
|
21
|
-
static UPDATE_BLOCKS = new Map([
|
|
22
|
-
["ADD_NEWS", "updateNews"]
|
|
23
|
-
] as const);
|
|
24
|
-
|
|
25
|
-
override defaultFields: Record<string, any> = {};
|
|
26
|
-
|
|
27
|
-
override removeFields: string[] = ["parentId", "parentType"];
|
|
28
|
-
|
|
29
|
-
override transforms: {
|
|
30
|
-
scope: (val: any) => any;
|
|
31
|
-
mentions: (val: any) => any[];
|
|
32
|
-
mediaImg: (val: any) => {
|
|
33
|
-
countImages: number;
|
|
34
|
-
images: string[];
|
|
35
|
-
};
|
|
36
|
-
mediaFile: (val: any) => {
|
|
37
|
-
countFiles: number;
|
|
38
|
-
files: any[];
|
|
39
|
-
};
|
|
40
|
-
} = {
|
|
41
|
-
scope: val => val?.type,
|
|
42
|
-
mentions: val =>
|
|
43
|
-
Array.isArray(val)
|
|
44
|
-
? val.map(m => ({ ...m, count: parseInt(m.count) }))
|
|
45
|
-
: [],
|
|
46
|
-
mediaImg: val => {
|
|
47
|
-
const images = val?.images?.map((img: any) => img.id).filter(Boolean) || [];
|
|
48
|
-
return images.length > 0 ? { countImages: images.length, images } : { countImages: 0, images: [] };
|
|
49
|
-
},
|
|
50
|
-
mediaFile: val => {
|
|
51
|
-
const files = val?.files?.map((f: any) => f.id).filter(Boolean) || [];
|
|
52
|
-
return files.length > 0 ? { countFiles: files.length, files } : { countFiles: 0, files: [] };
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Transforme les champs imbriqués (author, target, sharedBy, etc.) en instances d'entités.
|
|
58
|
-
* @param data - Les données brutes du serveur.
|
|
59
|
-
* @returns Les données transformées.
|
|
60
|
-
* @protected
|
|
61
|
-
*/
|
|
62
|
-
protected override _transformServerData(data: NewsItemNormalized): NewsItemNormalized {
|
|
63
|
-
// Transformer author en instance User/Organization
|
|
64
|
-
if (data.author) {
|
|
65
|
-
data.author = this._linkNestedEntity(data.author);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Transformer target en instance User/Organization/Project
|
|
69
|
-
if (data.target) {
|
|
70
|
-
data.target = this._linkNestedEntity(data.target);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Transformer lastAuthorShare en instance
|
|
74
|
-
if (data.lastAuthorShare) {
|
|
75
|
-
data.lastAuthorShare = this._linkNestedEntity(data.lastAuthorShare);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Transformer le tableau sharedBy
|
|
79
|
-
if (Array.isArray(data.sharedBy)) {
|
|
80
|
-
data.sharedBy = data.sharedBy.map(item => this._linkNestedEntity(item));
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return data;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Récupérer des actualités par IDs : Récupère des actualités à partir d'une liste d'identifiants.
|
|
88
|
-
* Constant : GET_NEWS_BY_ID
|
|
89
|
-
*/
|
|
90
|
-
override async get(): Promise<Record<string, any>> {
|
|
91
|
-
if (!this.id) throw new ApiError("Impossible de rafraîchir sans ID.", 400);
|
|
92
|
-
const id = this.id; // Type narrowing
|
|
93
|
-
|
|
94
|
-
const newsArray = await this.endpointApi.getNewsById({ ids: [id] });
|
|
95
|
-
|
|
96
|
-
if (newsArray && Array.isArray(newsArray) && newsArray.length === 1) {
|
|
97
|
-
const data = newsArray[0];
|
|
98
|
-
this._setData(data, { forceInitialDraftReset: true });
|
|
99
|
-
return this.serverData;
|
|
100
|
-
}
|
|
101
|
-
throw new ApiError(`Aucune actualité trouvée pour l'ID ${this.id}`, 404);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
override _add = async (payload: Record<string, any>): Promise<void> => {
|
|
106
|
-
if (!this._calledFromSave) {
|
|
107
|
-
throw new Error("utilisation invalide de _add, utilisez save");
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// si le texte est vide, on met un espace pour que le champ soit pris en compte car sur le serveur
|
|
111
|
-
// il y a une vérification de la taille du texte je pense
|
|
112
|
-
if(payload.text === ""){
|
|
113
|
-
payload.text = " ";
|
|
114
|
-
}
|
|
115
|
-
if (this.parent) {
|
|
116
|
-
payload.parentId = this.parent.id;
|
|
117
|
-
payload.parentType = this.parent.getEntityType();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// const data = await this.callIsConnected(() => this.endpointApi.addNews(payload));
|
|
121
|
-
// this._draftData.id = data.object.id;
|
|
122
|
-
// // TODO : voir si j'ai ce qui faut dans reponseData de ADD_NEWS pour mettre à jour #serverData
|
|
123
|
-
// // c'est dans reponseData.object
|
|
124
|
-
// // if(data?.object){
|
|
125
|
-
// // this._serverData = { ...data.object };
|
|
126
|
-
// // }
|
|
127
|
-
|
|
128
|
-
for (const [constant, methodName] of Array.from(News.ADD_BLOCKS)) {
|
|
129
|
-
const blockData = this._extractChangedFieldsFromSchema(
|
|
130
|
-
this.apiClient,
|
|
131
|
-
constant,
|
|
132
|
-
{ ...payload, ...this.defaultFields },
|
|
133
|
-
() => {},
|
|
134
|
-
[]
|
|
135
|
-
);
|
|
136
|
-
if (blockData && Object.keys(blockData).length > 0) {
|
|
137
|
-
const data = await this._invokeBlockMethod(News.ADD_BLOCKS, methodName, blockData);
|
|
138
|
-
if (!this.id && data?.object?.id) {
|
|
139
|
-
this._draftData.id = data.object.id;
|
|
140
|
-
// this._serverData = { ...data.object };
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
override _update = async (payload: Record<string, any>): Promise<boolean> => {
|
|
147
|
-
if (!this._calledFromSave) {
|
|
148
|
-
throw new Error("utilisation invalide de _update, utilisez save");
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (payload.id) delete payload.id;
|
|
152
|
-
|
|
153
|
-
// si le texte est vide, on met un espace pour que le champ soit pris en compte car sur le serveur
|
|
154
|
-
// il y a une vérification de la taille du texte je pense
|
|
155
|
-
if(payload?.text === ""){
|
|
156
|
-
payload.text = " ";
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (this.parent) {
|
|
160
|
-
payload.parentId = this.parent.id;
|
|
161
|
-
payload.parentType = this.parent.getEntityType();
|
|
162
|
-
}
|
|
163
|
-
payload.idNews = this.id;
|
|
164
|
-
|
|
165
|
-
let hasChanged = false;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
// il faut que j'ai les ids des images et fichiers avant la mise à jour venant de serverData
|
|
169
|
-
// if (this._serverData?.mediaImg?.images && this._serverData?.mediaImg?.images.length > 0) {
|
|
170
|
-
// imagesIds = this._serverData.mediaImg.images.map((img: any) => img.id);
|
|
171
|
-
// }
|
|
172
|
-
|
|
173
|
-
// if (this._serverData?.mediaFile?.files && this._serverData?.mediaFile?.files.length > 0) {
|
|
174
|
-
// filesIds = this._serverData.mediaFile.files.map((f: any) => f.id);
|
|
175
|
-
// }
|
|
176
|
-
|
|
177
|
-
// comparer avec this._draftData.mediaImg.images pour voir si des images ont été supprimées
|
|
178
|
-
// comparer avec this._draftData.mediaFile.files pour voir si des fichiers ont été supprimés
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
await this.callIsConnected(() => this.endpointApi.updateNews(payload as UpdateNewsData)) as any;
|
|
182
|
-
|
|
183
|
-
// TODO : je voudrais pouvoir comparer les images et fichiers pour supprimer ceux qui ont été enlevés
|
|
184
|
-
// avec deleteDocumentByContext() mais il faut que j'ai les ids des images et fichiers avant la mise à jour
|
|
185
|
-
|
|
186
|
-
hasChanged = true;
|
|
187
|
-
return hasChanged;
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
async addNews(data: Partial<AddNewsData> = {}): Promise<unknown> {
|
|
191
|
-
return this.callIsConnected(() => this.endpointApi.addNews(data as AddNewsData));
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
async updateNews(data: Partial<UpdateNewsData> = {}): Promise<unknown> {
|
|
195
|
-
return this.callIsConnected(() => this.endpointApi.updateNews(data as UpdateNewsData));
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
async addMention({ slug, id }: { slug?: string; id?: string; }): Promise<any[]> {
|
|
199
|
-
try {
|
|
200
|
-
if (!slug && !id) {
|
|
201
|
-
throw new ApiError("Vous devez fournir un slug ou un id pour ajouter une mention.", 400);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const userInstance = await this.entity("citoyens", { id, slug });
|
|
205
|
-
// const userInstance = new this.deps.User(this.apiClient, { id, slug }, { EndpointApi: this.endpointApi });
|
|
206
|
-
const user = userInstance.serverData;
|
|
207
|
-
|
|
208
|
-
if (!this._draftData.mentions) {
|
|
209
|
-
this._draftData.mentions = [];
|
|
210
|
-
}
|
|
211
|
-
// Vérification si la mention existe déjà
|
|
212
|
-
if (this._draftData.mentions.find((mention: any) => mention.id === user.id)) {
|
|
213
|
-
// Si la mention existe déjà, on incrémente le compteur
|
|
214
|
-
this._draftData.mentions = this._draftData.mentions.map((mention: any) => {
|
|
215
|
-
if (mention.id === user.id) {
|
|
216
|
-
mention.count += 1;
|
|
217
|
-
}
|
|
218
|
-
return mention;
|
|
219
|
-
});
|
|
220
|
-
return this._draftData.mentions;
|
|
221
|
-
}
|
|
222
|
-
const mention = { id: user.id, slug: user.slug, type: userInstance.getEntityType(), name: user.name, value: user.name, count: 1 };
|
|
223
|
-
this._draftData.mentions.push(mention);
|
|
224
|
-
return this._draftData.mentions;
|
|
225
|
-
} catch (error) {
|
|
226
|
-
this.apiClient._logger.error("Erreur lors de l'ajout de la mention :", error);
|
|
227
|
-
throw error;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Ajouter une image à une actualité : Ajoute une images à une actualité.
|
|
235
|
-
* Constant : ADD_IMAGE_NEWS
|
|
236
|
-
*/
|
|
237
|
-
async addImage(image: File | Blob | Buffer | import("stream").Readable): Promise<{ id: string; [key: string]: any }> {
|
|
238
|
-
const validatedImage = await this._validateImage(image);
|
|
239
|
-
const data: AddImageNewsData = {
|
|
240
|
-
pathParams: {
|
|
241
|
-
folder: this.parent?.getEntityType() as "citoyens" | "projects" | "organizations",
|
|
242
|
-
ownerId: this.parent?.id as string
|
|
243
|
-
},
|
|
244
|
-
newsImage: validatedImage as any
|
|
245
|
-
};
|
|
246
|
-
const dataImage = await this.callIsConnected(() => this.endpointApi.addImageNews(data)) as { id: string; [key: string]: any };
|
|
247
|
-
if (this._draftData.mediaImg) {
|
|
248
|
-
this._draftData.mediaImg.countImages = this._draftData.mediaImg.countImages + 1;
|
|
249
|
-
this._draftData.mediaImg.images.push(dataImage.id);
|
|
250
|
-
} else {
|
|
251
|
-
this._draftData.mediaImg = { countImages: 1, images: [dataImage.id] };
|
|
252
|
-
}
|
|
253
|
-
return dataImage;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Ajouter un fichier à une actualité : Ajoute un fichier à une actualité.
|
|
258
|
-
* Constant : ADD_FILE_NEWS
|
|
259
|
-
*/
|
|
260
|
-
async addFile(file: File | Blob | Buffer | import("stream").Readable): Promise<unknown> {
|
|
261
|
-
const validatedFile = await this._validateFile(file);
|
|
262
|
-
const data: AddFileNewsData = {
|
|
263
|
-
pathParams: {
|
|
264
|
-
folder: this.parent?.getEntityType() as "citoyens" | "projects" | "organizations",
|
|
265
|
-
ownerId: this.parent?.id as string
|
|
266
|
-
},
|
|
267
|
-
newsFile: validatedFile as any
|
|
268
|
-
};
|
|
269
|
-
const dataFile = await this.callIsConnected(() => this.endpointApi.addFileNews(data)) as { id: string; [key: string]: any };
|
|
270
|
-
if (this._draftData.mediaFile) {
|
|
271
|
-
this._draftData.mediaFile.countFiles = this._draftData.mediaFile.countFiles + 1;
|
|
272
|
-
this._draftData.mediaFile.files.push(dataFile.id);
|
|
273
|
-
} else {
|
|
274
|
-
this._draftData.mediaFile = { countFiles: 1, files: [dataFile.id] };
|
|
275
|
-
}
|
|
276
|
-
return dataFile;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Supprimer une actualité : Supprime une actualité existante.
|
|
283
|
-
* Constant : DELETE_NEWS
|
|
284
|
-
*/
|
|
285
|
-
async delete(): Promise<void> {
|
|
286
|
-
if(!this.id) {
|
|
287
|
-
throw new ApiError("Vous devez fournir un id pour supprimer une news.", 400);
|
|
288
|
-
}
|
|
289
|
-
const data = {
|
|
290
|
-
pathParams: { id: this.id },
|
|
291
|
-
isLive: false // Valeur par défaut, peut être surchargée
|
|
292
|
-
};
|
|
293
|
-
await this.callIsConnected(() => this.endpointApi.deleteNews(data as DeleteNewsData));
|
|
294
|
-
|
|
295
|
-
// Vider les objets réactifs sans casser la réactivité
|
|
296
|
-
Object.keys(this._draftData).forEach(key => delete this._draftData[key]);
|
|
297
|
-
Object.keys(this._serverData).forEach(key => delete (this._serverData as any)[key]);
|
|
298
|
-
|
|
299
|
-
// Marquer comme supprimé
|
|
300
|
-
this._isDeleted = true;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Créer une instance de commentaire pour cette news.
|
|
305
|
-
* @param commentData - Données du commentaire.
|
|
306
|
-
* @returns Instance de Comment.
|
|
307
|
-
*/
|
|
308
|
-
async comment(commentData: Record<string, any> = {}): Promise<Comment> {
|
|
309
|
-
if(!this.isConnected){
|
|
310
|
-
throw new ApiError("Vous devez être connecté.", 401);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
const entity = await this.entity("comments", commentData);
|
|
314
|
-
return entity as Comment;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Récupérer les commentaires : Récupère la liste de commentaires selon plusieurs critères.
|
|
319
|
-
* Constant : GET_COMMENTS
|
|
320
|
-
* @returns - Les données de réponse.
|
|
321
|
-
* @throws {ApiResponseError} - En cas d'erreur détectée dans la réponse.
|
|
322
|
-
* @throws {Error} - En cas d'erreur inattendue.
|
|
323
|
-
*/
|
|
324
|
-
async getComments(): Promise<Comment[]> {
|
|
325
|
-
|
|
326
|
-
if (!this.id) {
|
|
327
|
-
throw new ApiError(`${this.constructor.name} non enregistrée.`, 404);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
const payload: GetCommentsData = {
|
|
331
|
-
pathParams: { type: "news", id: this.id },
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
const arrayObjet = await this.endpointApi.getComments(payload);
|
|
335
|
-
|
|
336
|
-
if(!Array.isArray(arrayObjet)){
|
|
337
|
-
throw new ApiResponseError("Erreur lors de la récupération des commentaires.", 500, arrayObjet as object);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
const rawList = this._linkEntities(arrayObjet);
|
|
341
|
-
|
|
342
|
-
return this._createFilteredProxy(rawList);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Ajoute un vote sur cette news
|
|
347
|
-
*
|
|
348
|
-
* @param status - Statut du vote (ex: 'like', 'dislike', 'love', etc.)
|
|
349
|
-
* @returns Promise contenant la réponse de l'API après l'ajout du vote
|
|
350
|
-
* @throws {ApiError} Si la news n'a pas d'ID (non enregistrée)
|
|
351
|
-
*/
|
|
352
|
-
async addVote(status: string){
|
|
353
|
-
if (!this.id) {
|
|
354
|
-
throw new ApiError(`${this.constructor.name} non enregistrée.`, 404);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
const payload: AddVoteData = {
|
|
358
|
-
collection: "news",
|
|
359
|
-
id: this.id,
|
|
360
|
-
action: "vote",
|
|
361
|
-
details: {
|
|
362
|
-
status
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
return await this.callIsConnected(() => this.endpointApi.addVote(payload));
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* Récupère la liste des votes (like, love, etc.) sur cette news.
|
|
371
|
-
*
|
|
372
|
-
* Wrap de `SHOW_VOTE` avec auto-injection du `type` (`"news"`) et de
|
|
373
|
-
* `this.id` dans `pathParams`. Le retour contient `vote` (votes individuels
|
|
374
|
-
* indexés par userId) et `voteCount` (compteurs par statut).
|
|
375
|
-
*
|
|
376
|
-
* @returns Réponse API : `{ _id, vote, voteCount }` ou variante d'erreur.
|
|
377
|
-
* @throws {ApiError} 404 si la news n'a pas d'id (non enregistrée).
|
|
378
|
-
*
|
|
379
|
-
* @example
|
|
380
|
-
* const votes = await news.getVotes();
|
|
381
|
-
* votes.voteCount?.like; // nombre de likes
|
|
382
|
-
* votes.vote?.[userId]; // vote détaillé d'un user
|
|
383
|
-
*/
|
|
384
|
-
async getVotes(): Promise<unknown> {
|
|
385
|
-
if (!this.id) {
|
|
386
|
-
throw new ApiError(`${this.constructor.name} non enregistrée.`, 404);
|
|
387
|
-
}
|
|
388
|
-
const payload: ShowVoteData = {
|
|
389
|
-
pathParams: { type: "news", id: this.id },
|
|
390
|
-
};
|
|
391
|
-
return this.endpointApi.showVote(payload);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
* Signale un abus sur cette news
|
|
396
|
-
*
|
|
397
|
-
* @param params - Paramètres du signalement
|
|
398
|
-
* @param params.reason - Raison du signalement
|
|
399
|
-
* @param params.comment - Commentaire expliquant le signalement (optionnel)
|
|
400
|
-
* @returns Promise contenant la réponse de l'API après le signalement
|
|
401
|
-
* @throws {ApiError} Si la news n'a pas d'ID (non enregistrée)
|
|
402
|
-
*/
|
|
403
|
-
async addReportAbuse({ reason, comment }: { reason: string, comment?: string}){
|
|
404
|
-
if (!this.id) {
|
|
405
|
-
throw new ApiError(`${this.constructor.name} non enregistrée.`, 404);
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
const payload: AddReportAbuseData = {
|
|
409
|
-
collection: "news",
|
|
410
|
-
id: this.id,
|
|
411
|
-
action: "reportAbuse",
|
|
412
|
-
details: {
|
|
413
|
-
reason,
|
|
414
|
-
comment
|
|
415
|
-
}
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
return await this.callIsConnected(() =>this.endpointApi.addReportAbuse(payload));
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Partage cette news vers une entité (utilisateur, projet ou organisation)
|
|
423
|
-
*
|
|
424
|
-
* @param params - Paramètres de partage
|
|
425
|
-
* @param params.childId - ID de l'entité cible (par défaut: utilisateur connecté)
|
|
426
|
-
* @param params.childType - Type de l'entité cible (par défaut: "citoyens")
|
|
427
|
-
* @param params.comment - Commentaire optionnel accompagnant le partage
|
|
428
|
-
* @returns Promise contenant la réponse de l'API après le partage
|
|
429
|
-
* @throws {ApiError} Si la news n'a pas d'ID (404)
|
|
430
|
-
* @throws {ApiError} Si l'utilisateur n'est pas connecté (400)
|
|
431
|
-
* @throws {ApiError} Si le parent n'est pas défini (400)
|
|
432
|
-
* @throws {ApiError} Si on tente de partager sa propre news à soi-même (400)
|
|
433
|
-
* @throws {ApiError} Si le type cible n'est pas valide (400)
|
|
434
|
-
*/
|
|
435
|
-
async shareNews({ childId, childType, comment }: { childId?: string, childType?: string, comment?: string } = {}){
|
|
436
|
-
// Validations préalables
|
|
437
|
-
if (!this.id) {
|
|
438
|
-
throw new ApiError(`${this.constructor.name} non enregistrée.`, 404);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
if (!this.userId) {
|
|
442
|
-
throw new ApiError("L'utilisateur connecté n'est pas défini.", 400);
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
if(!this.parent?.id){
|
|
446
|
-
throw new ApiError("Le parent doit être défini pour partager une news", 400);
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
// Déterminer la cible du partage (par défaut: l'utilisateur connecté)
|
|
450
|
-
const targetId = childId ?? this.userId;
|
|
451
|
-
const targetType = childType ?? "citoyens";
|
|
452
|
-
|
|
453
|
-
// Valider que le type est autorisé
|
|
454
|
-
const validChildTypes: Array<"citoyens" | "projects" | "organizations"> = ["citoyens", "projects", "organizations"];
|
|
455
|
-
if (!validChildTypes.includes(targetType as any)) {
|
|
456
|
-
throw new ApiError(
|
|
457
|
-
`Le type de cible "${targetType}" n'est pas valide. Types autorisés: ${validChildTypes.join(", ")}`,
|
|
458
|
-
400
|
|
459
|
-
);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// Empêcher l'auto-partage: on ne peut pas partager sa propre news à soi-même
|
|
463
|
-
if (this.parent.id === this.userId && targetId === this.userId) {
|
|
464
|
-
throw new ApiError("Vous ne pouvez pas partager votre propre news à vous-même", 400);
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
const payload: ShareNewsData = {
|
|
468
|
-
parentId: this.id,
|
|
469
|
-
parentType: "news",
|
|
470
|
-
connectType: "share",
|
|
471
|
-
childType: targetType as "citoyens" | "projects" | "organizations",
|
|
472
|
-
childId: targetId,
|
|
473
|
-
comment
|
|
474
|
-
};
|
|
475
|
-
|
|
476
|
-
return await this.callIsConnected(() => this.endpointApi.shareNews(payload));
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* Vérifie si l'utilisateur connecté est l'auteur de cette actualité.
|
|
481
|
-
*
|
|
482
|
-
* Cette méthode compare l'ID de l'utilisateur connecté avec l'ID de l'auteur
|
|
483
|
-
* de l'actualité. L'auteur peut être soit un objet simple NewsAuthor, soit
|
|
484
|
-
* une instance d'entité User ou Organization.
|
|
485
|
-
* @param options - Options de vérification.
|
|
486
|
-
* @param options.silent - Si `true`, retourne `false` au lieu de lever une exception. Par défaut `true`.
|
|
487
|
-
* @returns `true` si l'utilisateur connecté est l'auteur, `false` sinon
|
|
488
|
-
* @throws {ApiError} Si l'utilisateur n'est pas connecté (401)
|
|
489
|
-
* @throws {ApiError} Si l'actualité n'a pas d'ID - non enregistrée (404)
|
|
490
|
-
* @throws {ApiError} Si les données serveur ne sont pas disponibles (404)
|
|
491
|
-
*
|
|
492
|
-
* @example
|
|
493
|
-
* ```typescript
|
|
494
|
-
* const news = await me.news({ id: "123" });
|
|
495
|
-
* await news.get();
|
|
496
|
-
*
|
|
497
|
-
* if (news.isAuthor()) {
|
|
498
|
-
* console.log("Vous êtes l'auteur de cette actualité");
|
|
499
|
-
* await news.delete(); // Vous pouvez la supprimer
|
|
500
|
-
* }
|
|
501
|
-
* ```
|
|
502
|
-
*/
|
|
503
|
-
override isAuthor(options?: { silent?: boolean }): boolean {
|
|
504
|
-
const silent = options?.silent ?? true;
|
|
505
|
-
|
|
506
|
-
try {
|
|
507
|
-
if (!this.isMe) {
|
|
508
|
-
throw new ApiError("Vous devez être connecté pour vérifier l'auteur.", 401);
|
|
509
|
-
}
|
|
510
|
-
if (!this.id) {
|
|
511
|
-
throw new ApiError(`${this.constructor.name} non enregistrée.`, 404);
|
|
512
|
-
}
|
|
513
|
-
if (!this.serverData) {
|
|
514
|
-
throw new ApiError("Aucune donnée serveur disponible.", 404);
|
|
515
|
-
}
|
|
516
|
-
if (!this.userId) {
|
|
517
|
-
throw new ApiError("Utilisateur non connecté.", 401);
|
|
518
|
-
}
|
|
519
|
-
} catch (e) {
|
|
520
|
-
if (silent) return false;
|
|
521
|
-
throw e;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
const author = this.serverData.author;
|
|
525
|
-
if (!author) {
|
|
526
|
-
return false;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
// Extraire l'ID selon le type d'author
|
|
530
|
-
// author peut être NewsAuthor (objet simple avec .id) ou User/Organization (entité avec .serverData.id)
|
|
531
|
-
let authorId: string | undefined;
|
|
532
|
-
|
|
533
|
-
if ("serverData" in author && author.serverData && typeof author.serverData === "object" && "id" in author.serverData) {
|
|
534
|
-
// C'est une instance d'entité (User ou Organization)
|
|
535
|
-
authorId = author.serverData.id as string;
|
|
536
|
-
} else if ("id" in author) {
|
|
537
|
-
// C'est un objet NewsAuthor simple
|
|
538
|
-
authorId = author.id as string;
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
return Boolean(authorId && this.userId === authorId);
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
override async form(): Promise<never> {
|
|
545
|
-
throw new ApiError(`form n'existe pas dans ${this.constructor.name}`, 501);
|
|
546
|
-
}
|
|
547
|
-
}
|