@blazeo.com/calendar-client 1.0.12 → 1.0.13
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/index.js +13 -6
- package/dist/index.mjs +13 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -551,16 +551,21 @@ EventModel.getByVisitorPhone = async (phone, opts = {}) => {
|
|
|
551
551
|
}
|
|
552
552
|
return null;
|
|
553
553
|
};
|
|
554
|
-
|
|
554
|
+
async function getByFiltersInternal(path, companyKey, opts = {}, dateRange = null) {
|
|
555
555
|
if (companyKey == null || String(companyKey).trim() === "") {
|
|
556
556
|
throw new Error("companyKey required");
|
|
557
557
|
}
|
|
558
558
|
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
559
559
|
const query = {
|
|
560
|
-
company_key: String(companyKey).trim()
|
|
561
|
-
start_date_from: startDateFrom,
|
|
562
|
-
start_date_to: startDateTo
|
|
560
|
+
company_key: String(companyKey).trim()
|
|
563
561
|
};
|
|
562
|
+
if (dateRange) {
|
|
563
|
+
if (dateRange.startDateFrom == null || dateRange.startDateTo == null) {
|
|
564
|
+
throw new Error("startDateFrom and startDateTo required");
|
|
565
|
+
}
|
|
566
|
+
query.start_date_from = dateRange.startDateFrom;
|
|
567
|
+
query.start_date_to = dateRange.startDateTo;
|
|
568
|
+
}
|
|
564
569
|
const offset = opts.offset ?? getDefaultOffset();
|
|
565
570
|
if (opts.calendarId != null && opts.calendarId !== "") query.calendar_id = opts.calendarId;
|
|
566
571
|
if (opts.participantId != null && opts.participantId !== "") query.participant_id = opts.participantId;
|
|
@@ -586,7 +591,7 @@ EventModel.getByDateRangeWithFilters = async (companyKey, startDateFrom, startDa
|
|
|
586
591
|
if (opts.skip != null) query.skip = opts.skip;
|
|
587
592
|
if (opts.take != null) query.take = opts.take;
|
|
588
593
|
}
|
|
589
|
-
const res = await reqGet(
|
|
594
|
+
const res = await reqGet(path, query, { headers: { offset: String(offset) } });
|
|
590
595
|
if (res.status !== "success") {
|
|
591
596
|
return { events: [], totalCount: 0 };
|
|
592
597
|
}
|
|
@@ -596,7 +601,9 @@ EventModel.getByDateRangeWithFilters = async (companyKey, startDateFrom, startDa
|
|
|
596
601
|
const totalCount = Number.isFinite(Number(totalCountRaw)) ? Number(totalCountRaw) : eventsRaw.length;
|
|
597
602
|
const events = eventsRaw.map((e) => EventModel.create(mapEventFromApi(e), { env: getConfig() }));
|
|
598
603
|
return { events, totalCount };
|
|
599
|
-
}
|
|
604
|
+
}
|
|
605
|
+
EventModel.getByDateRangeWithFilters = async (companyKey, startDateFrom, startDateTo, opts = {}) => getByFiltersInternal("/event/search/daterange/get", companyKey, opts, { startDateFrom, startDateTo });
|
|
606
|
+
EventModel.getByFilters = async (companyKey, opts = {}) => getByFiltersInternal("/event/search/get", companyKey, opts);
|
|
600
607
|
EventModel.getAvailability = async (calendarId, year, month, day, opts = {}) => {
|
|
601
608
|
const { req } = createRequestHelpersFromEnv(getConfig());
|
|
602
609
|
const query = { calendar_id: calendarId, year, month, day };
|
package/dist/index.mjs
CHANGED
|
@@ -498,16 +498,21 @@ EventModel.getByVisitorPhone = async (phone, opts = {}) => {
|
|
|
498
498
|
}
|
|
499
499
|
return null;
|
|
500
500
|
};
|
|
501
|
-
|
|
501
|
+
async function getByFiltersInternal(path, companyKey, opts = {}, dateRange = null) {
|
|
502
502
|
if (companyKey == null || String(companyKey).trim() === "") {
|
|
503
503
|
throw new Error("companyKey required");
|
|
504
504
|
}
|
|
505
505
|
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
506
506
|
const query = {
|
|
507
|
-
company_key: String(companyKey).trim()
|
|
508
|
-
start_date_from: startDateFrom,
|
|
509
|
-
start_date_to: startDateTo
|
|
507
|
+
company_key: String(companyKey).trim()
|
|
510
508
|
};
|
|
509
|
+
if (dateRange) {
|
|
510
|
+
if (dateRange.startDateFrom == null || dateRange.startDateTo == null) {
|
|
511
|
+
throw new Error("startDateFrom and startDateTo required");
|
|
512
|
+
}
|
|
513
|
+
query.start_date_from = dateRange.startDateFrom;
|
|
514
|
+
query.start_date_to = dateRange.startDateTo;
|
|
515
|
+
}
|
|
511
516
|
const offset = opts.offset ?? getDefaultOffset();
|
|
512
517
|
if (opts.calendarId != null && opts.calendarId !== "") query.calendar_id = opts.calendarId;
|
|
513
518
|
if (opts.participantId != null && opts.participantId !== "") query.participant_id = opts.participantId;
|
|
@@ -533,7 +538,7 @@ EventModel.getByDateRangeWithFilters = async (companyKey, startDateFrom, startDa
|
|
|
533
538
|
if (opts.skip != null) query.skip = opts.skip;
|
|
534
539
|
if (opts.take != null) query.take = opts.take;
|
|
535
540
|
}
|
|
536
|
-
const res = await reqGet(
|
|
541
|
+
const res = await reqGet(path, query, { headers: { offset: String(offset) } });
|
|
537
542
|
if (res.status !== "success") {
|
|
538
543
|
return { events: [], totalCount: 0 };
|
|
539
544
|
}
|
|
@@ -543,7 +548,9 @@ EventModel.getByDateRangeWithFilters = async (companyKey, startDateFrom, startDa
|
|
|
543
548
|
const totalCount = Number.isFinite(Number(totalCountRaw)) ? Number(totalCountRaw) : eventsRaw.length;
|
|
544
549
|
const events = eventsRaw.map((e) => EventModel.create(mapEventFromApi(e), { env: getConfig() }));
|
|
545
550
|
return { events, totalCount };
|
|
546
|
-
}
|
|
551
|
+
}
|
|
552
|
+
EventModel.getByDateRangeWithFilters = async (companyKey, startDateFrom, startDateTo, opts = {}) => getByFiltersInternal("/event/search/daterange/get", companyKey, opts, { startDateFrom, startDateTo });
|
|
553
|
+
EventModel.getByFilters = async (companyKey, opts = {}) => getByFiltersInternal("/event/search/get", companyKey, opts);
|
|
547
554
|
EventModel.getAvailability = async (calendarId, year, month, day, opts = {}) => {
|
|
548
555
|
const { req } = createRequestHelpersFromEnv(getConfig());
|
|
549
556
|
const query = { calendar_id: calendarId, year, month, day };
|