@itutoring/itutoring_application_js_api 1.23.1 → 1.24.0
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/apiController.js +46 -18
- package/modules/InquiryCheckout.js +1 -0
- package/objects/ApiFile.js +21 -0
- package/package.json +1 -1
package/apiController.js
CHANGED
|
@@ -239,10 +239,9 @@ class APIController
|
|
|
239
239
|
* @param module "Name of API module"
|
|
240
240
|
* @param method "Name of API method "
|
|
241
241
|
* @param data "data must be as array - key, value pair. They'll be passed into the request"
|
|
242
|
-
* @param file
|
|
243
242
|
* @returns "Response from server"
|
|
244
243
|
*/
|
|
245
|
-
static async Post(module, method, data,
|
|
244
|
+
static async Post(module, method, data, useCache = false)
|
|
246
245
|
{
|
|
247
246
|
if (useCache && APICache.IsCached(module + method))
|
|
248
247
|
{
|
|
@@ -254,16 +253,7 @@ class APIController
|
|
|
254
253
|
|
|
255
254
|
return new Promise(resolve =>
|
|
256
255
|
{
|
|
257
|
-
let formData =
|
|
258
|
-
if (file != null)
|
|
259
|
-
{
|
|
260
|
-
formData = new FormData();
|
|
261
|
-
formData.append("file", file);
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const args = APIController.GetArgsFromArray(data);
|
|
256
|
+
let formData = this.GetFormDataFromObject(data);
|
|
267
257
|
|
|
268
258
|
const request = new XMLHttpRequest();
|
|
269
259
|
request.withCredentials = true;
|
|
@@ -298,17 +288,52 @@ class APIController
|
|
|
298
288
|
if (this.UserSource != null)
|
|
299
289
|
request.setRequestHeader("visitor-source", this.UserSource);
|
|
300
290
|
|
|
301
|
-
|
|
291
|
+
request.send(formData);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
static GetFormDataFromObject(data)
|
|
296
|
+
{
|
|
297
|
+
let formData = new FormData();
|
|
298
|
+
// Extract ApiFiles from data and add them to formData
|
|
299
|
+
const files = this.GetApiFileFromObject(data);
|
|
300
|
+
Object.entries(files).forEach(([key, value]) =>
|
|
301
|
+
{
|
|
302
|
+
formData.append(key, value);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
// Search for objects and stringify them.
|
|
306
|
+
Object.entries(data).forEach(([key, value]) =>
|
|
307
|
+
{
|
|
308
|
+
if (typeof value === "object" && !(value instanceof File) && !(value instanceof ApiFile))
|
|
302
309
|
{
|
|
303
|
-
|
|
304
|
-
|
|
310
|
+
const files = this.GetApiFileFromObject(value);
|
|
311
|
+
Object.entries(files).forEach(([fKey, fValue]) =>
|
|
312
|
+
{
|
|
313
|
+
formData.append(fKey, fValue);
|
|
314
|
+
delete value[fKey];
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
let jsonVal = JSON.stringify(value);
|
|
318
|
+
formData.append(key, jsonVal);
|
|
305
319
|
}
|
|
306
|
-
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
return formData;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
static GetApiFileFromObject(data)
|
|
326
|
+
{
|
|
327
|
+
let fileAttributes = {};
|
|
328
|
+
Object.entries(data).forEach(([key, value]) =>
|
|
329
|
+
{
|
|
330
|
+
if (typeof value === "object" && value instanceof ApiFile)
|
|
307
331
|
{
|
|
308
|
-
|
|
309
|
-
request.send(args);
|
|
332
|
+
fileAttributes[key] = value.File;
|
|
310
333
|
}
|
|
311
334
|
});
|
|
335
|
+
|
|
336
|
+
return fileAttributes;
|
|
312
337
|
}
|
|
313
338
|
|
|
314
339
|
static GetArgsFromArray(args)
|
|
@@ -319,6 +344,9 @@ class APIController
|
|
|
319
344
|
{
|
|
320
345
|
for (const [key, value] of Object.entries(args))
|
|
321
346
|
{
|
|
347
|
+
if (typeof value === "object")
|
|
348
|
+
value = JSON.stringify(value);
|
|
349
|
+
|
|
322
350
|
argsString += key + "=" + value + "&";
|
|
323
351
|
}
|
|
324
352
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2026 iTutoring s.r.o.
|
|
3
|
+
*
|
|
4
|
+
* This source code is proprietary and confidential.
|
|
5
|
+
* Unauthorized copying, distribution, or disclosure is prohibited.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Use for sending files to API.
|
|
11
|
+
* ApiFile object can be added to any json data sent to API. It will be automatically converted to FormData and sent as multipart/form-data request.
|
|
12
|
+
* Server API will map this ApiFile to Api/File object
|
|
13
|
+
*/
|
|
14
|
+
class ApiFile
|
|
15
|
+
{
|
|
16
|
+
/**
|
|
17
|
+
* File object from input type=file
|
|
18
|
+
* @type {File}
|
|
19
|
+
*/
|
|
20
|
+
File;
|
|
21
|
+
}
|