@blazeo.com/calendar-client 1.0.11 → 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 +17 -6
- package/dist/index.mjs +17 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -551,16 +551,25 @@ EventModel.getByVisitorPhone = async (phone, opts = {}) => {
|
|
|
551
551
|
}
|
|
552
552
|
return null;
|
|
553
553
|
};
|
|
554
|
-
|
|
554
|
+
async function getByFiltersInternal(path, companyKey, opts = {}, dateRange = null) {
|
|
555
|
+
if (companyKey == null || String(companyKey).trim() === "") {
|
|
556
|
+
throw new Error("companyKey required");
|
|
557
|
+
}
|
|
555
558
|
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
556
559
|
const query = {
|
|
557
|
-
|
|
558
|
-
start_date_to: startDateTo
|
|
560
|
+
company_key: String(companyKey).trim()
|
|
559
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
|
+
}
|
|
560
569
|
const offset = opts.offset ?? getDefaultOffset();
|
|
561
|
-
if (opts.companyKey != null && opts.companyKey !== "") query.company_key = opts.companyKey;
|
|
562
570
|
if (opts.calendarId != null && opts.calendarId !== "") query.calendar_id = opts.calendarId;
|
|
563
571
|
if (opts.participantId != null && opts.participantId !== "") query.participant_id = opts.participantId;
|
|
572
|
+
if (opts.leadId != null && opts.leadId !== "") query.lead_id = opts.leadId;
|
|
564
573
|
if (opts.visitorName != null && opts.visitorName !== "") query.visitor_name = opts.visitorName;
|
|
565
574
|
if (opts.visitorEmail != null && opts.visitorEmail !== "") query.visitor_email = opts.visitorEmail;
|
|
566
575
|
if (opts.visitorPhone != null && opts.visitorPhone !== "") query.visitor_phone = opts.visitorPhone;
|
|
@@ -582,7 +591,7 @@ EventModel.getByDateRangeWithFilters = async (startDateFrom, startDateTo, opts =
|
|
|
582
591
|
if (opts.skip != null) query.skip = opts.skip;
|
|
583
592
|
if (opts.take != null) query.take = opts.take;
|
|
584
593
|
}
|
|
585
|
-
const res = await reqGet(
|
|
594
|
+
const res = await reqGet(path, query, { headers: { offset: String(offset) } });
|
|
586
595
|
if (res.status !== "success") {
|
|
587
596
|
return { events: [], totalCount: 0 };
|
|
588
597
|
}
|
|
@@ -592,7 +601,9 @@ EventModel.getByDateRangeWithFilters = async (startDateFrom, startDateTo, opts =
|
|
|
592
601
|
const totalCount = Number.isFinite(Number(totalCountRaw)) ? Number(totalCountRaw) : eventsRaw.length;
|
|
593
602
|
const events = eventsRaw.map((e) => EventModel.create(mapEventFromApi(e), { env: getConfig() }));
|
|
594
603
|
return { events, totalCount };
|
|
595
|
-
}
|
|
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);
|
|
596
607
|
EventModel.getAvailability = async (calendarId, year, month, day, opts = {}) => {
|
|
597
608
|
const { req } = createRequestHelpersFromEnv(getConfig());
|
|
598
609
|
const query = { calendar_id: calendarId, year, month, day };
|
package/dist/index.mjs
CHANGED
|
@@ -498,16 +498,25 @@ EventModel.getByVisitorPhone = async (phone, opts = {}) => {
|
|
|
498
498
|
}
|
|
499
499
|
return null;
|
|
500
500
|
};
|
|
501
|
-
|
|
501
|
+
async function getByFiltersInternal(path, companyKey, opts = {}, dateRange = null) {
|
|
502
|
+
if (companyKey == null || String(companyKey).trim() === "") {
|
|
503
|
+
throw new Error("companyKey required");
|
|
504
|
+
}
|
|
502
505
|
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
503
506
|
const query = {
|
|
504
|
-
|
|
505
|
-
start_date_to: startDateTo
|
|
507
|
+
company_key: String(companyKey).trim()
|
|
506
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
|
+
}
|
|
507
516
|
const offset = opts.offset ?? getDefaultOffset();
|
|
508
|
-
if (opts.companyKey != null && opts.companyKey !== "") query.company_key = opts.companyKey;
|
|
509
517
|
if (opts.calendarId != null && opts.calendarId !== "") query.calendar_id = opts.calendarId;
|
|
510
518
|
if (opts.participantId != null && opts.participantId !== "") query.participant_id = opts.participantId;
|
|
519
|
+
if (opts.leadId != null && opts.leadId !== "") query.lead_id = opts.leadId;
|
|
511
520
|
if (opts.visitorName != null && opts.visitorName !== "") query.visitor_name = opts.visitorName;
|
|
512
521
|
if (opts.visitorEmail != null && opts.visitorEmail !== "") query.visitor_email = opts.visitorEmail;
|
|
513
522
|
if (opts.visitorPhone != null && opts.visitorPhone !== "") query.visitor_phone = opts.visitorPhone;
|
|
@@ -529,7 +538,7 @@ EventModel.getByDateRangeWithFilters = async (startDateFrom, startDateTo, opts =
|
|
|
529
538
|
if (opts.skip != null) query.skip = opts.skip;
|
|
530
539
|
if (opts.take != null) query.take = opts.take;
|
|
531
540
|
}
|
|
532
|
-
const res = await reqGet(
|
|
541
|
+
const res = await reqGet(path, query, { headers: { offset: String(offset) } });
|
|
533
542
|
if (res.status !== "success") {
|
|
534
543
|
return { events: [], totalCount: 0 };
|
|
535
544
|
}
|
|
@@ -539,7 +548,9 @@ EventModel.getByDateRangeWithFilters = async (startDateFrom, startDateTo, opts =
|
|
|
539
548
|
const totalCount = Number.isFinite(Number(totalCountRaw)) ? Number(totalCountRaw) : eventsRaw.length;
|
|
540
549
|
const events = eventsRaw.map((e) => EventModel.create(mapEventFromApi(e), { env: getConfig() }));
|
|
541
550
|
return { events, totalCount };
|
|
542
|
-
}
|
|
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);
|
|
543
554
|
EventModel.getAvailability = async (calendarId, year, month, day, opts = {}) => {
|
|
544
555
|
const { req } = createRequestHelpersFromEnv(getConfig());
|
|
545
556
|
const query = { calendar_id: calendarId, year, month, day };
|