@communecter/cocolight-api-client 1.0.23 → 1.0.25
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 +2 -2
- package/dist/cocolight-api-client.cjs +1 -1
- package/dist/cocolight-api-client.mjs.js +1 -1
- package/package.json +1 -1
- package/src/api/Badge.js +20 -12
- package/src/api/BaseEntity.js +191 -12
- package/src/api/EndpointApi.js +15 -0
- package/src/api/EndpointApi.types.d.ts +8 -0
- package/src/api/Event.js +16 -11
- package/src/api/Organization.js +22 -9
- package/src/api/Poi.js +16 -12
- package/src/api/Project.js +22 -9
- package/src/api/User.js +55 -7
- package/src/endpoints.module.js +1 -1
package/package.json
CHANGED
package/src/api/Badge.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ApiError } from "../error.js";
|
|
1
2
|
import BaseEntity from "./BaseEntity.js";
|
|
2
3
|
|
|
3
4
|
export class Badge extends BaseEntity {
|
|
@@ -25,6 +26,9 @@ export class Badge extends BaseEntity {
|
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
async _add(payload) {
|
|
29
|
+
if (!this._calledFromSave) {
|
|
30
|
+
throw new ApiError("utilisation invalide de _add, utilisez save");
|
|
31
|
+
}
|
|
28
32
|
payload.id = this._newId?.();
|
|
29
33
|
if (payload.slug) delete payload.slug;
|
|
30
34
|
|
|
@@ -46,6 +50,10 @@ export class Badge extends BaseEntity {
|
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
async _update(payload) {
|
|
53
|
+
// TODO: qui peut modifier un badge ?
|
|
54
|
+
if (!this._calledFromSave) {
|
|
55
|
+
throw new ApiError("utilisation invalide de _update, utilisez save");
|
|
56
|
+
}
|
|
49
57
|
if (payload.id) delete payload.id;
|
|
50
58
|
let hasChanged = false;
|
|
51
59
|
|
|
@@ -67,51 +75,51 @@ export class Badge extends BaseEntity {
|
|
|
67
75
|
}
|
|
68
76
|
|
|
69
77
|
async getOrganizations() {
|
|
70
|
-
throw new
|
|
78
|
+
throw new ApiError(`getOrganizations n'existe pas dans ${this.constructor.name}`);
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
async getProjects() {
|
|
74
|
-
throw new
|
|
82
|
+
throw new ApiError(`getProjects n'existe pas dans ${this.constructor.name}`);
|
|
75
83
|
}
|
|
76
84
|
|
|
77
85
|
async getEvents() {
|
|
78
|
-
throw new
|
|
86
|
+
throw new ApiError(`getEvents n'existe pas dans ${this.constructor.name}`);
|
|
79
87
|
}
|
|
80
88
|
|
|
81
89
|
async getPois() {
|
|
82
|
-
throw new
|
|
90
|
+
throw new ApiError(`getPois n'existe pas dans ${this.constructor.name}`);
|
|
83
91
|
}
|
|
84
92
|
|
|
85
93
|
async getBadgesIssuer() {
|
|
86
|
-
throw new
|
|
94
|
+
throw new ApiError(`getBadgesIssuer n'existe pas dans ${this.constructor.name}`);
|
|
87
95
|
}
|
|
88
96
|
|
|
89
97
|
async getNews() {
|
|
90
|
-
throw new
|
|
98
|
+
throw new ApiError(`getNews n'existe pas dans ${this.constructor.name}`);
|
|
91
99
|
}
|
|
92
100
|
|
|
93
101
|
async getSubscribers() {
|
|
94
|
-
throw new
|
|
102
|
+
throw new ApiError(`getSubscribers n'existe pas dans ${this.constructor.name}`);
|
|
95
103
|
}
|
|
96
104
|
|
|
97
105
|
async project() {
|
|
98
|
-
throw new
|
|
106
|
+
throw new ApiError(`project n'existe pas dans ${this.constructor.name}`);
|
|
99
107
|
}
|
|
100
108
|
|
|
101
109
|
async poi() {
|
|
102
|
-
throw new
|
|
110
|
+
throw new ApiError(`poi n'existe pas dans ${this.constructor.name}`);
|
|
103
111
|
}
|
|
104
112
|
|
|
105
113
|
async event() {
|
|
106
|
-
throw new
|
|
114
|
+
throw new ApiError(`event n'existe pas dans ${this.constructor.name}`);
|
|
107
115
|
}
|
|
108
116
|
|
|
109
117
|
async badge() {
|
|
110
|
-
throw new
|
|
118
|
+
throw new ApiError(`badge n'existe pas dans ${this.constructor.name}`);
|
|
111
119
|
}
|
|
112
120
|
|
|
113
121
|
async news() {
|
|
114
|
-
throw new
|
|
122
|
+
throw new ApiError(`news n'existe pas dans ${this.constructor.name}`);
|
|
115
123
|
}
|
|
116
124
|
|
|
117
125
|
}
|
package/src/api/BaseEntity.js
CHANGED
|
@@ -61,10 +61,16 @@ export class BaseEntity {
|
|
|
61
61
|
/** @type {ApiClient} */
|
|
62
62
|
this.apiClient = parent;
|
|
63
63
|
this.parent = null;
|
|
64
|
+
this.userContext = null;
|
|
64
65
|
} else if (parent?.apiClient) {
|
|
65
66
|
/** @type {ApiClient} */
|
|
66
67
|
this.apiClient = parent.apiClient;
|
|
67
68
|
this.parent = parent;
|
|
69
|
+
if (parent?.__entityTag === "User") {
|
|
70
|
+
this.userContext = parent;
|
|
71
|
+
} else if (parent?.userContext) {
|
|
72
|
+
this.userContext = parent.userContext;
|
|
73
|
+
}
|
|
68
74
|
} else {
|
|
69
75
|
throw new ApiError("Parent invalide ou ApiClient manquant.");
|
|
70
76
|
}
|
|
@@ -101,6 +107,11 @@ export class BaseEntity {
|
|
|
101
107
|
return this._draftData.id || null;
|
|
102
108
|
}
|
|
103
109
|
|
|
110
|
+
/** @returns {string|null} Slug de l'entité */
|
|
111
|
+
get slug() {
|
|
112
|
+
return this._draftData.slug || null;
|
|
113
|
+
}
|
|
114
|
+
|
|
104
115
|
/** Définit un ID (utilisé en interne) */
|
|
105
116
|
_id(newId) {
|
|
106
117
|
this._draftData.id = newId;
|
|
@@ -133,7 +144,7 @@ export class BaseEntity {
|
|
|
133
144
|
|
|
134
145
|
/** @returns {boolean} Indique si cette entité représente l'utilisateur connecté */
|
|
135
146
|
get isMe() {
|
|
136
|
-
return this.isConnected && this.userId === this.
|
|
147
|
+
return this.isConnected && this.userId === this.userContext?.id;
|
|
137
148
|
}
|
|
138
149
|
|
|
139
150
|
/** @returns {string} Type de l'entité (ex: 'citoyens') */
|
|
@@ -170,6 +181,10 @@ export class BaseEntity {
|
|
|
170
181
|
|
|
171
182
|
if (!this.id && typeof this._add === "function") {
|
|
172
183
|
await this._add(payload);
|
|
184
|
+
// on refresh le contexte utilisateur si besoin
|
|
185
|
+
if(this.userContext) {
|
|
186
|
+
await this.userContext.refresh();
|
|
187
|
+
}
|
|
173
188
|
return await this.refresh();
|
|
174
189
|
} else if (typeof this._update === "function") {
|
|
175
190
|
const hasChanged = await this._update(payload);
|
|
@@ -204,6 +219,9 @@ export class BaseEntity {
|
|
|
204
219
|
* @private
|
|
205
220
|
*/
|
|
206
221
|
_setData(newData) {
|
|
222
|
+
if (this.userContext && this.userContext !== this) {
|
|
223
|
+
this.apiClient._logger?.info?.(`[${this.__entityTag}] Mise à jour liée à userContext : ${this.userContext.id}`);
|
|
224
|
+
}
|
|
207
225
|
this._serverData = reactive({ ...newData });
|
|
208
226
|
|
|
209
227
|
const { draft, proxy } = this._buildDraftAndProxy({
|
|
@@ -1120,8 +1138,8 @@ export class BaseEntity {
|
|
|
1120
1138
|
|
|
1121
1139
|
const fetchKeysByEntity = {
|
|
1122
1140
|
citoyens: ["id", "slug"],
|
|
1123
|
-
|
|
1124
|
-
|
|
1141
|
+
organizations: ["id", "slug"],
|
|
1142
|
+
projects: ["id", "slug"],
|
|
1125
1143
|
events: ["id", "slug"],
|
|
1126
1144
|
poi: ["id", "slug"],
|
|
1127
1145
|
news: ["id"],
|
|
@@ -1281,7 +1299,7 @@ export class BaseEntity {
|
|
|
1281
1299
|
*/
|
|
1282
1300
|
_getLinkFromConnectedUser() {
|
|
1283
1301
|
const { linkType } = this._getLinkMeta();
|
|
1284
|
-
return this
|
|
1302
|
+
return this?.userContext?.serverData?.links?.[linkType]?.[this.id] || null;
|
|
1285
1303
|
}
|
|
1286
1304
|
|
|
1287
1305
|
/**
|
|
@@ -1312,7 +1330,7 @@ export class BaseEntity {
|
|
|
1312
1330
|
|
|
1313
1331
|
// TODO : reflechir au moyen de remplir parent.serverData et this.serverData avec les data de retour pour eviter un refresh
|
|
1314
1332
|
const retour = await this.callIsMe(() => this.endpointApi.connect(data));
|
|
1315
|
-
await this.
|
|
1333
|
+
await this.userContext.refresh();
|
|
1316
1334
|
return retour;
|
|
1317
1335
|
}
|
|
1318
1336
|
|
|
@@ -1355,7 +1373,7 @@ export class BaseEntity {
|
|
|
1355
1373
|
|
|
1356
1374
|
// TODO : reflechir au moyen de remplir parent.serverData et this.serverData avec les data de retour pour eviter un refresh
|
|
1357
1375
|
const retour = await this.callIsMe(() => this.endpointApi.connect(data));
|
|
1358
|
-
await this.
|
|
1376
|
+
await this.userContext.refresh();
|
|
1359
1377
|
return retour;
|
|
1360
1378
|
}
|
|
1361
1379
|
|
|
@@ -1401,7 +1419,7 @@ export class BaseEntity {
|
|
|
1401
1419
|
};
|
|
1402
1420
|
// TODO : reflechir au moyen de remplir parent.serverData et this.serverData avec les data de retour pour eviter un refresh
|
|
1403
1421
|
const retour = await this.callIsMe(() => this.endpointApi.linkValidate(data));
|
|
1404
|
-
await this.
|
|
1422
|
+
await this.userContext.refresh();
|
|
1405
1423
|
return retour;
|
|
1406
1424
|
}
|
|
1407
1425
|
|
|
@@ -1438,7 +1456,7 @@ export class BaseEntity {
|
|
|
1438
1456
|
|
|
1439
1457
|
// TODO : reflechir au moyen de remplir parent.serverData et this.serverData avec les data de retour pour eviter un refresh
|
|
1440
1458
|
const retour = await this.callIsMe(() => this.endpointApi.disconnect(data));
|
|
1441
|
-
await this.
|
|
1459
|
+
await this.userContext.refresh();
|
|
1442
1460
|
return retour;
|
|
1443
1461
|
}
|
|
1444
1462
|
|
|
@@ -1937,7 +1955,7 @@ export class BaseEntity {
|
|
|
1937
1955
|
throw new ApiError(`${this.constructor.name} non enregistrée.`);
|
|
1938
1956
|
}
|
|
1939
1957
|
|
|
1940
|
-
const userLink = this.
|
|
1958
|
+
const userLink = this.userContext?.serverData?.links?.["follows"]?.[this.id] || null;
|
|
1941
1959
|
|
|
1942
1960
|
if (!userLink) {
|
|
1943
1961
|
const data = {
|
|
@@ -1946,7 +1964,7 @@ export class BaseEntity {
|
|
|
1946
1964
|
};
|
|
1947
1965
|
const retour = await this.callIsMe(() => this.endpointApi.follow(data));
|
|
1948
1966
|
// TODO : reflechir au moyen de remplir parent.serverData et this.serverData avec les data de retour pour eviter un refresh
|
|
1949
|
-
await this.
|
|
1967
|
+
await this.userContext.refresh();
|
|
1950
1968
|
return retour;
|
|
1951
1969
|
}
|
|
1952
1970
|
|
|
@@ -1968,7 +1986,7 @@ export class BaseEntity {
|
|
|
1968
1986
|
throw new ApiError(`${this.constructor.name} non enregistrée.`);
|
|
1969
1987
|
}
|
|
1970
1988
|
|
|
1971
|
-
const userLink = this.
|
|
1989
|
+
const userLink = this.userContext?.serverData?.links?.["follows"]?.[this.id] || null;
|
|
1972
1990
|
|
|
1973
1991
|
if (userLink) {
|
|
1974
1992
|
const data = {
|
|
@@ -1978,13 +1996,174 @@ export class BaseEntity {
|
|
|
1978
1996
|
};
|
|
1979
1997
|
const retour = await this.callIsMe(() => this.endpointApi.disconnect(data));
|
|
1980
1998
|
// TODO : reflechir au moyen de remplir parent.serverData et this.serverData avec les data de retour pour eviter un refresh
|
|
1981
|
-
await this.
|
|
1999
|
+
await this.userContext.refresh();
|
|
1982
2000
|
return retour;
|
|
1983
2001
|
}
|
|
1984
2002
|
|
|
1985
2003
|
throw new ApiError("Vous n'êtes pas abonné à cette entité.");
|
|
1986
2004
|
}
|
|
1987
2005
|
|
|
2006
|
+
|
|
2007
|
+
/**
|
|
2008
|
+
* Vérifie si l'utilisateur est connecté et a accès à l'entité.
|
|
2009
|
+
*
|
|
2010
|
+
* @param {string} action - Action à effectuer.
|
|
2011
|
+
* @returns {void}
|
|
2012
|
+
* @throws {ApiError} - Si l'utilisateur n'est pas connecté ou si l'entité n'est pas enregistrée.
|
|
2013
|
+
* @private
|
|
2014
|
+
*/
|
|
2015
|
+
_checkAccess(action = "effectuer cette action") {
|
|
2016
|
+
if (!this.isMe) {
|
|
2017
|
+
throw new ApiError(`Vous devez être connecté pour ${action}`);
|
|
2018
|
+
}
|
|
2019
|
+
if (!this.id) {
|
|
2020
|
+
throw new ApiError(`${this.constructor.name} non enregistrée.`);
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
/**
|
|
2025
|
+
* Vérifie si l'utilisateur a un lien valide avec l'entité.
|
|
2026
|
+
*
|
|
2027
|
+
* @param {Object} userLink - Lien de l'utilisateur avec l'entité.
|
|
2028
|
+
* @param {boolean} userLink.toBeValidated - Indique si le lien est en attente de validation.
|
|
2029
|
+
* @param {boolean} userLink.isInviting - Indique si l'utilisateur a été invité.
|
|
2030
|
+
* @returns {boolean} - `true` si le lien est valide, `false` sinon.
|
|
2031
|
+
* @private
|
|
2032
|
+
*/
|
|
2033
|
+
_validateUserLink(userLink) {
|
|
2034
|
+
if (!userLink) return false;
|
|
2035
|
+
const { toBeValidated, isInviting } = userLink;
|
|
2036
|
+
return !toBeValidated && !isInviting;
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
/**
|
|
2040
|
+
* Vérifie si l'entité est d'un type spécifique.
|
|
2041
|
+
*
|
|
2042
|
+
* @param {...string} types - Types d'entité attendus.
|
|
2043
|
+
* @throws {ApiError} - Si l'entité n'est pas du type attendu.
|
|
2044
|
+
* @private
|
|
2045
|
+
*/
|
|
2046
|
+
_assertEntityType(...types) {
|
|
2047
|
+
const expectedTypes = Array.isArray(types[0]) ? types[0] : types;
|
|
2048
|
+
if (!expectedTypes.includes(this.getEntityType())) {
|
|
2049
|
+
throw new ApiError(`L'entité doit être de type : ${expectedTypes.join(", ")}, reçu : ${this.getEntityType()}`);
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
/**
|
|
2054
|
+
* Vérifie si l'entité est liée à un type de lien spécifique.
|
|
2055
|
+
*
|
|
2056
|
+
* @param {string} linkType - Type de lien à vérifier.
|
|
2057
|
+
* @returns {boolean} - `true` si l'entité est liée, `false` sinon.
|
|
2058
|
+
* @private
|
|
2059
|
+
*/
|
|
2060
|
+
_isLinked(linkType) {
|
|
2061
|
+
return !!this.userContext?.serverData?.links?.[linkType]?.[this.id];
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
/**
|
|
2065
|
+
* Vérifie si l'utilisateur est l'auteur de l'entité.
|
|
2066
|
+
*
|
|
2067
|
+
* @returns {boolean} - `true` si l'utilisateur est l'auteur, `false` sinon.
|
|
2068
|
+
* @throws {ApiError} - Si l'utilisateur n'est pas connecté ou si les données du serveur ne sont pas disponibles.
|
|
2069
|
+
*/
|
|
2070
|
+
isAuthor() {
|
|
2071
|
+
this._checkAccess("vérifier l'auteur");
|
|
2072
|
+
if (!this.serverData) {
|
|
2073
|
+
throw new ApiError("Aucune donnée serveur disponible.");
|
|
2074
|
+
}
|
|
2075
|
+
return this.userId && this.serverData?.creator === this.userId;
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
/**
|
|
2079
|
+
* Vérifie si l'utilisateur est administrateur de l'entité.
|
|
2080
|
+
*
|
|
2081
|
+
* @returns {boolean} - `true` si l'utilisateur est administrateur, `false` sinon.
|
|
2082
|
+
* @throws {ApiError}
|
|
2083
|
+
*/
|
|
2084
|
+
isAdmin() {
|
|
2085
|
+
this._checkAccess("vérifier l'administrateur.");
|
|
2086
|
+
this._assertEntityType("organizations", "projects", "events");
|
|
2087
|
+
const userLink = this._getLinkFromConnectedUser();
|
|
2088
|
+
return this._validateUserLink(userLink) && userLink?.isAdmin === true && !userLink?.isAdminPending;
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2091
|
+
/**
|
|
2092
|
+
* Vérifie si l'utilisateur est soit l'auteur, soit administrateur de l'entité.
|
|
2093
|
+
*
|
|
2094
|
+
* @returns {boolean} - `true` si l'utilisateur est l'auteur ou administrateur, `false` sinon.
|
|
2095
|
+
* @throws {ApiError}
|
|
2096
|
+
*/
|
|
2097
|
+
isAuthorOrAdmin() {
|
|
2098
|
+
this._checkAccess("vérifier l'auteur ou l'administrateur.");
|
|
2099
|
+
return this.isAuthor() || this.isAdmin();
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
/**
|
|
2103
|
+
* Vérifie si l'utilisateur est membre de l'entité.
|
|
2104
|
+
*
|
|
2105
|
+
* @returns {boolean} - `true` si l'utilisateur est membre, `false` sinon.
|
|
2106
|
+
* @throws {ApiError}
|
|
2107
|
+
*/
|
|
2108
|
+
isMember() {
|
|
2109
|
+
this._checkAccess("vérifier le membre.");
|
|
2110
|
+
this._assertEntityType("organizations");
|
|
2111
|
+
const userLink = this._getLinkFromConnectedUser();
|
|
2112
|
+
return this._validateUserLink(userLink);
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
/**
|
|
2116
|
+
* Vérifie si l'utilisateur est contributeur de l'entité.
|
|
2117
|
+
*
|
|
2118
|
+
* @returns {boolean} - `true` si l'utilisateur est contributeur, `false` sinon.
|
|
2119
|
+
* @throws {ApiError}
|
|
2120
|
+
*/
|
|
2121
|
+
isContributor() {
|
|
2122
|
+
this._checkAccess("vérifier le contributeur.");
|
|
2123
|
+
this._assertEntityType("projects");
|
|
2124
|
+
const userLink = this._getLinkFromConnectedUser();
|
|
2125
|
+
return this._validateUserLink(userLink);
|
|
2126
|
+
}
|
|
2127
|
+
|
|
2128
|
+
/**
|
|
2129
|
+
* Vérifie si l'utilisateur est participant de l'entité.
|
|
2130
|
+
*
|
|
2131
|
+
* @returns {boolean} - `true` si l'utilisateur est participant, `false` sinon.
|
|
2132
|
+
* @throws {ApiError}
|
|
2133
|
+
*/
|
|
2134
|
+
isAttendee() {
|
|
2135
|
+
this._checkAccess("vérifier si vous êtes un participant.");
|
|
2136
|
+
this._assertEntityType("events");
|
|
2137
|
+
const userLink = this._getLinkFromConnectedUser();
|
|
2138
|
+
return this._validateUserLink(userLink);
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
/**
|
|
2142
|
+
* Vérifie si l'utilisateur suit l'entité.
|
|
2143
|
+
*
|
|
2144
|
+
* @returns {boolean} - `true` si l'utilisateur suit l'entité, `false` sinon.
|
|
2145
|
+
* @throws {ApiError}
|
|
2146
|
+
*/
|
|
2147
|
+
isFollower() {
|
|
2148
|
+
this._checkAccess("vérifier si il vous suit.");
|
|
2149
|
+
this._assertEntityType("citoyens","organizations", "projects", "events", "poi");
|
|
2150
|
+
return this._isLinked("followers");
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
/**
|
|
2154
|
+
* Vérifie si l'utilisateur est abonné à l'entité.
|
|
2155
|
+
*
|
|
2156
|
+
* @returns {boolean} - `true` si l'utilisateur est abonné, `false` sinon.
|
|
2157
|
+
* @throws {ApiError}
|
|
2158
|
+
*/
|
|
2159
|
+
isFollowing() {
|
|
2160
|
+
this._checkAccess("vérifier si vous le suivez.");
|
|
2161
|
+
this._assertEntityType("citoyens","organizations", "projects", "events", "poi");
|
|
2162
|
+
return this._isLinked("follows");
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
|
|
2166
|
+
|
|
1988
2167
|
}
|
|
1989
2168
|
|
|
1990
2169
|
export default BaseEntity;
|
package/src/api/EndpointApi.js
CHANGED
|
@@ -1348,6 +1348,21 @@ class EndpointApi {
|
|
|
1348
1348
|
return this.callIsConnected("FOLLOW", data);
|
|
1349
1349
|
}
|
|
1350
1350
|
|
|
1351
|
+
/**
|
|
1352
|
+
* Récuperer les data d'un JSON d'un costum : Récuperer les data d'un JSON d'un costum
|
|
1353
|
+
* Constant : GET_COSTUM_JSON
|
|
1354
|
+
* @param {import("./EndpointApi.types").GetCostumJsonData} data - Données envoyées à l'API
|
|
1355
|
+
* @returns {Promise<Object>} - Les données de réponse.
|
|
1356
|
+
* @throws {ApiResponseError} - En cas d'erreur détectée dans la réponse.
|
|
1357
|
+
* @throws {Error} - En cas d'erreur inattendue.
|
|
1358
|
+
*/
|
|
1359
|
+
async getCostumJson(data) {
|
|
1360
|
+
if (!data || typeof data !== "object") {
|
|
1361
|
+
throw new TypeError("Le paramètre data doit être un objet.");
|
|
1362
|
+
}
|
|
1363
|
+
return this.call("GET_COSTUM_JSON", data);
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1351
1366
|
}
|
|
1352
1367
|
|
|
1353
1368
|
export default EndpointApi;
|
package/src/api/Event.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ApiError } from "../error.js";
|
|
1
2
|
import BaseEntity from "./BaseEntity.js";
|
|
2
3
|
|
|
3
4
|
export class Event extends BaseEntity {
|
|
@@ -38,7 +39,7 @@ export class Event extends BaseEntity {
|
|
|
38
39
|
|
|
39
40
|
async _add(payload) {
|
|
40
41
|
if (!this._calledFromSave) {
|
|
41
|
-
throw new
|
|
42
|
+
throw new ApiError("utilisation invalide de _add, utilisez save");
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
payload.id = this._newId?.();
|
|
@@ -62,8 +63,12 @@ export class Event extends BaseEntity {
|
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
async _update(payload) {
|
|
66
|
+
if(!this.isAdmin()){
|
|
67
|
+
throw new ApiError("Vous n'avez pas les droits pour modifier cet événement", 403);
|
|
68
|
+
}
|
|
69
|
+
|
|
65
70
|
if (!this._calledFromSave) {
|
|
66
|
-
throw new
|
|
71
|
+
throw new ApiError("utilisation invalide de _update, utilisez save");
|
|
67
72
|
}
|
|
68
73
|
|
|
69
74
|
if (payload.id) delete payload.id;
|
|
@@ -87,23 +92,23 @@ export class Event extends BaseEntity {
|
|
|
87
92
|
}
|
|
88
93
|
|
|
89
94
|
async getOrganizations() {
|
|
90
|
-
throw new
|
|
95
|
+
throw new ApiError(`getOrganizations n'existe pas dans ${this.constructor.name}`);
|
|
91
96
|
}
|
|
92
97
|
|
|
93
98
|
async getProjects() {
|
|
94
|
-
throw new
|
|
99
|
+
throw new ApiError(`getProjects n'existe pas dans ${this.constructor.name}`);
|
|
95
100
|
}
|
|
96
101
|
|
|
97
102
|
async getEvents() {
|
|
98
|
-
throw new
|
|
103
|
+
throw new ApiError(`getEvents - les sous-events ne sont pas encore implémentés dans ${this.constructor.name}`);
|
|
99
104
|
}
|
|
100
105
|
|
|
101
106
|
async getPois() {
|
|
102
|
-
throw new
|
|
107
|
+
throw new ApiError(`getPois n'existe pas dans ${this.constructor.name}`);
|
|
103
108
|
}
|
|
104
109
|
|
|
105
110
|
async getBadgesIssuer() {
|
|
106
|
-
throw new
|
|
111
|
+
throw new ApiError(`getBadgesIssuer n'existe pas dans ${this.constructor.name}`);
|
|
107
112
|
}
|
|
108
113
|
|
|
109
114
|
async getNews(data = {}) {
|
|
@@ -115,19 +120,19 @@ export class Event extends BaseEntity {
|
|
|
115
120
|
}
|
|
116
121
|
|
|
117
122
|
async project() {
|
|
118
|
-
throw new
|
|
123
|
+
throw new ApiError(`project n'existe pas dans ${this.constructor.name}`);
|
|
119
124
|
}
|
|
120
125
|
|
|
121
126
|
async poi() {
|
|
122
|
-
throw new
|
|
127
|
+
throw new ApiError(`poi n'existe pas dans ${this.constructor.name}`);
|
|
123
128
|
}
|
|
124
129
|
|
|
125
130
|
async event() {
|
|
126
|
-
throw new
|
|
131
|
+
throw new ApiError(`les sous-events ne sont pas encore implémentés dans ${this.constructor.name}`);
|
|
127
132
|
}
|
|
128
133
|
|
|
129
134
|
async badge() {
|
|
130
|
-
throw new
|
|
135
|
+
throw new ApiError(`badge n'existe pas dans ${this.constructor.name}`);
|
|
131
136
|
}
|
|
132
137
|
|
|
133
138
|
/**
|
package/src/api/Organization.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiResponseError } from "../error.js";
|
|
1
|
+
import { ApiError, ApiResponseError } from "../error.js";
|
|
2
2
|
import BaseEntity from "./BaseEntity.js";
|
|
3
3
|
|
|
4
4
|
export class Organization extends BaseEntity {
|
|
@@ -52,7 +52,7 @@ export class Organization extends BaseEntity {
|
|
|
52
52
|
|
|
53
53
|
async _add(payload) {
|
|
54
54
|
if (!this._calledFromSave) {
|
|
55
|
-
throw new
|
|
55
|
+
throw new ApiError("utilisation invalide de _add, utilisez save");
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
payload.id = this._newId?.();
|
|
@@ -76,8 +76,12 @@ export class Organization extends BaseEntity {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
async _update(payload) {
|
|
79
|
+
if(!this.isAdmin()){
|
|
80
|
+
throw new ApiError("Vous n'avez pas les droits pour modifier cette organisation", 403);
|
|
81
|
+
}
|
|
82
|
+
|
|
79
83
|
if (!this._calledFromSave) {
|
|
80
|
-
throw new
|
|
84
|
+
throw new ApiError("utilisation invalide de _update, utilisez save");
|
|
81
85
|
}
|
|
82
86
|
|
|
83
87
|
if (payload.id) delete payload.id;
|
|
@@ -106,7 +110,7 @@ export class Organization extends BaseEntity {
|
|
|
106
110
|
|
|
107
111
|
|
|
108
112
|
async getOrganizations() {
|
|
109
|
-
throw new
|
|
113
|
+
throw new ApiError("getOrganizations n'existe pas dans Organization");
|
|
110
114
|
}
|
|
111
115
|
|
|
112
116
|
async getProjects(data = {}) {
|
|
@@ -114,7 +118,7 @@ export class Organization extends BaseEntity {
|
|
|
114
118
|
}
|
|
115
119
|
|
|
116
120
|
async getEvents() {
|
|
117
|
-
throw new
|
|
121
|
+
throw new ApiError("getEvents pas encore implémenté dans Organization");
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
async getPois(data = {}) {
|
|
@@ -215,7 +219,9 @@ export class Organization extends BaseEntity {
|
|
|
215
219
|
* @throws {Error} Si une erreur se produit lors de la création du projet.
|
|
216
220
|
*/
|
|
217
221
|
async project(projectData = {}) {
|
|
218
|
-
|
|
222
|
+
if(!this.isAdmin()){
|
|
223
|
+
throw new ApiError("Vous n'avez pas les droits pour créer un projet dans cette organisation", 403);
|
|
224
|
+
}
|
|
219
225
|
return super.project(projectData);
|
|
220
226
|
}
|
|
221
227
|
|
|
@@ -227,7 +233,9 @@ export class Organization extends BaseEntity {
|
|
|
227
233
|
* @throws {Error} Si une erreur se produit lors de la création du POI.
|
|
228
234
|
*/
|
|
229
235
|
async poi(poiData = {}) {
|
|
230
|
-
|
|
236
|
+
if(!this.isAdmin()){
|
|
237
|
+
throw new ApiError("Vous n'avez pas les droits pour créer un projet dans cette organisation", 403);
|
|
238
|
+
}
|
|
231
239
|
return super.poi(poiData);
|
|
232
240
|
}
|
|
233
241
|
|
|
@@ -239,7 +247,9 @@ export class Organization extends BaseEntity {
|
|
|
239
247
|
* @throws {Error} Si une erreur se produit lors de la création de l'événement.
|
|
240
248
|
*/
|
|
241
249
|
async event(eventData = {}) {
|
|
242
|
-
|
|
250
|
+
if(!this.isAdmin()){
|
|
251
|
+
throw new ApiError("Vous n'avez pas les droits pour créer un projet dans cette organisation", 403);
|
|
252
|
+
}
|
|
243
253
|
return super.event(eventData);
|
|
244
254
|
}
|
|
245
255
|
|
|
@@ -251,7 +261,9 @@ export class Organization extends BaseEntity {
|
|
|
251
261
|
* @throws {Error} Si une erreur se produit lors de la création du badge.
|
|
252
262
|
*/
|
|
253
263
|
async badge(badgeData = {}) {
|
|
254
|
-
|
|
264
|
+
if(!this.isAdmin()){
|
|
265
|
+
throw new ApiError("Vous n'avez pas les droits pour créer un projet dans cette organisation", 403);
|
|
266
|
+
}
|
|
255
267
|
return super.badge(badgeData);
|
|
256
268
|
}
|
|
257
269
|
|
|
@@ -263,6 +275,7 @@ export class Organization extends BaseEntity {
|
|
|
263
275
|
* @throws {Error} Si une erreur se produit lors de la création de la news.
|
|
264
276
|
*/
|
|
265
277
|
async news(newsData = {}) {
|
|
278
|
+
// TODO: qui peut créer une news sur l'organisation ?
|
|
266
279
|
return super.news(newsData);
|
|
267
280
|
}
|
|
268
281
|
|