@itutoring/itutoring_application_js_api 1.6.0 → 1.6.2
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 +14 -0
- package/modules/ReservationSystem.js +0 -240
- package/package.json +1 -1
package/apiController.js
CHANGED
|
@@ -224,6 +224,12 @@ class APIController
|
|
|
224
224
|
resolve(APIController.#R_KEY);
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
if (localStorage.getItem("r_key") !== null)
|
|
228
|
+
{
|
|
229
|
+
APIController.#R_KEY = localStorage.getItem("r_key");
|
|
230
|
+
resolve(APIController.#R_KEY);
|
|
231
|
+
}
|
|
232
|
+
|
|
227
233
|
// For localhost don't use xml config, but automatically
|
|
228
234
|
// return test key.
|
|
229
235
|
if (location.hostname === "localhost")
|
|
@@ -240,6 +246,7 @@ class APIController
|
|
|
240
246
|
const rKey = rKeyXML.getElementsByTagName("key")[0].childNodes[0].nodeValue;
|
|
241
247
|
|
|
242
248
|
APIController.#R_KEY = rKey;
|
|
249
|
+
localStorage.setItem("r_key", APIController.#R_KEY)
|
|
243
250
|
resolve(APIController.#R_KEY);
|
|
244
251
|
});
|
|
245
252
|
}
|
|
@@ -255,6 +262,12 @@ class APIController
|
|
|
255
262
|
resolve(APIController.#CLIENT_KEY);
|
|
256
263
|
}
|
|
257
264
|
|
|
265
|
+
if (localStorage.getItem("client_key") !== null)
|
|
266
|
+
{
|
|
267
|
+
APIController.#CLIENT_KEY = localStorage.getItem("client_key");
|
|
268
|
+
resolve(APIController.#CLIENT_KEY);
|
|
269
|
+
}
|
|
270
|
+
|
|
258
271
|
let keyPath = '/client_key.xml';
|
|
259
272
|
// For localhost use different xml file (to make suer we won't rewrite the server key when uploading websites)
|
|
260
273
|
if (location.hostname === "localhost")
|
|
@@ -269,6 +282,7 @@ class APIController
|
|
|
269
282
|
const key = keyXML.getElementsByTagName("key")[0].childNodes[0].nodeValue;
|
|
270
283
|
|
|
271
284
|
APIController.#CLIENT_KEY = key;
|
|
285
|
+
localStorage.setItem("client_key", APIController.#CLIENT_KEY)
|
|
272
286
|
resolve(APIController.#CLIENT_KEY);
|
|
273
287
|
});
|
|
274
288
|
|
|
@@ -9,21 +9,7 @@ class ReservationSystem
|
|
|
9
9
|
*/
|
|
10
10
|
static #MODULE = "ReservationSystem";
|
|
11
11
|
|
|
12
|
-
// All method names
|
|
13
|
-
static #GET_AVAILABILITY_FOR_DAY = "GetAvailabilityForDay";
|
|
14
|
-
static #GET_AVAILABILITY_FOR_MONTH = "GetAvailabilityForMonth";
|
|
15
|
-
static #IS_TIME_AVAILABLE = "IsTimeAvailable";
|
|
16
|
-
static #IS_DAY_AVAILABLE = "IsDayAvailable";
|
|
17
|
-
static #RESERVE_TIME = "ReserveTime";
|
|
18
|
-
static #BOOK = "Book";
|
|
19
|
-
static #ORDER_TIMEOUT = "OrderTimeout";
|
|
20
|
-
static #CONFIRM_RESERVATION = "ConfirmReservation";
|
|
21
|
-
static #GET_RESERVATION = "GetReservation";
|
|
22
|
-
static #IS_RESERVATION_PAID = "IsReservationPaid";
|
|
23
|
-
static #MARK_RESERVATION_PAID = "MarkReservationPaid";
|
|
24
|
-
static #RETRIVE_ORDER_ID = "RetriveOrderID";
|
|
25
12
|
static #SEND_REQUEST = "SendRequest";
|
|
26
|
-
|
|
27
13
|
static #ADD_ITEM_TO_CART = "AddItemToCart";
|
|
28
14
|
static #GET_CART_ITEMS = "GetCartItems";
|
|
29
15
|
static #GET_TOTAL_PRICE = "GetTotalPrice";
|
|
@@ -141,232 +127,6 @@ class ReservationSystem
|
|
|
141
127
|
return amounts;
|
|
142
128
|
}
|
|
143
129
|
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Returns availability for specific day and subject
|
|
147
|
-
* @param {*} date
|
|
148
|
-
* @param {*} subject
|
|
149
|
-
* @returns float in range 0...1
|
|
150
|
-
* @deprecated
|
|
151
|
-
*/
|
|
152
|
-
static async GetAvailabilityForDay(date, subject)
|
|
153
|
-
{
|
|
154
|
-
var data = await APIController.Get(this.#MODULE, this.#GET_AVAILABILITY_FOR_DAY, { 'date': date, 'subject': subject });
|
|
155
|
-
|
|
156
|
-
return parseFloat(data);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Get how much each day in month is free.
|
|
161
|
-
*
|
|
162
|
-
* @param {*} month month id (starts with 0 ends 11)
|
|
163
|
-
* @param {*} year
|
|
164
|
-
* @param {*} subject subject id
|
|
165
|
-
* @returns all values (in percent 0...1) by day ascending (1st .... 31st/30rd) as JSON string.
|
|
166
|
-
* @deprecated
|
|
167
|
-
*/
|
|
168
|
-
static async GetAvailabilityForMonth(month, year, subject)
|
|
169
|
-
{
|
|
170
|
-
var data = await APIController.Get(this.#MODULE, this.#GET_AVAILABILITY_FOR_MONTH,
|
|
171
|
-
{
|
|
172
|
-
'month': month,
|
|
173
|
-
'year': year,
|
|
174
|
-
'subject': subject,
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
return JSON.parse(data);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Check if specific start time is availiable.
|
|
182
|
-
* @param {*} date
|
|
183
|
-
* @param {*} subject
|
|
184
|
-
* @param {*} startTime
|
|
185
|
-
* @param {*} lessons number of lessons (1 = 60 mins, 2 = 2x60 mins)
|
|
186
|
-
* @returns bool
|
|
187
|
-
* @deprecated
|
|
188
|
-
*/
|
|
189
|
-
static async IsTimeAvailable(date, subject, startTime, lessons = 1)
|
|
190
|
-
{
|
|
191
|
-
var data = await APIController.Get(this.#MODULE, this.#IS_TIME_AVAILABLE, { 'date': date, 'subject': subject, 'start': startTime, "lessons": lessons });
|
|
192
|
-
|
|
193
|
-
return APIController.IntToBool(data);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Get all available times for specific day and subject
|
|
198
|
-
* @param {*} date
|
|
199
|
-
* @param {*} subject
|
|
200
|
-
* @param {*} lessons number of lessons (1 = 60 mins, 2 = 2x60 mins)
|
|
201
|
-
* @returns float array of available times
|
|
202
|
-
* @deprecated
|
|
203
|
-
*/
|
|
204
|
-
static async IsDayAvailable(date, subject, lessons = 1)
|
|
205
|
-
{
|
|
206
|
-
var availableTimes = await APIController.Get(this.#MODULE, this.#IS_DAY_AVAILABLE, { 'date': date, 'subject': subject, "lessons": lessons });
|
|
207
|
-
|
|
208
|
-
return JSON.parse(availableTimes);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Reserve time during creating order.
|
|
213
|
-
*
|
|
214
|
-
* Reserved time will have unique token.
|
|
215
|
-
*
|
|
216
|
-
* Is not needed to pass teacherId if you already calld GetTeacherForLesson. So teacher is already chosen and saved in session.
|
|
217
|
-
* @param {*} date
|
|
218
|
-
* @param {*} startTime
|
|
219
|
-
* @param {*} subject
|
|
220
|
-
* @param {*} lessons
|
|
221
|
-
* @param {*} teacherId
|
|
222
|
-
* @deprecated
|
|
223
|
-
*/
|
|
224
|
-
static async ReserveTime(date, startTime, subject, lessons, teacherId = "session")
|
|
225
|
-
{
|
|
226
|
-
var result = await APIController.Get(this.#MODULE, this.#RESERVE_TIME, {
|
|
227
|
-
'date': date,
|
|
228
|
-
'start': startTime,
|
|
229
|
-
'subject': subject,
|
|
230
|
-
'lessons': lessons,
|
|
231
|
-
'teacher': teacherId,
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
return parseInt(result);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Keep teacherId in reservation object null if you chosen teacher before
|
|
239
|
-
* @param {*} reservation
|
|
240
|
-
* @param {*} lessons
|
|
241
|
-
* @returns int (BookReturn)
|
|
242
|
-
* @deprecated
|
|
243
|
-
*/
|
|
244
|
-
static async Book(reservation, lessons)
|
|
245
|
-
{
|
|
246
|
-
if (!reservation.IsValid())
|
|
247
|
-
{
|
|
248
|
-
throw ("Reservation is not valid");
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
var reservationJSON = JSON.stringify(reservation);
|
|
252
|
-
|
|
253
|
-
var result = await APIController.Post(this.#MODULE, this.#BOOK, {
|
|
254
|
-
'reservation': encodeURIComponent(reservationJSON),
|
|
255
|
-
'lessons': lessons,
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
return result;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Return if reserved time in DB is still present.
|
|
263
|
-
*
|
|
264
|
-
* Need to be called after reserving time, so token is generated.
|
|
265
|
-
*
|
|
266
|
-
* Should be called before book to check that time.
|
|
267
|
-
* @returns true if is timeouted(time is deleted) , false if time is still there
|
|
268
|
-
* @deprecated
|
|
269
|
-
*/
|
|
270
|
-
static async OrderTimeout()
|
|
271
|
-
{
|
|
272
|
-
var res = await APIController.Get(this.#MODULE, this.#ORDER_TIMEOUT);
|
|
273
|
-
|
|
274
|
-
return APIController.IntToBool(res);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Send confirmation email to teacher and customer.
|
|
279
|
-
* @param {*} resend If true, the last send confirmation email will be resend. (just for the same session)
|
|
280
|
-
* @returns True if succeded
|
|
281
|
-
* @deprecated
|
|
282
|
-
*/
|
|
283
|
-
static async ConfirmReservation(resend = false)
|
|
284
|
-
{
|
|
285
|
-
var res = await APIController.Get(this.#MODULE, this.#CONFIRM_RESERVATION, { 'resend': APIController.BoolToInt(resend) });
|
|
286
|
-
|
|
287
|
-
return APIController.IntToBool(res);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Get reservation by id
|
|
292
|
-
* @param {*} id reservation id
|
|
293
|
-
* @returns Reservation object
|
|
294
|
-
* @deprecated
|
|
295
|
-
*/
|
|
296
|
-
static async GetReservation(id)
|
|
297
|
-
{
|
|
298
|
-
var res = await APIController.Get(this.#MODULE, this.#GET_RESERVATION, { 'id': id });
|
|
299
|
-
|
|
300
|
-
try
|
|
301
|
-
{
|
|
302
|
-
JSON.parse(res)
|
|
303
|
-
}
|
|
304
|
-
catch
|
|
305
|
-
{
|
|
306
|
-
return null;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
var reservationArray = JSON.parse(res);
|
|
310
|
-
|
|
311
|
-
var reservation = new Reservation();
|
|
312
|
-
reservation.Date = reservationArray['Date'];
|
|
313
|
-
reservation.StartTime = reservationArray['StartTime'];
|
|
314
|
-
reservation.Subject = reservationArray['Subject'];
|
|
315
|
-
reservation.TeacherId = reservationArray['TeacherId'];
|
|
316
|
-
reservation.Note = reservationArray['Note'];
|
|
317
|
-
reservation.FirstName = reservationArray['FirstName'];
|
|
318
|
-
reservation.LastName = reservationArray['LastName'];
|
|
319
|
-
reservation.Email = reservationArray['Email'];
|
|
320
|
-
|
|
321
|
-
return reservation;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* Check if reservation has been paid
|
|
326
|
-
* @param {*} id reservation id
|
|
327
|
-
* @returns
|
|
328
|
-
* @deprecated
|
|
329
|
-
*/
|
|
330
|
-
static async IsReservationPaid(id)
|
|
331
|
-
{
|
|
332
|
-
var res = await APIController.Get(this.#MODULE, this.#IS_RESERVATION_PAID, { 'id': id })
|
|
333
|
-
|
|
334
|
-
return APIController.IntToBool(res);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Will mark reservation as paid. Must provide transaction id for that reservation to confirm that it was paid.
|
|
339
|
-
* @param {*} reservationId
|
|
340
|
-
* @param {*} transactionId
|
|
341
|
-
* @returns bool
|
|
342
|
-
* @deprecated
|
|
343
|
-
*/
|
|
344
|
-
static async MarkReservationPaid(reservationId, transactionId)
|
|
345
|
-
{
|
|
346
|
-
var res = await APIController.Get(this.#MODULE, this.#MARK_RESERVATION_PAID, {
|
|
347
|
-
'reservationId': reservationId,
|
|
348
|
-
'transactionId': transactionId,
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
return APIController.IntToBool(res);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Get latest order id. Works for both Lessons and courses.
|
|
356
|
-
*
|
|
357
|
-
* Book function must be called before. ID is stored in session.
|
|
358
|
-
*
|
|
359
|
-
* @returns orderId
|
|
360
|
-
*
|
|
361
|
-
* @deprecated
|
|
362
|
-
*/
|
|
363
|
-
static async RetriveOrderID()
|
|
364
|
-
{
|
|
365
|
-
var id = await APIController.Get(this.#MODULE, this.#RETRIVE_ORDER_ID);
|
|
366
|
-
|
|
367
|
-
return id;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
130
|
/**
|
|
371
131
|
* Send request for tutoring. Will register as event
|
|
372
132
|
* @param {*} name
|