@stackfactor/client-api 1.0.32 → 1.0.33

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.
@@ -1,267 +1,265 @@
1
- import { axios } from "./axiosClient";
1
+ import axios from "./axiosClient";
2
2
 
3
- module.exports = {
4
- axios: axios,
3
+ /**
4
+ * Create training plan and set information
5
+ * @param {Object} data
6
+ * @param {Number} type
7
+ * @param {Boolean} saveAsDraft Save as draft flag
8
+ * @param {String} token Authorization token
9
+ */
10
+ export const createTrainingPlan = (data, type, saveAsDraft, token) => {
11
+ return new Promise(function (resolve, reject) {
12
+ const requestData = {
13
+ data: {
14
+ ...data,
15
+ },
16
+ saveAsDraft,
17
+ type,
18
+ };
19
+ let confirmationRequest = axios.put("api/v1/trainingplans", requestData, {
20
+ headers: { authorization: token },
21
+ });
22
+ confirmationRequest
23
+ .then((response) => {
24
+ resolve(response.data);
25
+ })
26
+ .catch((error) => {
27
+ reject(error);
28
+ });
29
+ });
30
+ };
5
31
 
6
- /**
7
- * Create training plan and set information
8
- * @param {Object} data
9
- * @param {Number} type
10
- * @param {Boolean} saveAsDraft Save as draft flag
11
- * @param {String} token Authorization token
12
- */
13
- createTrainingPlan: (data, type, saveAsDraft, token) => {
14
- return new Promise(function (resolve, reject) {
15
- const requestData = {
16
- data: {
17
- ...data,
18
- },
19
- saveAsDraft,
20
- type,
21
- };
22
- let confirmationRequest = axios.put("api/v1/trainingplans", requestData, {
23
- headers: { authorization: token },
32
+ /**
33
+ * Delete training plan
34
+ * @param {String} id The id of the training plan to be deleted
35
+ * @param {String} comment The comment for approver
36
+ * @param {String} token Authorization token
37
+ */
38
+ export const deleteTrainingPlan = (id, comment, token) => {
39
+ return new Promise(function (resolve, reject) {
40
+ const data = {
41
+ id: id,
42
+ };
43
+ if (comment) data.comment = comment;
44
+ const request = axios.delete(`api/v1/trainingplans/`, {
45
+ headers: { authorization: token },
46
+ data: data,
47
+ });
48
+ request
49
+ .then((response) => {
50
+ resolve(response.data);
51
+ })
52
+ .catch((error) => {
53
+ reject(error);
24
54
  });
25
- confirmationRequest
26
- .then((response) => {
27
- resolve(response.data);
28
- })
29
- .catch((error) => {
30
- reject(error);
31
- });
55
+ });
56
+ };
57
+
58
+ /**
59
+ * Discard the training plan draft changes
60
+ * @param {String} id The id of the training plan to be deleted
61
+ * @param {String} token Authorization token
62
+ */
63
+ export const discardTrainingPlanChanges = (id, token) => {
64
+ return new Promise(function (resolve, reject) {
65
+ const request = axios.get(`api/v1/trainingplans/discard/${id}`, {
66
+ headers: { authorization: token },
32
67
  });
33
- },
68
+ request
69
+ .then((response) => {
70
+ resolve(response.data);
71
+ })
72
+ .catch((error) => {
73
+ reject(error);
74
+ });
75
+ });
76
+ };
34
77
 
35
- /**
36
- * Delete training plan
37
- * @param {String} id The id of the training plan to be deleted
38
- * @param {String} comment The comment for approver
39
- * @param {String} token Authorization token
40
- */
41
- deleteTrainingPlan: (id, comment, token) => {
42
- return new Promise(function (resolve, reject) {
43
- const data = {
44
- id: id,
45
- };
46
- if (comment) data.comment = comment;
47
- const request = axios.delete(`api/v1/trainingplans/`, {
78
+ /**
79
+ * Create a new baselie
80
+ * @param {String} id The Id of the plan for which a new baseline is to be generated
81
+ * @param {Object} data The data
82
+ * @param {Boolean} returnMinimized If set to true just high level plan baseline information will be returned
83
+ * @param {Boolean} saveBaseline If set to true it will save the baseline
84
+ * @param {String} token Authorization token
85
+ */
86
+ export const generateNewBaseline = (
87
+ id,
88
+ data,
89
+ returnMinimized,
90
+ saveBaseline,
91
+ token
92
+ ) => {
93
+ return new Promise(function (resolve, reject) {
94
+ const requestData = {
95
+ data: data,
96
+ returnMinimized: returnMinimized,
97
+ saveBaseline: saveBaseline,
98
+ };
99
+ if (id) requestData.id = id;
100
+ let confirmationRequest = axios.post(
101
+ "api/v1/trainingplans/generatenewbaseline",
102
+ requestData,
103
+ {
48
104
  headers: { authorization: token },
49
- data: data,
105
+ }
106
+ );
107
+ confirmationRequest
108
+ .then((response) => {
109
+ resolve(response.data);
110
+ })
111
+ .catch((error) => {
112
+ reject(error);
50
113
  });
51
- request
52
- .then((response) => {
53
- resolve(response.data);
54
- })
55
- .catch((error) => {
56
- reject(error);
57
- });
58
- });
59
- },
114
+ });
115
+ };
60
116
 
61
- /**
62
- * Discard the training plan draft changes
63
- * @param {String} id The id of the training plan to be deleted
64
- * @param {String} token Authorization token
65
- */
66
- discardTrainingPlanChanges: (id, token) => {
67
- return new Promise(function (resolve, reject) {
68
- const request = axios.get(`api/v1/trainingplans/discard/${id}`, {
117
+ /**
118
+ * Get traing plan information
119
+ * @param {String} id The id of the training plan
120
+ * @param {String} token Authorization token
121
+ */
122
+ export const getTrainingPlanById = (id, version, token) => {
123
+ return new Promise(function (resolve, reject) {
124
+ let confirmationRequest = axios.get(
125
+ `api/v1/trainingplans/${id}/${version}`,
126
+ {
69
127
  headers: { authorization: token },
128
+ }
129
+ );
130
+ confirmationRequest
131
+ .then((response) => {
132
+ resolve(response.data);
133
+ })
134
+ .catch((error) => {
135
+ reject(error);
70
136
  });
71
- request
72
- .then((response) => {
73
- resolve(response.data);
74
- })
75
- .catch((error) => {
76
- reject(error);
77
- });
78
- });
79
- },
80
-
81
- /**
82
- * Create a new baselie
83
- * @param {String} id The Id of the plan for which a new baseline is to be generated
84
- * @param {Object} data The data
85
- * @param {Boolean} returnMinimized If set to true just high level plan baseline information will be returned
86
- * @param {Boolean} saveBaseline If set to true it will save the baseline
87
- * @param {String} token Authorization token
88
- */
89
- generateNewBaseline: (id, data, returnMinimized, saveBaseline, token) => {
90
- return new Promise(function (resolve, reject) {
91
- const requestData = {
92
- data: data,
93
- returnMinimized: returnMinimized,
94
- saveBaseline: saveBaseline,
95
- };
96
- if (id) requestData.id = id;
97
- let confirmationRequest = axios.post(
98
- "api/v1/trainingplans/generatenewbaseline",
99
- requestData,
100
- {
101
- headers: { authorization: token },
102
- }
103
- );
104
- confirmationRequest
105
- .then((response) => {
106
- resolve(response.data);
107
- })
108
- .catch((error) => {
109
- reject(error);
110
- });
111
- });
112
- },
113
-
114
- /**
115
- * Get traing plan information
116
- * @param {String} id The id of the training plan
117
- * @param {String} token Authorization token
118
- */
119
- getTrainingPlanById: (id, version, token) => {
120
- return new Promise(function (resolve, reject) {
121
- let confirmationRequest = axios.get(
122
- `api/v1/trainingplans/${id}/${version}`,
123
- {
124
- headers: { authorization: token },
125
- }
126
- );
127
- confirmationRequest
128
- .then((response) => {
129
- resolve(response.data);
130
- })
131
- .catch((error) => {
132
- reject(error);
133
- });
134
- });
135
- },
137
+ });
138
+ };
136
139
 
137
- /**
138
- * Get training plans list
139
- * @param {Array<ObjectId>} users The list of users for which the plans should be loaded
140
- * @param {Array<Number>} types The types of plans to be loaded
141
- * @param {String} version The version of the document to be retrieved
142
- * @param {Array<String>} fields The fields to be selected
143
- * @param {Boolean} includeDeleted If set true it will return deleted plans too
144
- * @param {Boolean} returnDefaultIfVersionNotAvailable If set to true it will load the draft information if the plan was never published
145
- * @param {String} token Authorization token
146
- */
147
- getListOfTrainingPlans: (
148
- users,
149
- types,
150
- version,
151
- fields,
152
- includeDeleted,
153
- includeDetailedInformation,
154
- returnDefaultIfVersionNotAvailable,
155
- token
156
- ) => {
157
- return new Promise(function (resolve, reject) {
158
- const requestData = {
159
- version: version,
160
- includeDeleted: includeDeleted,
161
- includeDetailedInformation: includeDetailedInformation,
162
- returnDefaultIfVersionNotAvailable: returnDefaultIfVersionNotAvailable,
163
- };
164
- if (fields) requestData.fields = fields;
165
- if (types) requestData.types = types;
166
- if (users) requestData.users = users;
167
- let confirmationRequest = axios.post(
168
- `api/v1/trainingplans`,
169
- requestData,
170
- {
171
- headers: { authorization: token },
172
- }
173
- );
174
- confirmationRequest
175
- .then((response) => {
176
- resolve(response.data);
177
- })
178
- .catch((error) => {
179
- reject(error);
180
- });
140
+ /**
141
+ * Get training plans list
142
+ * @param {Array<ObjectId>} users The list of users for which the plans should be loaded
143
+ * @param {Array<Number>} types The types of plans to be loaded
144
+ * @param {String} version The version of the document to be retrieved
145
+ * @param {Array<String>} fields The fields to be selected
146
+ * @param {Boolean} includeDeleted If set true it will return deleted plans too
147
+ * @param {Boolean} returnDefaultIfVersionNotAvailable If set to true it will load the draft information if the plan was never published
148
+ * @param {String} token Authorization token
149
+ */
150
+ export const getListOfTrainingPlans = (
151
+ users,
152
+ types,
153
+ version,
154
+ fields,
155
+ includeDeleted,
156
+ includeDetailedInformation,
157
+ returnDefaultIfVersionNotAvailable,
158
+ token
159
+ ) => {
160
+ return new Promise(function (resolve, reject) {
161
+ const requestData = {
162
+ version: version,
163
+ includeDeleted: includeDeleted,
164
+ includeDetailedInformation: includeDetailedInformation,
165
+ returnDefaultIfVersionNotAvailable: returnDefaultIfVersionNotAvailable,
166
+ };
167
+ if (fields) requestData.fields = fields;
168
+ if (types) requestData.types = types;
169
+ if (users) requestData.users = users;
170
+ let confirmationRequest = axios.post(`api/v1/trainingplans`, requestData, {
171
+ headers: { authorization: token },
181
172
  });
182
- },
173
+ confirmationRequest
174
+ .then((response) => {
175
+ resolve(response.data);
176
+ })
177
+ .catch((error) => {
178
+ reject(error);
179
+ });
180
+ });
181
+ };
183
182
 
184
- /**
185
- * Publish training plan
186
- * @param {String} id The id of the template to be published
187
- * @param {String} comment The comment to be include with the request
188
- * @param {String} token Authorization token
189
- */
190
- publishTrainingPlan: (id, comment, token) => {
191
- return new Promise(function (resolve, reject) {
192
- let data = {};
193
- if (comment) data.comment = comment;
194
- let confirmationRequest = axios.post(
195
- `api/v1/trainingplans/publish/${id}`,
196
- data,
197
- {
198
- headers: { authorization: token },
199
- }
200
- );
201
- confirmationRequest
202
- .then((response) => {
203
- resolve(response.data);
204
- })
205
- .catch((error) => {
206
- reject(error);
207
- });
208
- });
209
- },
183
+ /**
184
+ * Publish training plan
185
+ * @param {String} id The id of the template to be published
186
+ * @param {String} comment The comment to be include with the request
187
+ * @param {String} token Authorization token
188
+ */
189
+ export const publishTrainingPlan = (id, comment, token) => {
190
+ return new Promise(function (resolve, reject) {
191
+ let data = {};
192
+ if (comment) data.comment = comment;
193
+ let confirmationRequest = axios.post(
194
+ `api/v1/trainingplans/publish/${id}`,
195
+ data,
196
+ {
197
+ headers: { authorization: token },
198
+ }
199
+ );
200
+ confirmationRequest
201
+ .then((response) => {
202
+ resolve(response.data);
203
+ })
204
+ .catch((error) => {
205
+ reject(error);
206
+ });
207
+ });
208
+ };
210
209
 
211
- /**
212
- * Update training plan
213
- * @param {String} id The ID of the training plan
214
- * @param {Object} data The updated data
215
- * @param {String} token Authorization token
216
- */
217
- updateTrainingPlan: (planId, data, saveAsDraft, token) => {
218
- return new Promise(function (resolve, reject) {
219
- const requestData = {
220
- data: data,
221
- id: planId,
222
- saveAsDraft,
223
- };
224
- let confirmationRequest = axios.put(
225
- `api/v1/trainingplans/update/${planId}`,
226
- requestData,
227
- {
228
- headers: { authorization: token },
229
- }
230
- );
231
- confirmationRequest
232
- .then((response) => {
233
- resolve(response.data);
234
- })
235
- .catch((error) => {
236
- reject(error);
237
- });
238
- });
239
- },
210
+ /**
211
+ * Update training plan
212
+ * @param {String} id The ID of the training plan
213
+ * @param {Object} data The updated data
214
+ * @param {String} token Authorization token
215
+ */
216
+ export const updateTrainingPlan = (planId, data, saveAsDraft, token) => {
217
+ return new Promise(function (resolve, reject) {
218
+ const requestData = {
219
+ data: data,
220
+ id: planId,
221
+ saveAsDraft,
222
+ };
223
+ let confirmationRequest = axios.put(
224
+ `api/v1/trainingplans/update/${planId}`,
225
+ requestData,
226
+ {
227
+ headers: { authorization: token },
228
+ }
229
+ );
230
+ confirmationRequest
231
+ .then((response) => {
232
+ resolve(response.data);
233
+ })
234
+ .catch((error) => {
235
+ reject(error);
236
+ });
237
+ });
238
+ };
240
239
 
241
- /**
242
- * Update a task
243
- * @param {String} planId
244
- * @param {Object} data Ordered array of objects containing the activity Id and the new status
245
- * @param {Function} successCallBack
246
- * @param {Function} failCallBack
247
- * @returns {Object} An object containing the task information
248
- */
249
- updateActivities: (planId, data, token) => {
250
- return new Promise(function (resolve, reject) {
251
- let confirmationRequest = axios.post(
252
- `api/v1/trainingplans/${planId}/activities`,
253
- data,
254
- {
255
- headers: { authorization: token },
256
- }
257
- );
258
- confirmationRequest
259
- .then(() => {
260
- resolve();
261
- })
262
- .catch((error) => {
263
- reject(error);
264
- });
265
- });
266
- },
240
+ /**
241
+ * Update a task
242
+ * @param {String} planId
243
+ * @param {Object} data Ordered array of objects containing the activity Id and the new status
244
+ * @param {Function} successCallBack
245
+ * @param {Function} failCallBack
246
+ * @returns {Object} An object containing the task information
247
+ */
248
+ export const updateActivities = (planId, data, token) => {
249
+ return new Promise(function (resolve, reject) {
250
+ let confirmationRequest = axios.post(
251
+ `api/v1/trainingplans/${planId}/activities`,
252
+ data,
253
+ {
254
+ headers: { authorization: token },
255
+ }
256
+ );
257
+ confirmationRequest
258
+ .then(() => {
259
+ resolve();
260
+ })
261
+ .catch((error) => {
262
+ reject(error);
263
+ });
264
+ });
267
265
  };