@blazeo.com/calendar-client 1.0.1 → 1.0.3
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/README.md +15 -44
- package/dist/index.d.ts +101 -741
- package/dist/index.js +1320 -501
- package/dist/index.mjs +1309 -498
- package/package.json +3 -7
- package/dist/index.d.mts +0 -741
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -17,296 +16,165 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
16
|
};
|
|
18
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
18
|
|
|
20
|
-
// src/index.
|
|
19
|
+
// src/models/appointment/index.js
|
|
21
20
|
var index_exports = {};
|
|
22
21
|
__export(index_exports, {
|
|
23
|
-
AppointmentClient: () => AppointmentClient,
|
|
24
22
|
AssignmentMethod: () => AssignmentMethod,
|
|
25
23
|
AttendeeStatus: () => AttendeeStatus,
|
|
26
24
|
AvailabilityDetailModel: () => AvailabilityDetail_default,
|
|
27
25
|
AvailabilityModel: () => Availability_default,
|
|
26
|
+
CalendarDayModel: () => CalendarDay_default,
|
|
28
27
|
CalendarModel: () => Calendar_default,
|
|
29
28
|
CalendarParticipantModel: () => CalendarParticipant_default,
|
|
29
|
+
CompanyModel: () => Company_default,
|
|
30
|
+
ConfigModel: () => ConfigModel_default,
|
|
30
31
|
DayOfWeek: () => DayOfWeek,
|
|
31
32
|
EventModel: () => Event_default,
|
|
32
33
|
OpeningHourModel: () => OpeningHour_default,
|
|
34
|
+
ParticipantInfoModel: () => ParticipantInfo_default,
|
|
33
35
|
ParticipantModel: () => Participant_default,
|
|
36
|
+
PreferenceModel: () => Preference_default,
|
|
37
|
+
PreferenceScope: () => PreferenceScope,
|
|
34
38
|
RecurringFrequency: () => RecurringFrequency,
|
|
35
39
|
RootStore: () => RootStore,
|
|
36
40
|
SettingModel: () => Setting_default,
|
|
37
41
|
TimeFrameModel: () => TimeFrame_default,
|
|
38
42
|
TimeSlotModel: () => TimeSlot_default,
|
|
39
43
|
Unit: () => Unit,
|
|
40
|
-
|
|
44
|
+
configure: () => configure,
|
|
45
|
+
createRootStore: () => createRootStore,
|
|
46
|
+
getConfig: () => getConfig,
|
|
47
|
+
getConfigStore: () => getConfigStore,
|
|
48
|
+
setBaseUrl: () => setBaseUrl
|
|
41
49
|
});
|
|
42
50
|
module.exports = __toCommonJS(index_exports);
|
|
43
51
|
|
|
44
|
-
// src/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
// src/models/appointment/Calendar.js
|
|
53
|
+
var import_mobx_state_tree7 = require("mobx-state-tree");
|
|
54
|
+
|
|
55
|
+
// src/ConfigModel.js
|
|
56
|
+
var import_mobx_state_tree = require("mobx-state-tree");
|
|
57
|
+
var ConfigModel = import_mobx_state_tree.types.model("Config", {
|
|
58
|
+
baseUrl: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.string, "")
|
|
59
|
+
}).volatile(() => ({
|
|
60
|
+
fetch: void 0,
|
|
61
|
+
getDefaultOffset: () => -(/* @__PURE__ */ new Date()).getTimezoneOffset()
|
|
62
|
+
})).actions((self) => ({
|
|
63
|
+
setBaseUrl(url) {
|
|
64
|
+
self.baseUrl = url;
|
|
65
|
+
},
|
|
66
|
+
setFetch(fn) {
|
|
67
|
+
self.fetch = fn;
|
|
68
|
+
},
|
|
69
|
+
setGetDefaultOffset(fn) {
|
|
70
|
+
self.getDefaultOffset = fn;
|
|
71
|
+
},
|
|
72
|
+
configure(env) {
|
|
73
|
+
if (env.baseUrl != null) self.baseUrl = env.baseUrl;
|
|
74
|
+
if (env.fetch != null) self.fetch = env.fetch;
|
|
75
|
+
if (env.getDefaultOffset != null) self.getDefaultOffset = env.getDefaultOffset;
|
|
49
76
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (!Number.isNaN(n)) return n;
|
|
58
|
-
}
|
|
77
|
+
})).views((self) => ({
|
|
78
|
+
getEnv() {
|
|
79
|
+
return {
|
|
80
|
+
baseUrl: self.baseUrl || void 0,
|
|
81
|
+
fetch: self.fetch,
|
|
82
|
+
getDefaultOffset: self.getDefaultOffset
|
|
83
|
+
};
|
|
59
84
|
}
|
|
60
|
-
|
|
85
|
+
}));
|
|
86
|
+
var _instance = null;
|
|
87
|
+
function getConfigStore() {
|
|
88
|
+
if (!_instance) _instance = ConfigModel.create({});
|
|
89
|
+
return _instance;
|
|
61
90
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
91
|
+
var ConfigModel_default = ConfigModel;
|
|
92
|
+
|
|
93
|
+
// src/config.js
|
|
94
|
+
function configure(env) {
|
|
95
|
+
const store = getConfigStore();
|
|
96
|
+
store.configure(env);
|
|
67
97
|
}
|
|
68
|
-
function
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const visitorPhone = pickStr(input, "visitorPhone", "visitor_phone") ?? "";
|
|
73
|
-
const startDateStr = pickStr(input, "startDate", "start_date");
|
|
74
|
-
const endDateStr = pickStr(input, "endDate", "end_date");
|
|
75
|
-
const startHour = pickNum(input, "startHour", "start_hour") ?? 0;
|
|
76
|
-
const startMinute = pickNum(input, "startMinute", "start_minute") ?? 0;
|
|
77
|
-
const endHour = pickNum(input, "endHour", "end_hour") ?? startHour;
|
|
78
|
-
const endMinute = pickNum(input, "endMinute", "end_minute") ?? startMinute;
|
|
79
|
-
let startDate = parseDate(startDateStr);
|
|
80
|
-
let parsedStartHour = startHour;
|
|
81
|
-
let parsedStartMinute = startMinute;
|
|
82
|
-
const startTime = pickStr(input, "startTime", "start_time");
|
|
83
|
-
if (startTime && /^\d{1,2}:\d{2}$/.test(startTime)) {
|
|
84
|
-
const [h, m] = startTime.split(":").map(Number);
|
|
85
|
-
parsedStartHour = h;
|
|
86
|
-
parsedStartMinute = m;
|
|
87
|
-
}
|
|
88
|
-
const endDate = endDateStr ? parseDate(endDateStr) : startDate;
|
|
89
|
-
const rawParticipantId = input.participantId ?? input.participant_id;
|
|
90
|
-
const participantId = rawParticipantId == null ? null : typeof rawParticipantId === "string" ? rawParticipantId : String(rawParticipantId);
|
|
91
|
-
return {
|
|
92
|
-
calendarId,
|
|
93
|
-
participantId,
|
|
94
|
-
title: input.title ?? "",
|
|
95
|
-
description: input.description ?? "",
|
|
96
|
-
startDate,
|
|
97
|
-
endDate,
|
|
98
|
-
startHour: parsedStartHour,
|
|
99
|
-
startMinute: parsedStartMinute,
|
|
100
|
-
endHour,
|
|
101
|
-
endMinute,
|
|
102
|
-
visitorName,
|
|
103
|
-
visitorEmail,
|
|
104
|
-
visitorPhone,
|
|
105
|
-
isRecurring: false,
|
|
106
|
-
recurringFrequency: 0
|
|
107
|
-
};
|
|
98
|
+
function getConfig() {
|
|
99
|
+
const store = getConfigStore();
|
|
100
|
+
if (!store.baseUrl) return null;
|
|
101
|
+
return store.getEnv();
|
|
108
102
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
function normalizeBaseUrl(baseUrl) {
|
|
112
|
-
return baseUrl.replace(/\/+$/, "");
|
|
103
|
+
function setBaseUrl(baseUrl) {
|
|
104
|
+
getConfigStore().setBaseUrl(baseUrl);
|
|
113
105
|
}
|
|
106
|
+
|
|
107
|
+
// src/apiRequest.js
|
|
114
108
|
function buildQuery(params) {
|
|
115
109
|
const search = new URLSearchParams();
|
|
116
|
-
for (const [k, v] of Object.entries(params)) {
|
|
110
|
+
for (const [k, v] of Object.entries(params || {})) {
|
|
117
111
|
if (v === void 0 || v === null) continue;
|
|
118
|
-
|
|
112
|
+
if (Array.isArray(v)) {
|
|
113
|
+
for (const item of v) search.append(k, String(item));
|
|
114
|
+
} else {
|
|
115
|
+
search.set(k, String(v));
|
|
116
|
+
}
|
|
119
117
|
}
|
|
120
118
|
const q = search.toString();
|
|
121
119
|
return q ? `?${q}` : "";
|
|
122
120
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
"Content-Type": "application/json",
|
|
136
|
-
...headers
|
|
137
|
-
};
|
|
138
|
-
const res = await this.fetchFn(url, { method, headers: reqHeaders, body });
|
|
139
|
-
const text = await res.text();
|
|
140
|
-
let data;
|
|
141
|
-
try {
|
|
142
|
-
data = JSON.parse(text);
|
|
143
|
-
} catch {
|
|
144
|
-
data = { status: "failure", message: text || res.statusText };
|
|
145
|
-
}
|
|
146
|
-
if (!res.ok && data.status !== "failure") {
|
|
147
|
-
data.status = "failure";
|
|
148
|
-
data.message = data.message ?? `HTTP ${res.status}`;
|
|
149
|
-
}
|
|
150
|
-
return data;
|
|
151
|
-
}
|
|
152
|
-
// ---------- Event ----------
|
|
153
|
-
/** GET /event/get – by event_id or externalevent_id */
|
|
154
|
-
async getEvent(params) {
|
|
155
|
-
if (params.eventId ?? params.event_id) {
|
|
156
|
-
return this.request("/event/get", {
|
|
157
|
-
query: { event_id: params.eventId ?? params.event_id }
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
if (params.externalEventId ?? params.externalevent_id) {
|
|
161
|
-
return this.request("/event/get", {
|
|
162
|
-
query: { externalevent_id: params.externalEventId ?? params.externalevent_id }
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
return Promise.resolve({ status: "failure", message: "Provide eventId or externalEventId" });
|
|
166
|
-
}
|
|
167
|
-
/** GET /event/availability/get – slots for a day. Optional participant_id. */
|
|
168
|
-
async getAvailability(params) {
|
|
169
|
-
const calendarId = params.calendarId ?? params.calendar_id;
|
|
170
|
-
const offset = params.offset;
|
|
171
|
-
const query = {
|
|
172
|
-
calendar_id: calendarId,
|
|
173
|
-
year: params.year,
|
|
174
|
-
month: params.month,
|
|
175
|
-
day: params.day
|
|
176
|
-
};
|
|
177
|
-
if (params.participantId ?? params.participant_id) {
|
|
178
|
-
query.participant_id = params.participantId ?? params.participant_id;
|
|
179
|
-
}
|
|
180
|
-
return this.request("/event/availability/get", {
|
|
181
|
-
headers: { offset: String(offset) },
|
|
182
|
-
query
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
/** GET /event/day/selectable/get – whether the day has any slots. Optional participant_id. */
|
|
186
|
-
async getDaySelectable(params) {
|
|
187
|
-
const calendarId = params.calendarId ?? params.calendar_id;
|
|
188
|
-
const query = {
|
|
189
|
-
calendar_id: calendarId,
|
|
190
|
-
year: params.year,
|
|
191
|
-
month: params.month,
|
|
192
|
-
day: params.day
|
|
193
|
-
};
|
|
194
|
-
if (params.participantId ?? params.participant_id) {
|
|
195
|
-
query.participant_id = params.participantId ?? params.participant_id;
|
|
196
|
-
}
|
|
197
|
-
const res = await this.request("/event/day/selectable/get", {
|
|
198
|
-
headers: { offset: String(params.offset) },
|
|
199
|
-
query
|
|
200
|
-
});
|
|
201
|
-
if (res.data !== void 0) return { ...res, data: Boolean(res.data) };
|
|
202
|
-
return res;
|
|
203
|
-
}
|
|
204
|
-
/** GET /event/days/available/get – list of next N available days (yyyy-MM-dd). */
|
|
205
|
-
async getEarliestAvailableDays(params) {
|
|
206
|
-
const calendarId = params.calendarId ?? params.calendar_id;
|
|
207
|
-
const query = {
|
|
208
|
-
calendar_id: calendarId,
|
|
209
|
-
count: params.count
|
|
210
|
-
};
|
|
211
|
-
if (params.year != null) query.year = params.year;
|
|
212
|
-
if (params.month != null) query.month = params.month;
|
|
213
|
-
if (params.day != null) query.day = params.day;
|
|
214
|
-
return this.request("/event/days/available/get", {
|
|
215
|
-
headers: { offset: String(params.offset) },
|
|
216
|
-
query
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
/** GET /event/existing/getbyvisitoremail – by company_key or calendar_id */
|
|
220
|
-
async getExistingEventsByVisitorEmail(params) {
|
|
221
|
-
const query = {
|
|
222
|
-
email: params.email,
|
|
223
|
-
offset: params.offset
|
|
224
|
-
};
|
|
225
|
-
if (params.companyKey ?? params.company_key) query.company_key = params.companyKey ?? params.company_key;
|
|
226
|
-
if (params.calendarId ?? params.calendar_id) query.calendar_id = params.calendarId ?? params.calendar_id;
|
|
227
|
-
return this.request("/event/existing/getbyvisitoremail", {
|
|
228
|
-
headers: { offset: String(params.offset) },
|
|
229
|
-
query
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
/** GET /event/existing/getbyvisitorphone – by company_key or calendar_id */
|
|
233
|
-
async getExistingEventsByVisitorPhone(params) {
|
|
234
|
-
const query = {
|
|
235
|
-
phone: params.phone,
|
|
236
|
-
offset: params.offset
|
|
237
|
-
};
|
|
238
|
-
if (params.companyKey ?? params.company_key) query.company_key = params.companyKey ?? params.company_key;
|
|
239
|
-
if (params.calendarId ?? params.calendar_id) query.calendar_id = params.calendarId ?? params.calendar_id;
|
|
240
|
-
return this.request("/event/existing/getbyvisitorphone", {
|
|
241
|
-
headers: { offset: String(params.offset) },
|
|
242
|
-
query
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
/** POST /event/create – create event. Accepts flexible input; maps to backend shape. */
|
|
246
|
-
async createEvent(input, offsetMinutes) {
|
|
247
|
-
const offset = offsetMinutes ?? this.getDefaultOffset();
|
|
248
|
-
const body = mapCreateEventInputToEvent(input);
|
|
249
|
-
return this.request("/event/create", {
|
|
250
|
-
method: "POST",
|
|
251
|
-
headers: { offset: String(offset) },
|
|
252
|
-
body: JSON.stringify(body)
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
/** GET /event/cancel – cancel by event_id */
|
|
256
|
-
async cancelEvent(eventId) {
|
|
257
|
-
return this.request("/event/cancel", { query: { event_id: eventId } });
|
|
258
|
-
}
|
|
259
|
-
/** GET /event/cancellable – check if event can be cancelled */
|
|
260
|
-
async getCancellable(eventId) {
|
|
261
|
-
const res = await this.request("/event/cancellable", { query: { event_id: eventId } });
|
|
262
|
-
if (res.data !== void 0) return { ...res, data: Boolean(res.data) };
|
|
263
|
-
return res;
|
|
264
|
-
}
|
|
265
|
-
/** GET /event/participant/roundrobin/get – get assignable participant for calendar */
|
|
266
|
-
async getRoundRobinParticipant(calendarId) {
|
|
267
|
-
return this.request("/event/participant/roundrobin/get", {
|
|
268
|
-
query: { calendar_id: calendarId }
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
/** GET /event/attendeeStatus – set attendee status (route: /event/{eventId}/{attendeeStatus}) */
|
|
272
|
-
async setAttendeeStatus(eventId, attendeeStatus) {
|
|
273
|
-
return this.request(`/event/${encodeURIComponent(eventId)}/${encodeURIComponent(attendeeStatus)}`);
|
|
274
|
-
}
|
|
275
|
-
/** GET /event/seteventreminder/{event_id} */
|
|
276
|
-
async setEventReminder(eventId) {
|
|
277
|
-
return this.request(`/event/seteventreminder/${encodeURIComponent(eventId)}`);
|
|
278
|
-
}
|
|
279
|
-
// ---------- Calendar ----------
|
|
280
|
-
/** GET Calendar/Get – get calendar by calendar_id */
|
|
281
|
-
async getCalendar(calendarId) {
|
|
282
|
-
return this.request("/Calendar/Get", { query: { calendar_id: calendarId } });
|
|
283
|
-
}
|
|
284
|
-
/** GET Calendar/All – calendars by company_key */
|
|
285
|
-
async getCalendarsByCompany(companyKey) {
|
|
286
|
-
return this.request("/Calendar/All", { query: { company_key: companyKey } });
|
|
287
|
-
}
|
|
288
|
-
/** GET Calendar/TimeZones/Get */
|
|
289
|
-
async getTimeZones() {
|
|
290
|
-
return this.request("/Calendar/TimeZones/Get");
|
|
291
|
-
}
|
|
292
|
-
/** GET Calendar/TimeZone/Get – display name for timezone_id */
|
|
293
|
-
async getTimeZone(timezoneId) {
|
|
294
|
-
return this.request("/Calendar/TimeZone/Get", { query: { timezone_id: timezoneId } });
|
|
295
|
-
}
|
|
296
|
-
/** POST Calendar/Create – create or update calendar */
|
|
297
|
-
async createCalendar(payload) {
|
|
298
|
-
return this.request("/Calendar/Create", { method: "POST", body: JSON.stringify(payload) });
|
|
299
|
-
}
|
|
300
|
-
/** GET Calendar/Remove */
|
|
301
|
-
async removeCalendar(calendarId) {
|
|
302
|
-
return this.request(`/Calendar/Remove`, { query: { calendar_id: calendarId } });
|
|
121
|
+
async function request(baseUrl, fetchFn, path, options = {}) {
|
|
122
|
+
const { method = "GET", headers = {}, body, query, skipContentType } = options;
|
|
123
|
+
const url = `${String(baseUrl).replace(/\/+$/, "")}${path}${buildQuery(query)}`;
|
|
124
|
+
const reqHeaders = { ...headers };
|
|
125
|
+
if (!skipContentType && typeof body === "string") reqHeaders["Content-Type"] = "application/json";
|
|
126
|
+
const res = await fetchFn(url, { method, headers: reqHeaders, body });
|
|
127
|
+
const text = await res.text();
|
|
128
|
+
let data;
|
|
129
|
+
try {
|
|
130
|
+
data = JSON.parse(text);
|
|
131
|
+
} catch {
|
|
132
|
+
data = { status: "failure", message: text || res.statusText };
|
|
303
133
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
134
|
+
if (!res.ok && data.status !== "failure") {
|
|
135
|
+
data.status = "failure";
|
|
136
|
+
data.message = data.message ?? `HTTP ${res.status}`;
|
|
137
|
+
}
|
|
138
|
+
return data;
|
|
139
|
+
}
|
|
140
|
+
function createRequestHelpers(self, getEnv7) {
|
|
141
|
+
const env = () => getEnv7(self);
|
|
142
|
+
const baseUrl = () => env().baseUrl;
|
|
143
|
+
const fetchFn = () => env().fetch ?? (typeof fetch !== "undefined" ? fetch : () => {
|
|
144
|
+
throw new Error("fetch not available");
|
|
145
|
+
});
|
|
146
|
+
const req = (path, opts = {}) => {
|
|
147
|
+
const url = baseUrl();
|
|
148
|
+
if (!url) throw new Error("Model env requires baseUrl. Call configure({ baseUrl }) at app startup.");
|
|
149
|
+
return request(url, fetchFn(), path, opts);
|
|
150
|
+
};
|
|
151
|
+
return {
|
|
152
|
+
req,
|
|
153
|
+
reqGet: (path, query, opts = {}) => req(path, { ...opts, query }),
|
|
154
|
+
reqPost: (path, body, query, opts = {}) => req(path, { ...opts, method: "POST", body: JSON.stringify(body), query })
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function createRequestHelpersFromEnv(env) {
|
|
158
|
+
const e = env ?? getConfig();
|
|
159
|
+
if (!e) throw new Error("Env required. Pass env to the method or call configure({ baseUrl }) at app startup.");
|
|
160
|
+
const baseUrl = () => e == null ? void 0 : e.baseUrl;
|
|
161
|
+
const fetchFn = () => (e == null ? void 0 : e.fetch) ?? (typeof fetch !== "undefined" ? fetch : () => {
|
|
162
|
+
throw new Error("fetch not available");
|
|
163
|
+
});
|
|
164
|
+
const req = (path, opts = {}) => {
|
|
165
|
+
const url = baseUrl();
|
|
166
|
+
if (!url) throw new Error("Env requires baseUrl. Call configure({ baseUrl }) at app startup.");
|
|
167
|
+
return request(url, fetchFn(), path, opts);
|
|
168
|
+
};
|
|
169
|
+
return {
|
|
170
|
+
env: e,
|
|
171
|
+
req,
|
|
172
|
+
reqGet: (path, query, opts = {}) => req(path, { ...opts, query }),
|
|
173
|
+
reqPost: (path, body, query, opts = {}) => req(path, { ...opts, method: "POST", body: JSON.stringify(body), query })
|
|
174
|
+
};
|
|
175
|
+
}
|
|
308
176
|
|
|
309
|
-
// src/models/appointment/enums.
|
|
177
|
+
// src/models/appointment/enums.js
|
|
310
178
|
var Unit = {
|
|
311
179
|
Minutes: 1,
|
|
312
180
|
Hours: 2,
|
|
@@ -344,264 +212,991 @@ var DayOfWeek = {
|
|
|
344
212
|
Saturday: 6
|
|
345
213
|
};
|
|
346
214
|
|
|
347
|
-
// src/models/appointment/
|
|
348
|
-
var
|
|
349
|
-
id: import_mobx_state_tree.types.maybeNull(import_mobx_state_tree.types.number),
|
|
350
|
-
companyKey: import_mobx_state_tree.types.maybeNull(import_mobx_state_tree.types.string),
|
|
351
|
-
calendarId: import_mobx_state_tree.types.identifier,
|
|
352
|
-
name: import_mobx_state_tree.types.maybeNull(import_mobx_state_tree.types.string),
|
|
353
|
-
location: import_mobx_state_tree.types.maybeNull(import_mobx_state_tree.types.string),
|
|
354
|
-
timeZoneId: import_mobx_state_tree.types.maybeNull(import_mobx_state_tree.types.string),
|
|
355
|
-
purpose: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.string, ""),
|
|
356
|
-
description: import_mobx_state_tree.types.maybeNull(import_mobx_state_tree.types.string),
|
|
357
|
-
assignmentMethod: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, AssignmentMethod.RoundRobin),
|
|
358
|
-
duration: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, 0),
|
|
359
|
-
durationUnit: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, Unit.Minutes),
|
|
360
|
-
minimumBookingNotice: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, 0),
|
|
361
|
-
minimumBookingNoticeUnit: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, Unit.Minutes),
|
|
362
|
-
minimumCancelationNotice: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, 0),
|
|
363
|
-
minimumCancelationNoticeUnit: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, Unit.Minutes),
|
|
364
|
-
futureLimit: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, 0),
|
|
365
|
-
futureLimitUnit: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, Unit.Days),
|
|
366
|
-
bufferTime: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, 0),
|
|
367
|
-
bufferTimeUnit: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, Unit.Minutes),
|
|
368
|
-
bookingLimit: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, 0),
|
|
369
|
-
createdOn: import_mobx_state_tree.types.maybeNull(import_mobx_state_tree.types.string),
|
|
370
|
-
modifiedOn: import_mobx_state_tree.types.maybeNull(import_mobx_state_tree.types.string)
|
|
371
|
-
}).actions((self) => ({
|
|
372
|
-
async create() {
|
|
373
|
-
const api = (0, import_mobx_state_tree.getEnv)(self).api;
|
|
374
|
-
const payload = {
|
|
375
|
-
calendarId: self.calendarId,
|
|
376
|
-
companyKey: self.companyKey ?? void 0,
|
|
377
|
-
name: self.name ?? void 0,
|
|
378
|
-
location: self.location ?? void 0,
|
|
379
|
-
timeZoneId: self.timeZoneId ?? void 0,
|
|
380
|
-
purpose: self.purpose,
|
|
381
|
-
description: self.description ?? void 0,
|
|
382
|
-
assignmentMethod: self.assignmentMethod,
|
|
383
|
-
duration: self.duration,
|
|
384
|
-
durationUnit: self.durationUnit,
|
|
385
|
-
minimumBookingNotice: self.minimumBookingNotice,
|
|
386
|
-
minimumBookingNoticeUnit: self.minimumBookingNoticeUnit,
|
|
387
|
-
minimumCancelationNotice: self.minimumCancelationNotice,
|
|
388
|
-
minimumCancelationNoticeUnit: self.minimumCancelationNoticeUnit,
|
|
389
|
-
futureLimit: self.futureLimit,
|
|
390
|
-
futureLimitUnit: self.futureLimitUnit,
|
|
391
|
-
bufferTime: self.bufferTime,
|
|
392
|
-
bufferTimeUnit: self.bufferTimeUnit,
|
|
393
|
-
bookingLimit: self.bookingLimit
|
|
394
|
-
};
|
|
395
|
-
const res = await api.createCalendar(payload);
|
|
396
|
-
if (res.status === "success" && res.data) (0, import_mobx_state_tree.applySnapshot)(self, { ...res.data, calendarId: self.calendarId });
|
|
397
|
-
return res;
|
|
398
|
-
},
|
|
399
|
-
async get() {
|
|
400
|
-
const api = (0, import_mobx_state_tree.getEnv)(self).api;
|
|
401
|
-
const res = await api.getCalendar(self.calendarId);
|
|
402
|
-
if (res.status === "success" && res.data) (0, import_mobx_state_tree.applySnapshot)(self, { ...res.data, calendarId: self.calendarId });
|
|
403
|
-
return res;
|
|
404
|
-
},
|
|
405
|
-
async remove() {
|
|
406
|
-
const api = (0, import_mobx_state_tree.getEnv)(self).api;
|
|
407
|
-
return api.removeCalendar(self.calendarId);
|
|
408
|
-
}
|
|
409
|
-
}));
|
|
410
|
-
var Calendar_default = CalendarModel;
|
|
215
|
+
// src/models/appointment/Event.js
|
|
216
|
+
var import_mobx_state_tree3 = require("mobx-state-tree");
|
|
411
217
|
|
|
412
|
-
// src/models/appointment/
|
|
218
|
+
// src/models/appointment/TimeSlot.js
|
|
413
219
|
var import_mobx_state_tree2 = require("mobx-state-tree");
|
|
414
|
-
var
|
|
415
|
-
id: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.number),
|
|
416
|
-
eventId: import_mobx_state_tree2.types.identifier,
|
|
417
|
-
calendarId: import_mobx_state_tree2.types.string,
|
|
418
|
-
participantId: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
419
|
-
title: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
420
|
-
description: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
421
|
-
isRecurring: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.boolean, false),
|
|
422
|
-
recurringFrequency: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.number, RecurringFrequency.None),
|
|
423
|
-
startDate: import_mobx_state_tree2.types.string,
|
|
424
|
-
endDate: import_mobx_state_tree2.types.string,
|
|
220
|
+
var TimeSlotModel = import_mobx_state_tree2.types.model("TimeSlot", {
|
|
425
221
|
startHour: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.number, 0),
|
|
426
222
|
startMinute: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.number, 0),
|
|
427
223
|
endHour: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.number, 0),
|
|
428
224
|
endMinute: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.number, 0),
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
createdOn: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
433
|
-
modifiedOn: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
434
|
-
externalEventId: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
435
|
-
attendeeStatus: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.number, AttendeeStatus.Tentative),
|
|
436
|
-
rescheduleLink: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
437
|
-
cancelLink: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
438
|
-
timeZone: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
439
|
-
offset: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.number, 0)
|
|
225
|
+
startDate: import_mobx_state_tree2.types.string,
|
|
226
|
+
endDate: import_mobx_state_tree2.types.string,
|
|
227
|
+
participantId: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string)
|
|
440
228
|
}).actions((self) => ({
|
|
441
|
-
|
|
442
|
-
const
|
|
443
|
-
const
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
title: self.title ?? void 0,
|
|
453
|
-
description: self.description ?? void 0,
|
|
454
|
-
startDate: self.startDate,
|
|
455
|
-
endDate: self.endDate,
|
|
456
|
-
startHour: self.startHour,
|
|
457
|
-
startMinute: self.startMinute,
|
|
458
|
-
endHour: self.endHour,
|
|
459
|
-
endMinute: self.endMinute,
|
|
460
|
-
visitorName: self.visitorName ?? void 0,
|
|
461
|
-
visitorEmail: self.visitorEmail ?? void 0,
|
|
462
|
-
visitorPhone: self.visitorPhone ?? void 0
|
|
463
|
-
};
|
|
464
|
-
const res = await api.createEvent(payload, offsetMinutes);
|
|
465
|
-
if (res.status === "success" && res.data) (0, import_mobx_state_tree2.applySnapshot)(self, { ...res.data, eventId: self.eventId });
|
|
466
|
-
return res;
|
|
467
|
-
},
|
|
468
|
-
async cancel() {
|
|
469
|
-
const api = (0, import_mobx_state_tree2.getEnv)(self).api;
|
|
470
|
-
return api.cancelEvent(self.eventId);
|
|
471
|
-
},
|
|
472
|
-
async getCancellable() {
|
|
473
|
-
const api = (0, import_mobx_state_tree2.getEnv)(self).api;
|
|
474
|
-
return api.getCancellable(self.eventId);
|
|
475
|
-
},
|
|
476
|
-
async getAvailability(params) {
|
|
477
|
-
const api = (0, import_mobx_state_tree2.getEnv)(self).api;
|
|
478
|
-
return api.getAvailability({
|
|
479
|
-
calendarId: self.calendarId,
|
|
480
|
-
participantId: params.participantId ?? self.participantId ?? void 0,
|
|
481
|
-
year: params.year,
|
|
482
|
-
month: params.month,
|
|
483
|
-
day: params.day,
|
|
484
|
-
offset: params.offset
|
|
485
|
-
});
|
|
486
|
-
},
|
|
487
|
-
async setReminder() {
|
|
488
|
-
const api = (0, import_mobx_state_tree2.getEnv)(self).api;
|
|
489
|
-
return api.setEventReminder(self.eventId);
|
|
229
|
+
setWithOffset(offsetMinutes) {
|
|
230
|
+
const start = new Date(self.startDate);
|
|
231
|
+
const end = new Date(self.endDate);
|
|
232
|
+
start.setMinutes(start.getMinutes() + offsetMinutes);
|
|
233
|
+
end.setMinutes(end.getMinutes() + offsetMinutes);
|
|
234
|
+
self.startDate = start.toISOString();
|
|
235
|
+
self.endDate = end.toISOString();
|
|
236
|
+
self.startHour = start.getHours();
|
|
237
|
+
self.startMinute = start.getMinutes();
|
|
238
|
+
self.endHour = end.getHours();
|
|
239
|
+
self.endMinute = end.getMinutes();
|
|
490
240
|
}
|
|
491
241
|
}));
|
|
492
|
-
var
|
|
242
|
+
var TimeSlot_default = TimeSlotModel;
|
|
493
243
|
|
|
494
|
-
// src/models/appointment/
|
|
495
|
-
|
|
496
|
-
var
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
244
|
+
// src/models/appointment/Event.js
|
|
245
|
+
function getDefaultOffset() {
|
|
246
|
+
var _a;
|
|
247
|
+
const cfg = getConfig();
|
|
248
|
+
return ((_a = cfg == null ? void 0 : cfg.getDefaultOffset) == null ? void 0 : _a.call(cfg)) ?? -(/* @__PURE__ */ new Date()).getTimezoneOffset();
|
|
249
|
+
}
|
|
250
|
+
var EventModel = import_mobx_state_tree3.types.model("Event", {
|
|
251
|
+
id: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.number), null),
|
|
252
|
+
eventId: import_mobx_state_tree3.types.identifier,
|
|
253
|
+
calendarId: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.string, ""),
|
|
254
|
+
participantId: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
|
|
255
|
+
title: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
|
|
256
|
+
description: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
|
|
257
|
+
isRecurring: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.boolean, false),
|
|
258
|
+
recurringFrequency: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.number, RecurringFrequency.None),
|
|
259
|
+
startDate: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.string, ""),
|
|
260
|
+
endDate: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.string, ""),
|
|
261
|
+
startHour: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.number, 0),
|
|
262
|
+
startMinute: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.number, 0),
|
|
263
|
+
endHour: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.number, 0),
|
|
264
|
+
endMinute: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.number, 0),
|
|
265
|
+
visitorName: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
|
|
266
|
+
visitorEmail: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
|
|
267
|
+
visitorPhone: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
|
|
268
|
+
createdOn: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
|
|
269
|
+
modifiedOn: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
|
|
270
|
+
externalEventId: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
|
|
271
|
+
attendeeStatus: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.number, AttendeeStatus.Tentative),
|
|
272
|
+
rescheduleLink: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
|
|
273
|
+
cancelLink: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
|
|
274
|
+
timeZone: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
|
|
275
|
+
offset: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.number, 0)
|
|
276
|
+
}).actions((self) => {
|
|
277
|
+
const { req, reqGet, reqPost } = createRequestHelpers(self, import_mobx_state_tree3.getEnv);
|
|
278
|
+
const getOffset = () => {
|
|
279
|
+
var _a, _b;
|
|
280
|
+
return ((_b = (_a = (0, import_mobx_state_tree3.getEnv)(self)).getDefaultOffset) == null ? void 0 : _b.call(_a)) ?? getDefaultOffset();
|
|
281
|
+
};
|
|
282
|
+
return {
|
|
283
|
+
/** GET /event/get – fetch this event by eventId or externalEventId */
|
|
284
|
+
async get(params) {
|
|
285
|
+
if ((params == null ? void 0 : params.eventId) ?? (params == null ? void 0 : params.event_id)) {
|
|
286
|
+
const res = await reqGet("/event/get", { event_id: params.eventId ?? params.event_id });
|
|
287
|
+
if (res.status === "success" && res.data) (0, import_mobx_state_tree3.applySnapshot)(self, { ...res.data, eventId: self.eventId });
|
|
288
|
+
return res;
|
|
289
|
+
}
|
|
290
|
+
if ((params == null ? void 0 : params.externalEventId) ?? (params == null ? void 0 : params.externalevent_id)) {
|
|
291
|
+
const res = await reqGet("/event/get", { externalevent_id: params.externalEventId ?? params.externalevent_id });
|
|
292
|
+
if (res.status === "success" && res.data) (0, import_mobx_state_tree3.applySnapshot)(self, { ...res.data, eventId: self.eventId });
|
|
293
|
+
return res;
|
|
294
|
+
}
|
|
295
|
+
return { status: "failure", message: "Provide eventId or externalEventId" };
|
|
296
|
+
},
|
|
297
|
+
/** POST /event/create – create event */
|
|
298
|
+
async create(offsetMinutes) {
|
|
299
|
+
const offset = offsetMinutes ?? getOffset();
|
|
300
|
+
const payload = {
|
|
301
|
+
calendarId: self.calendarId,
|
|
302
|
+
participantId: self.participantId ?? void 0,
|
|
303
|
+
title: self.title ?? void 0,
|
|
304
|
+
description: self.description ?? void 0,
|
|
305
|
+
startDate: self.startDate,
|
|
306
|
+
endDate: self.endDate,
|
|
307
|
+
startHour: self.startHour,
|
|
308
|
+
startMinute: self.startMinute,
|
|
309
|
+
endHour: self.endHour,
|
|
310
|
+
endMinute: self.endMinute,
|
|
311
|
+
visitorName: self.visitorName ?? void 0,
|
|
312
|
+
visitorEmail: self.visitorEmail ?? void 0,
|
|
313
|
+
visitorPhone: self.visitorPhone ?? void 0
|
|
314
|
+
};
|
|
315
|
+
const res = await reqPost("/event/create", payload, null, { headers: { offset: String(offset) } });
|
|
316
|
+
if (res.status === "success" && res.data) (0, import_mobx_state_tree3.applySnapshot)(self, { ...res.data, eventId: self.eventId });
|
|
317
|
+
return res;
|
|
318
|
+
},
|
|
319
|
+
/** POST /event/update – update event */
|
|
320
|
+
async update() {
|
|
321
|
+
const payload = {
|
|
322
|
+
eventId: self.eventId,
|
|
323
|
+
calendarId: self.calendarId,
|
|
324
|
+
participantId: self.participantId ?? void 0,
|
|
325
|
+
title: self.title ?? void 0,
|
|
326
|
+
description: self.description ?? void 0,
|
|
327
|
+
startDate: self.startDate,
|
|
328
|
+
endDate: self.endDate,
|
|
329
|
+
startHour: self.startHour,
|
|
330
|
+
startMinute: self.startMinute,
|
|
331
|
+
endHour: self.endHour,
|
|
332
|
+
endMinute: self.endMinute,
|
|
333
|
+
visitorName: self.visitorName ?? void 0,
|
|
334
|
+
visitorEmail: self.visitorEmail ?? void 0,
|
|
335
|
+
visitorPhone: self.visitorPhone ?? void 0
|
|
336
|
+
};
|
|
337
|
+
return reqPost("/event/update", payload);
|
|
338
|
+
},
|
|
339
|
+
/** POST /event/reschedule – reschedule event */
|
|
340
|
+
async reschedule(offsetMinutes) {
|
|
341
|
+
const offset = offsetMinutes ?? getOffset();
|
|
342
|
+
const payload = {
|
|
343
|
+
eventId: self.eventId,
|
|
344
|
+
calendarId: self.calendarId,
|
|
345
|
+
participantId: self.participantId ?? void 0,
|
|
346
|
+
title: self.title ?? void 0,
|
|
347
|
+
description: self.description ?? void 0,
|
|
348
|
+
startDate: self.startDate,
|
|
349
|
+
endDate: self.endDate,
|
|
350
|
+
startHour: self.startHour,
|
|
351
|
+
startMinute: self.startMinute,
|
|
352
|
+
endHour: self.endHour,
|
|
353
|
+
endMinute: self.endMinute,
|
|
354
|
+
visitorName: self.visitorName ?? void 0,
|
|
355
|
+
visitorEmail: self.visitorEmail ?? void 0,
|
|
356
|
+
visitorPhone: self.visitorPhone ?? void 0
|
|
357
|
+
};
|
|
358
|
+
const res = await reqPost("/event/reschedule", payload, null, { headers: { offset: String(offset) } });
|
|
359
|
+
if (res.status === "success" && res.data) (0, import_mobx_state_tree3.applySnapshot)(self, { ...res.data, eventId: self.eventId });
|
|
360
|
+
return res;
|
|
361
|
+
},
|
|
362
|
+
/** GET /event/cancel – cancel this event */
|
|
363
|
+
async cancel() {
|
|
364
|
+
return reqGet("/event/cancel", { event_id: self.eventId });
|
|
365
|
+
},
|
|
366
|
+
/** GET /event/cancellable – check if this event is cancellable */
|
|
367
|
+
async getCancellable() {
|
|
368
|
+
const res = await reqGet("/event/cancellable", { event_id: self.eventId });
|
|
369
|
+
if (res.data !== void 0) return { ...res, data: Boolean(res.data) };
|
|
370
|
+
return res;
|
|
371
|
+
},
|
|
372
|
+
/** GET /event/availability/get – get availability slots for a day */
|
|
373
|
+
async getAvailability(params) {
|
|
374
|
+
const query = {
|
|
375
|
+
calendar_id: self.calendarId,
|
|
376
|
+
year: params.year,
|
|
377
|
+
month: params.month,
|
|
378
|
+
day: params.day
|
|
379
|
+
};
|
|
380
|
+
if (params.participantId ?? self.participantId) query.participant_id = params.participantId ?? self.participantId;
|
|
381
|
+
return reqGet("/event/availability/get", query, { headers: { offset: String(params.offset ?? getOffset()) } });
|
|
382
|
+
},
|
|
383
|
+
/** GET /event/seteventreminder/{event_id} – set SMS reminder */
|
|
384
|
+
async setReminder() {
|
|
385
|
+
return req(`/event/seteventreminder/${encodeURIComponent(self.eventId)}`, { method: "GET" });
|
|
386
|
+
},
|
|
387
|
+
/** GET /event/{eventId}/{attendeeStatus} – set attendee status */
|
|
388
|
+
async setAttendeeStatus(status) {
|
|
389
|
+
const statusName = typeof status === "number" ? Object.keys(AttendeeStatus).find((k) => AttendeeStatus[k] === status) ?? "None" : status;
|
|
390
|
+
return reqGet(`/event/${encodeURIComponent(self.eventId)}/${encodeURIComponent(statusName)}`);
|
|
391
|
+
}
|
|
392
|
+
};
|
|
503
393
|
});
|
|
504
|
-
|
|
394
|
+
function mapEventFromApi(d) {
|
|
395
|
+
if (!d) return d;
|
|
396
|
+
const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
397
|
+
const n = (v) => v != null && v !== "" ? Number(v) : void 0;
|
|
398
|
+
return {
|
|
399
|
+
eventId: String(pick("eventId", "EventId", "event_id") ?? ""),
|
|
400
|
+
calendarId: String(pick("calendarId", "CalendarId", "calendar_id") ?? ""),
|
|
401
|
+
participantId: pick("participantId", "ParticipantId", "participant_id") ?? null,
|
|
402
|
+
title: pick("title", "Title"),
|
|
403
|
+
description: pick("description", "Description"),
|
|
404
|
+
startDate: pick("startDate", "StartDate", "start_date"),
|
|
405
|
+
endDate: pick("endDate", "EndDate", "end_date"),
|
|
406
|
+
startHour: n(pick("startHour", "StartHour", "start_hour")),
|
|
407
|
+
startMinute: n(pick("startMinute", "StartMinute", "start_minute")),
|
|
408
|
+
endHour: n(pick("endHour", "EndHour", "end_hour")),
|
|
409
|
+
endMinute: n(pick("endMinute", "EndMinute", "end_minute")),
|
|
410
|
+
visitorName: pick("visitorName", "VisitorName", "visitor_name"),
|
|
411
|
+
visitorEmail: pick("visitorEmail", "VisitorEmail", "visitor_email"),
|
|
412
|
+
visitorPhone: pick("visitorPhone", "VisitorPhone", "visitor_phone"),
|
|
413
|
+
externalEventId: pick("externalEventId", "ExternalEventId", "external_event_id"),
|
|
414
|
+
attendeeStatus: n(pick("attendeeStatus", "AttendeeStatus", "attendee_status")),
|
|
415
|
+
rescheduleLink: pick("rescheduleLink", "RescheduleLink", "reschedule_link"),
|
|
416
|
+
cancelLink: pick("cancelLink", "CancelLink", "cancel_link"),
|
|
417
|
+
timeZone: pick("timeZone", "TimeZone", "time_zone"),
|
|
418
|
+
createdOn: pick("createdOn", "CreatedOn", "created_on"),
|
|
419
|
+
modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on")
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
EventModel.get = async (eventId) => {
|
|
423
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
424
|
+
const res = await reqGet("/event/get", { event_id: eventId });
|
|
425
|
+
if (res.status === "success" && res.data) {
|
|
426
|
+
return EventModel.create(mapEventFromApi(res.data), { env: getConfig() });
|
|
427
|
+
}
|
|
428
|
+
return null;
|
|
429
|
+
};
|
|
430
|
+
EventModel.getByExternalId = async (externalEventId) => {
|
|
431
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
432
|
+
const res = await reqGet("/event/get", { externalevent_id: externalEventId });
|
|
433
|
+
if (res.status === "success" && res.data) {
|
|
434
|
+
return EventModel.create(mapEventFromApi(res.data), { env: getConfig() });
|
|
435
|
+
}
|
|
436
|
+
return null;
|
|
437
|
+
};
|
|
438
|
+
EventModel.getRoundRobinParticipant = async (calendarId) => {
|
|
439
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
440
|
+
const res = await reqGet("/event/participant/roundrobin/get", { calendar_id: calendarId });
|
|
441
|
+
return res.status === "success" ? res.data : null;
|
|
442
|
+
};
|
|
443
|
+
EventModel.getEarliestAvailableDays = async (calendarId, count, opts = {}) => {
|
|
444
|
+
const { req } = createRequestHelpersFromEnv(getConfig());
|
|
445
|
+
const query = { calendar_id: calendarId, count };
|
|
446
|
+
if (opts.year != null) query.year = opts.year;
|
|
447
|
+
if (opts.month != null) query.month = opts.month;
|
|
448
|
+
if (opts.day != null) query.day = opts.day;
|
|
449
|
+
const offset = opts.offset ?? getDefaultOffset();
|
|
450
|
+
const res = await req("/event/days/available/get", { method: "GET", query, headers: { offset: String(offset) } });
|
|
451
|
+
return res.status === "success" && Array.isArray(res.data) ? res.data : null;
|
|
452
|
+
};
|
|
453
|
+
EventModel.getDaySelectable = async (calendarId, year, month, day, opts = {}) => {
|
|
454
|
+
const { req } = createRequestHelpersFromEnv(getConfig());
|
|
455
|
+
const query = { calendar_id: calendarId, year, month, day };
|
|
456
|
+
if (opts.participantId) query.participant_id = opts.participantId;
|
|
457
|
+
const offset = opts.offset ?? getDefaultOffset();
|
|
458
|
+
const res = await req("/event/day/selectable/get", { method: "GET", query, headers: { offset: String(offset) } });
|
|
459
|
+
return res.status === "success" ? Boolean(res.data) : false;
|
|
460
|
+
};
|
|
461
|
+
EventModel.getByVisitorEmail = async (email, opts = {}) => {
|
|
462
|
+
const { req } = createRequestHelpersFromEnv(getConfig());
|
|
463
|
+
const query = { email };
|
|
464
|
+
if (opts.companyKey) query.company_key = opts.companyKey;
|
|
465
|
+
else if (opts.calendarId) query.calendar_id = opts.calendarId;
|
|
466
|
+
else throw new Error("companyKey or calendarId required");
|
|
467
|
+
const offset = opts.offset ?? getDefaultOffset();
|
|
468
|
+
const res = await req("/event/existing/getbyvisitoremail", { method: "GET", query, headers: { offset: String(offset) } });
|
|
469
|
+
if (res.status === "success" && Array.isArray(res.data)) {
|
|
470
|
+
return res.data.map((e) => EventModel.create(mapEventFromApi(e), { env: getConfig() }));
|
|
471
|
+
}
|
|
472
|
+
return null;
|
|
473
|
+
};
|
|
474
|
+
EventModel.getByVisitorPhone = async (phone, opts = {}) => {
|
|
475
|
+
const { req } = createRequestHelpersFromEnv(getConfig());
|
|
476
|
+
const query = { phone };
|
|
477
|
+
if (opts.companyKey) query.company_key = opts.companyKey;
|
|
478
|
+
else if (opts.calendarId) query.calendar_id = opts.calendarId;
|
|
479
|
+
else throw new Error("companyKey or calendarId required");
|
|
480
|
+
const offset = opts.offset ?? getDefaultOffset();
|
|
481
|
+
const res = await req("/event/existing/getbyvisitorphone", { method: "GET", query, headers: { offset: String(offset) } });
|
|
482
|
+
if (res.status === "success" && Array.isArray(res.data)) {
|
|
483
|
+
return res.data.map((e) => EventModel.create(mapEventFromApi(e), { env: getConfig() }));
|
|
484
|
+
}
|
|
485
|
+
return null;
|
|
486
|
+
};
|
|
487
|
+
EventModel.getAvailability = async (calendarId, year, month, day, opts = {}) => {
|
|
488
|
+
const { req } = createRequestHelpersFromEnv(getConfig());
|
|
489
|
+
const query = { calendar_id: calendarId, year, month, day };
|
|
490
|
+
if (opts.participantId) query.participant_id = opts.participantId;
|
|
491
|
+
const offset = opts.offset ?? getDefaultOffset();
|
|
492
|
+
const res = await req("/event/availability/get", { method: "GET", query, headers: { offset: String(offset) } });
|
|
493
|
+
if (res.status === "success" && Array.isArray(res.data)) {
|
|
494
|
+
return res.data.map((s) => TimeSlot_default.create({
|
|
495
|
+
startHour: s.startHour ?? s.StartHour,
|
|
496
|
+
startMinute: s.startMinute ?? s.StartMinute,
|
|
497
|
+
endHour: s.endHour ?? s.EndHour,
|
|
498
|
+
endMinute: s.endMinute ?? s.EndMinute,
|
|
499
|
+
startDate: s.startDate ?? s.StartDate,
|
|
500
|
+
endDate: s.endDate ?? s.EndDate,
|
|
501
|
+
participantId: s.participantId ?? s.ParticipantId ?? null
|
|
502
|
+
}));
|
|
503
|
+
}
|
|
504
|
+
return [];
|
|
505
|
+
};
|
|
506
|
+
EventModel.cancel = async (eventId) => {
|
|
507
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
508
|
+
return reqGet("/event/cancel", { event_id: eventId });
|
|
509
|
+
};
|
|
510
|
+
EventModel.getCancellable = async (eventId) => {
|
|
511
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
512
|
+
const res = await reqGet("/event/cancellable", { event_id: eventId });
|
|
513
|
+
return res.status === "success" ? Boolean(res.data) : false;
|
|
514
|
+
};
|
|
515
|
+
EventModel.createEvent = async (payload, offsetMinutes) => {
|
|
516
|
+
const { reqPost } = createRequestHelpersFromEnv(getConfig());
|
|
517
|
+
const offset = offsetMinutes ?? getDefaultOffset();
|
|
518
|
+
const res = await reqPost("/event/create", payload, null, { headers: { offset: String(offset) } });
|
|
519
|
+
if (res.status === "success" && res.data) {
|
|
520
|
+
return EventModel.create(mapEventFromApi(res.data), { env: getConfig() });
|
|
521
|
+
}
|
|
522
|
+
return null;
|
|
523
|
+
};
|
|
524
|
+
EventModel.reschedule = async (payload, offsetMinutes) => {
|
|
525
|
+
const { reqPost } = createRequestHelpersFromEnv(getConfig());
|
|
526
|
+
const offset = offsetMinutes ?? getDefaultOffset();
|
|
527
|
+
const res = await reqPost("/event/reschedule", payload, null, { headers: { offset: String(offset) } });
|
|
528
|
+
if (res.status === "success" && res.data) {
|
|
529
|
+
return EventModel.create(mapEventFromApi(res.data), { env: getConfig() });
|
|
530
|
+
}
|
|
531
|
+
return null;
|
|
532
|
+
};
|
|
533
|
+
EventModel.updateEvent = async (payload) => {
|
|
534
|
+
const { reqPost } = createRequestHelpersFromEnv(getConfig());
|
|
535
|
+
return reqPost("/event/update", payload);
|
|
536
|
+
};
|
|
537
|
+
EventModel.createTest = async (payload, offsetMinutes) => {
|
|
538
|
+
const { reqPost } = createRequestHelpersFromEnv(getConfig());
|
|
539
|
+
const offset = offsetMinutes ?? getDefaultOffset();
|
|
540
|
+
return reqPost("/event/testcreate", payload, null, { headers: { offset: String(offset) } });
|
|
541
|
+
};
|
|
542
|
+
EventModel.getCustomData = async (calendarId, eventId) => {
|
|
543
|
+
const { reqPost } = createRequestHelpersFromEnv(getConfig());
|
|
544
|
+
const query = { calendar_id: calendarId };
|
|
545
|
+
if (eventId) query.event_id = eventId;
|
|
546
|
+
const res = await reqPost("/event/customdata/get", {}, query);
|
|
547
|
+
if (res.status === "success" && typeof res.data === "string") {
|
|
548
|
+
try {
|
|
549
|
+
return JSON.parse(res.data);
|
|
550
|
+
} catch {
|
|
551
|
+
return res.data;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return res.status === "success" ? res.data : null;
|
|
555
|
+
};
|
|
556
|
+
EventModel.setReminder = async (eventId) => {
|
|
557
|
+
const { req } = createRequestHelpersFromEnv(getConfig());
|
|
558
|
+
return req(`/event/seteventreminder/${encodeURIComponent(eventId)}`, { method: "GET" });
|
|
559
|
+
};
|
|
560
|
+
EventModel.setAttendeeStatus = async (eventId, attendeeStatus) => {
|
|
561
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
562
|
+
const statusName = typeof attendeeStatus === "number" ? Object.keys(AttendeeStatus).find((k) => AttendeeStatus[k] === attendeeStatus) ?? "None" : attendeeStatus;
|
|
563
|
+
return reqGet(`/event/${encodeURIComponent(eventId)}/${encodeURIComponent(statusName)}`);
|
|
564
|
+
};
|
|
565
|
+
var Event_default = EventModel;
|
|
566
|
+
|
|
567
|
+
// src/models/appointment/CalendarParticipant.js
|
|
568
|
+
var import_mobx_state_tree5 = require("mobx-state-tree");
|
|
505
569
|
|
|
506
|
-
// src/models/appointment/
|
|
570
|
+
// src/models/appointment/ParticipantInfo.js
|
|
507
571
|
var import_mobx_state_tree4 = require("mobx-state-tree");
|
|
508
|
-
var
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
friday: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.boolean, false),
|
|
517
|
-
saturday: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.boolean, false),
|
|
518
|
-
startHour: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.number, 0),
|
|
519
|
-
startMinute: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.number, 0),
|
|
520
|
-
endHour: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.number, 0),
|
|
521
|
-
endMinute: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.number, 0),
|
|
522
|
-
createdOn: import_mobx_state_tree4.types.maybeNull(import_mobx_state_tree4.types.string),
|
|
523
|
-
modifiedOn: import_mobx_state_tree4.types.maybeNull(import_mobx_state_tree4.types.string)
|
|
572
|
+
var ParticipantInfoModel = import_mobx_state_tree4.types.model("ParticipantInfo", {
|
|
573
|
+
participantId: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.string, ""),
|
|
574
|
+
calendarParticipantId: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.string, ""),
|
|
575
|
+
alias: import_mobx_state_tree4.types.maybeNull(import_mobx_state_tree4.types.string),
|
|
576
|
+
email: import_mobx_state_tree4.types.maybeNull(import_mobx_state_tree4.types.string),
|
|
577
|
+
isApproved: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.boolean, false),
|
|
578
|
+
emailProvider: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.number, 0),
|
|
579
|
+
isAvailable: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.boolean, false)
|
|
524
580
|
});
|
|
525
|
-
var
|
|
581
|
+
var ParticipantInfo_default = ParticipantInfoModel;
|
|
526
582
|
|
|
527
|
-
// src/models/appointment/CalendarParticipant.
|
|
528
|
-
var import_mobx_state_tree5 = require("mobx-state-tree");
|
|
583
|
+
// src/models/appointment/CalendarParticipant.js
|
|
529
584
|
var CalendarParticipantModel = import_mobx_state_tree5.types.model("CalendarParticipant", {
|
|
530
|
-
id: import_mobx_state_tree5.types.maybeNull(import_mobx_state_tree5.types.number),
|
|
585
|
+
id: import_mobx_state_tree5.types.optional(import_mobx_state_tree5.types.maybeNull(import_mobx_state_tree5.types.number), null),
|
|
531
586
|
calendarParticipantId: import_mobx_state_tree5.types.optional(import_mobx_state_tree5.types.string, ""),
|
|
532
|
-
participantId: import_mobx_state_tree5.types.string,
|
|
533
|
-
calendarId: import_mobx_state_tree5.types.string,
|
|
534
|
-
createdOn: import_mobx_state_tree5.types.maybeNull(import_mobx_state_tree5.types.string),
|
|
535
|
-
modifiedOn: import_mobx_state_tree5.types.maybeNull(import_mobx_state_tree5.types.string)
|
|
587
|
+
participantId: import_mobx_state_tree5.types.optional(import_mobx_state_tree5.types.string, ""),
|
|
588
|
+
calendarId: import_mobx_state_tree5.types.optional(import_mobx_state_tree5.types.string, ""),
|
|
589
|
+
createdOn: import_mobx_state_tree5.types.optional(import_mobx_state_tree5.types.maybeNull(import_mobx_state_tree5.types.string), null),
|
|
590
|
+
modifiedOn: import_mobx_state_tree5.types.optional(import_mobx_state_tree5.types.maybeNull(import_mobx_state_tree5.types.string), null)
|
|
536
591
|
});
|
|
592
|
+
function mapFromApi(d) {
|
|
593
|
+
if (!d) return d;
|
|
594
|
+
const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
595
|
+
return {
|
|
596
|
+
id: pick("id", "Id"),
|
|
597
|
+
calendarParticipantId: String(pick("calendarParticipantId", "CalendarParticipantId", "calendarparticipant_id") ?? ""),
|
|
598
|
+
participantId: String(pick("participantId", "ParticipantId", "participant_id") ?? ""),
|
|
599
|
+
calendarId: String(pick("calendarId", "CalendarId", "calendar_id") ?? ""),
|
|
600
|
+
createdOn: pick("createdOn", "CreatedOn", "created_on") ?? null,
|
|
601
|
+
modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on") ?? null
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
CalendarParticipantModel.getByCalendar = async (calendarId) => {
|
|
605
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
606
|
+
const res = await reqGet("/Calendar/Participant/Get", { calendar_id: calendarId });
|
|
607
|
+
if (res.status === "success" && res.data != null) {
|
|
608
|
+
const arr = Array.isArray(res.data) ? res.data : typeof res.data === "string" ? JSON.parse(res.data) : [];
|
|
609
|
+
return arr.map((p) => CalendarParticipantModel.create(mapFromApi({ ...p, calendar_id: calendarId })));
|
|
610
|
+
}
|
|
611
|
+
return null;
|
|
612
|
+
};
|
|
613
|
+
CalendarParticipantModel.getInfoByCalendar = async (calendarId) => {
|
|
614
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
615
|
+
const res = await reqGet("/Calendar/Participants/GetInfo", { calendar_id: calendarId });
|
|
616
|
+
if (res.status === "success" && Array.isArray(res.data)) {
|
|
617
|
+
return res.data.map(
|
|
618
|
+
(p) => ParticipantInfo_default.create({
|
|
619
|
+
participantId: p.participantId ?? p.ParticipantId ?? p.participant_id ?? "",
|
|
620
|
+
calendarParticipantId: p.calendarParticipantId ?? p.CalendarParticipantId ?? p.calendarparticipant_id ?? "",
|
|
621
|
+
alias: p.alias ?? p.Alias ?? null,
|
|
622
|
+
email: p.email ?? p.Email ?? null,
|
|
623
|
+
isApproved: p.isApproved ?? p.IsApproved ?? p.is_approved ?? false,
|
|
624
|
+
emailProvider: p.emailProvider ?? p.EmailProvider ?? p.email_provider ?? 0,
|
|
625
|
+
isAvailable: p.isAvailable ?? p.IsAvailable ?? p.is_available ?? false
|
|
626
|
+
})
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
return null;
|
|
630
|
+
};
|
|
631
|
+
CalendarParticipantModel.getByParticipant = async (participantId) => {
|
|
632
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
633
|
+
const res = await reqGet("/Participant/calendar/get", { participant_id: participantId });
|
|
634
|
+
if (res.status === "success" && res.data != null) {
|
|
635
|
+
const arr = Array.isArray(res.data) ? res.data : typeof res.data === "string" ? JSON.parse(res.data) : [];
|
|
636
|
+
return arr.map((p) => CalendarParticipantModel.create(mapFromApi({ ...p, participant_id: participantId })));
|
|
637
|
+
}
|
|
638
|
+
return null;
|
|
639
|
+
};
|
|
537
640
|
var CalendarParticipant_default = CalendarParticipantModel;
|
|
538
641
|
|
|
539
|
-
// src/models/appointment/
|
|
642
|
+
// src/models/appointment/CalendarDay.js
|
|
540
643
|
var import_mobx_state_tree6 = require("mobx-state-tree");
|
|
541
|
-
var
|
|
542
|
-
|
|
543
|
-
participantId: import_mobx_state_tree6.types.identifier,
|
|
544
|
-
companyKey: import_mobx_state_tree6.types.maybeNull(import_mobx_state_tree6.types.string),
|
|
545
|
-
alias: import_mobx_state_tree6.types.optional(import_mobx_state_tree6.types.string, ""),
|
|
546
|
-
email: import_mobx_state_tree6.types.optional(import_mobx_state_tree6.types.string, ""),
|
|
547
|
-
isApproved: import_mobx_state_tree6.types.optional(import_mobx_state_tree6.types.boolean, false),
|
|
548
|
-
isAvailable: import_mobx_state_tree6.types.optional(import_mobx_state_tree6.types.boolean, false),
|
|
549
|
-
provider: import_mobx_state_tree6.types.optional(import_mobx_state_tree6.types.number, 0),
|
|
550
|
-
createdOn: import_mobx_state_tree6.types.maybeNull(import_mobx_state_tree6.types.string),
|
|
551
|
-
modifiedOn: import_mobx_state_tree6.types.maybeNull(import_mobx_state_tree6.types.string),
|
|
552
|
-
isDeleted: import_mobx_state_tree6.types.optional(import_mobx_state_tree6.types.boolean, false)
|
|
644
|
+
var CalendarDayModel = import_mobx_state_tree6.types.model("CalendarDay", {
|
|
645
|
+
date: import_mobx_state_tree6.types.optional(import_mobx_state_tree6.types.string, "")
|
|
553
646
|
});
|
|
554
|
-
var
|
|
647
|
+
var CalendarDay_default = CalendarDayModel;
|
|
555
648
|
|
|
556
|
-
// src/models/appointment/
|
|
557
|
-
var
|
|
558
|
-
var OpeningHourModel = import_mobx_state_tree7.types.model("OpeningHour", {
|
|
649
|
+
// src/models/appointment/Calendar.js
|
|
650
|
+
var CalendarModel = import_mobx_state_tree7.types.model("Calendar", {
|
|
559
651
|
id: import_mobx_state_tree7.types.maybeNull(import_mobx_state_tree7.types.number),
|
|
560
|
-
|
|
561
|
-
calendarId: import_mobx_state_tree7.types.
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
652
|
+
companyKey: import_mobx_state_tree7.types.maybeNull(import_mobx_state_tree7.types.string),
|
|
653
|
+
calendarId: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.identifier, "new"),
|
|
654
|
+
name: import_mobx_state_tree7.types.maybeNull(import_mobx_state_tree7.types.string),
|
|
655
|
+
// location: types.maybeNull(types.string),
|
|
656
|
+
timeZoneId: import_mobx_state_tree7.types.maybeNull(import_mobx_state_tree7.types.string),
|
|
657
|
+
purpose: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.string, ""),
|
|
658
|
+
description: import_mobx_state_tree7.types.maybeNull(import_mobx_state_tree7.types.string),
|
|
659
|
+
assignmentMethod: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, AssignmentMethod.RoundRobin),
|
|
660
|
+
duration: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, 0),
|
|
661
|
+
durationUnit: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, Unit.Minutes),
|
|
662
|
+
minimumBookingNotice: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, 0),
|
|
663
|
+
minimumBookingNoticeUnit: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, Unit.Minutes),
|
|
664
|
+
minimumCancelationNotice: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, 0),
|
|
665
|
+
minimumCancelationNoticeUnit: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, Unit.Minutes),
|
|
666
|
+
futureLimit: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, 0),
|
|
667
|
+
futureLimitUnit: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, Unit.Days),
|
|
668
|
+
bufferTime: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, 0),
|
|
669
|
+
bufferTimeUnit: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, Unit.Minutes),
|
|
670
|
+
bookingLimit: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, 0),
|
|
569
671
|
createdOn: import_mobx_state_tree7.types.maybeNull(import_mobx_state_tree7.types.string),
|
|
570
672
|
modifiedOn: import_mobx_state_tree7.types.maybeNull(import_mobx_state_tree7.types.string)
|
|
673
|
+
}).actions((self) => {
|
|
674
|
+
const { req, reqGet, reqPost } = createRequestHelpers(self, import_mobx_state_tree7.getEnv);
|
|
675
|
+
return {
|
|
676
|
+
/** GET Calendar/Get – fetch this calendar by calendarId */
|
|
677
|
+
async get() {
|
|
678
|
+
if (!self.calendarId) return { status: "failure", message: "calendarId required" };
|
|
679
|
+
const res = await reqGet("/Calendar/Get", { calendar_id: self.calendarId });
|
|
680
|
+
if (res.status === "success" && res.data) {
|
|
681
|
+
(0, import_mobx_state_tree7.applySnapshot)(self, { ...res.data, calendarId: self.calendarId });
|
|
682
|
+
}
|
|
683
|
+
return res;
|
|
684
|
+
},
|
|
685
|
+
/** POST Calendar/Create – create or update calendar */
|
|
686
|
+
async create() {
|
|
687
|
+
const payload = {
|
|
688
|
+
calendarId: self.calendarId || void 0,
|
|
689
|
+
companyKey: self.companyKey ?? void 0,
|
|
690
|
+
name: self.name ?? void 0,
|
|
691
|
+
timeZoneId: self.timeZoneId ?? void 0,
|
|
692
|
+
purpose: self.purpose,
|
|
693
|
+
description: self.description ?? void 0,
|
|
694
|
+
assignmentMethod: self.assignmentMethod,
|
|
695
|
+
duration: self.duration,
|
|
696
|
+
durationUnit: self.durationUnit,
|
|
697
|
+
minimumBookingNotice: self.minimumBookingNotice,
|
|
698
|
+
minimumBookingNoticeUnit: self.minimumBookingNoticeUnit,
|
|
699
|
+
minimumCancelationNotice: self.minimumCancelationNotice,
|
|
700
|
+
minimumCancelationNoticeUnit: self.minimumCancelationNoticeUnit,
|
|
701
|
+
futureLimit: self.futureLimit,
|
|
702
|
+
futureLimitUnit: self.futureLimitUnit,
|
|
703
|
+
bufferTime: self.bufferTime,
|
|
704
|
+
bufferTimeUnit: self.bufferTimeUnit,
|
|
705
|
+
bookingLimit: self.bookingLimit
|
|
706
|
+
};
|
|
707
|
+
const res = await reqPost("/Calendar/Create", payload);
|
|
708
|
+
if (res.status === "success" && res.data) {
|
|
709
|
+
(0, import_mobx_state_tree7.applySnapshot)(self, { ...res.data, calendarId: res.data.calendarId || self.calendarId });
|
|
710
|
+
}
|
|
711
|
+
return res;
|
|
712
|
+
},
|
|
713
|
+
/** GET Calendar/Remove */
|
|
714
|
+
async remove() {
|
|
715
|
+
if (!self.calendarId) return { status: "failure", message: "calendarId required" };
|
|
716
|
+
return reqGet("/Calendar/Remove", { calendar_id: self.calendarId });
|
|
717
|
+
},
|
|
718
|
+
/** POST Calendar/Event/Update */
|
|
719
|
+
async update() {
|
|
720
|
+
const payload = {
|
|
721
|
+
calendarId: self.calendarId,
|
|
722
|
+
companyKey: self.companyKey ?? void 0,
|
|
723
|
+
name: self.name ?? void 0,
|
|
724
|
+
timeZoneId: self.timeZoneId ?? void 0,
|
|
725
|
+
purpose: self.purpose,
|
|
726
|
+
description: self.description ?? void 0,
|
|
727
|
+
assignmentMethod: self.assignmentMethod,
|
|
728
|
+
duration: self.duration,
|
|
729
|
+
durationUnit: self.durationUnit,
|
|
730
|
+
minimumBookingNotice: self.minimumBookingNotice,
|
|
731
|
+
minimumBookingNoticeUnit: self.minimumBookingNoticeUnit,
|
|
732
|
+
minimumCancelationNotice: self.minimumCancelationNotice,
|
|
733
|
+
minimumCancelationNoticeUnit: self.minimumCancelationNoticeUnit,
|
|
734
|
+
futureLimit: self.futureLimit,
|
|
735
|
+
futureLimitUnit: self.futureLimitUnit,
|
|
736
|
+
bufferTime: self.bufferTime,
|
|
737
|
+
bufferTimeUnit: self.bufferTimeUnit,
|
|
738
|
+
bookingLimit: self.bookingLimit
|
|
739
|
+
};
|
|
740
|
+
return reqPost("/Calendar/Event/Update", payload);
|
|
741
|
+
},
|
|
742
|
+
/** GET Calendar/Participant/Add */
|
|
743
|
+
async addParticipant(participantId) {
|
|
744
|
+
if (!self.calendarId) return { status: "failure", message: "calendarId required" };
|
|
745
|
+
return reqGet("/Calendar/Participant/Add", { calendar_id: self.calendarId, participant_id: participantId });
|
|
746
|
+
},
|
|
747
|
+
/** GET Calendar/Participant/Remove */
|
|
748
|
+
async removeParticipant(participantId) {
|
|
749
|
+
if (!self.calendarId) return { status: "failure", message: "calendarId required" };
|
|
750
|
+
return reqGet("/Calendar/Participant/Remove", { calendar_id: self.calendarId, participant_id: participantId });
|
|
751
|
+
},
|
|
752
|
+
/** GET Calendar/Participant/OpeningHours/Get */
|
|
753
|
+
async getParticipantOpeningHours(params = {}) {
|
|
754
|
+
if (!self.calendarId && !params.calendarParticipantId) {
|
|
755
|
+
return { status: "failure", message: "calendarId or calendarParticipantId required" };
|
|
756
|
+
}
|
|
757
|
+
const q = {};
|
|
758
|
+
if (params.calendarParticipantId) q.calendarparticipant_id = params.calendarParticipantId;
|
|
759
|
+
if (params.participantId) q.participant_id = params.participantId;
|
|
760
|
+
if (params.calendarId) q.calendar_id = params.calendarId;
|
|
761
|
+
else if (self.calendarId) q.calendar_id = self.calendarId;
|
|
762
|
+
return reqGet("/Calendar/Participant/OpeningHours/Get", q);
|
|
763
|
+
},
|
|
764
|
+
/** POST Calendar/Participant/Availability/OpeningHour/Save */
|
|
765
|
+
async saveOpeningHour(payload) {
|
|
766
|
+
return reqPost("/Calendar/Participant/Availability/OpeningHour/Save", payload);
|
|
767
|
+
},
|
|
768
|
+
/** POST Calendar/Participant/Availability/OpeningHours/Save */
|
|
769
|
+
async saveOpeningHours(payload) {
|
|
770
|
+
return reqPost("/Calendar/Participant/Availability/OpeningHours/Save", payload);
|
|
771
|
+
},
|
|
772
|
+
/** GET Calendar/Participant/OpeningHour/Remove */
|
|
773
|
+
async removeParticipantOpeningHours(participantId) {
|
|
774
|
+
if (!self.calendarId) return { status: "failure", message: "calendarId required" };
|
|
775
|
+
return reqGet("/Calendar/Participant/OpeningHour/Remove", { calendar_id: self.calendarId, participant_id: participantId });
|
|
776
|
+
},
|
|
777
|
+
/** GET Calendar/Participant/Availability/Add */
|
|
778
|
+
async addParticipantAvailability(participantId, detail) {
|
|
779
|
+
if (!self.calendarId) return { status: "failure", message: "calendarId required" };
|
|
780
|
+
return req("/Calendar/Participant/Availability/Add", {
|
|
781
|
+
method: "GET",
|
|
782
|
+
query: { calendar_id: self.calendarId, participant_id: participantId },
|
|
783
|
+
body: JSON.stringify(detail)
|
|
784
|
+
});
|
|
785
|
+
},
|
|
786
|
+
/** GET Calendar/Participant/All */
|
|
787
|
+
async getParticipants() {
|
|
788
|
+
if (!self.calendarId) return { status: "failure", message: "calendarId required" };
|
|
789
|
+
return reqGet("/Calendar/Participant/All", { calendar_id: self.calendarId });
|
|
790
|
+
},
|
|
791
|
+
/** GET Calendar/Month/Get */
|
|
792
|
+
async getMonth(year, month) {
|
|
793
|
+
if (!self.calendarId) return { status: "failure", message: "calendarId required" };
|
|
794
|
+
return reqGet("/Calendar/Month/Get", { calendar_id: self.calendarId, year, month });
|
|
795
|
+
},
|
|
796
|
+
/** GET Calendar/Events/Get */
|
|
797
|
+
async getEvents() {
|
|
798
|
+
if (!self.calendarId) return { status: "failure", message: "calendarId required" };
|
|
799
|
+
return reqGet("/Calendar/Events/Get", { calendar_id: self.calendarId });
|
|
800
|
+
},
|
|
801
|
+
/** GET Calendar/Participant/Get */
|
|
802
|
+
async getCalendarParticipant() {
|
|
803
|
+
if (!self.calendarId) return { status: "failure", message: "calendarId required" };
|
|
804
|
+
return reqGet("/Calendar/Participant/Get", { calendar_id: self.calendarId });
|
|
805
|
+
},
|
|
806
|
+
/** GET Calendar/Participants/GetInfo */
|
|
807
|
+
async getParticipantsInfo() {
|
|
808
|
+
if (!self.calendarId) return { status: "failure", message: "calendarId required" };
|
|
809
|
+
return reqGet("/Calendar/Participants/GetInfo", { calendar_id: self.calendarId });
|
|
810
|
+
},
|
|
811
|
+
/** GET Calendar/All – calendars by company_key */
|
|
812
|
+
async getByCompany(companyKey) {
|
|
813
|
+
return reqGet("/Calendar/All", { company_key: companyKey || self.companyKey });
|
|
814
|
+
},
|
|
815
|
+
/** GET Calendar/TimeZones/Get */
|
|
816
|
+
async getTimeZones() {
|
|
817
|
+
return reqGet("/Calendar/TimeZones/Get");
|
|
818
|
+
},
|
|
819
|
+
/** GET Calendar/TimeZone/Get – display name for timezone_id */
|
|
820
|
+
async getTimeZone(timezoneId) {
|
|
821
|
+
return reqGet("/Calendar/TimeZone/Get", { timezone_id: timezoneId || self.timeZoneId });
|
|
822
|
+
},
|
|
823
|
+
/** GET Calendar/CreateWithParticipants */
|
|
824
|
+
async createWithParticipants(name, companyKey, participantIds, description) {
|
|
825
|
+
const q = {
|
|
826
|
+
name,
|
|
827
|
+
company_key: companyKey,
|
|
828
|
+
participantids: Array.isArray(participantIds) ? participantIds.join(",") : String(participantIds)
|
|
829
|
+
};
|
|
830
|
+
if (description) q.description = description;
|
|
831
|
+
return reqGet("/Calendar/CreateWithParticipants", q);
|
|
832
|
+
},
|
|
833
|
+
/** GET Calendar/EditWithParticipants */
|
|
834
|
+
async editWithParticipants(calendarId, name, participantIds, description) {
|
|
835
|
+
const q = {
|
|
836
|
+
calendar_id: calendarId,
|
|
837
|
+
name,
|
|
838
|
+
participantids: Array.isArray(participantIds) ? participantIds.join(",") : String(participantIds)
|
|
839
|
+
};
|
|
840
|
+
if (description) q.description = description;
|
|
841
|
+
return reqGet("/Calendar/EditWithParticipants", q);
|
|
842
|
+
}
|
|
843
|
+
};
|
|
571
844
|
});
|
|
572
|
-
|
|
845
|
+
function mapCalendarFromApi(d) {
|
|
846
|
+
if (!d) return d;
|
|
847
|
+
const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
848
|
+
const n = (v) => v != null && v !== "" ? Number(v) : void 0;
|
|
849
|
+
return {
|
|
850
|
+
id: pick("id", "Id"),
|
|
851
|
+
companyKey: pick("companyKey", "CompanyKey", "company_key"),
|
|
852
|
+
calendarId: pick("calendarId", "CalendarId", "calendar_id") ?? "",
|
|
853
|
+
name: pick("name", "Name"),
|
|
854
|
+
timeZoneId: pick("timeZoneId", "TimeZoneId", "time_zone_id"),
|
|
855
|
+
purpose: pick("purpose", "Purpose") ?? "",
|
|
856
|
+
description: pick("description", "Description"),
|
|
857
|
+
assignmentMethod: n(pick("assignmentMethod", "AssignmentMethod", "assignment_method")),
|
|
858
|
+
duration: n(pick("duration", "Duration")),
|
|
859
|
+
durationUnit: n(pick("durationUnit", "DurationUnit", "duration_unit")),
|
|
860
|
+
minimumBookingNotice: n(pick("minimumBookingNotice", "MinimumBookingNotice", "minimum_booking_notice")),
|
|
861
|
+
minimumBookingNoticeUnit: n(pick("minimumBookingNoticeUnit", "MinimumBookingNoticeUnit", "minimum_booking_notice_unit")),
|
|
862
|
+
minimumCancelationNotice: n(pick("minimumCancelationNotice", "MinimumCancelationNotice", "minimum_cancelation_notice")),
|
|
863
|
+
minimumCancelationNoticeUnit: n(pick("minimumCancelationNoticeUnit", "MinimumCancelationNoticeUnit", "minimum_cancelation_notice_unit")),
|
|
864
|
+
futureLimit: n(pick("futureLimit", "FutureLimit", "future_limit")),
|
|
865
|
+
futureLimitUnit: n(pick("futureLimitUnit", "FutureLimitUnit", "future_limit_unit")),
|
|
866
|
+
bufferTime: n(pick("bufferTime", "BufferTime", "buffer_time")),
|
|
867
|
+
bufferTimeUnit: n(pick("bufferTimeUnit", "BufferTimeUnit", "buffer_time_unit")),
|
|
868
|
+
bookingLimit: n(pick("bookingLimit", "BookingLimit", "booking_limit")),
|
|
869
|
+
createdOn: pick("createdOn", "CreatedOn", "created_on"),
|
|
870
|
+
modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on")
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
CalendarModel.getRaw = async (calendarId) => {
|
|
874
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
875
|
+
return reqGet("/Calendar/Get", { calendar_id: calendarId });
|
|
876
|
+
};
|
|
877
|
+
CalendarModel.get = async (calendarId) => {
|
|
878
|
+
var _a, _b;
|
|
879
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
880
|
+
const res = await reqGet("/Calendar/Get", { calendar_id: calendarId });
|
|
881
|
+
if (res.status === "success" && res.data) {
|
|
882
|
+
const raw = ((_a = res.data) == null ? void 0 : _a.data) ?? ((_b = res.data) == null ? void 0 : _b.Data) ?? res.data;
|
|
883
|
+
const mapped = mapCalendarFromApi({ ...raw, calendar_id: calendarId });
|
|
884
|
+
return CalendarModel.create(mapped, { env: getConfig() });
|
|
885
|
+
}
|
|
886
|
+
return null;
|
|
887
|
+
};
|
|
888
|
+
CalendarModel.getByCompany = async (companyKey) => {
|
|
889
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
890
|
+
const res = await reqGet("/Calendar/All", { company_key: companyKey });
|
|
891
|
+
if (res.status === "success" && Array.isArray(res.data)) {
|
|
892
|
+
return res.data.map(
|
|
893
|
+
(c) => CalendarModel.create(mapCalendarFromApi(c), { env: getConfig() })
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
return null;
|
|
897
|
+
};
|
|
898
|
+
CalendarModel.getTimeZones = async () => {
|
|
899
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
900
|
+
const res = await reqGet("/Calendar/TimeZones/Get");
|
|
901
|
+
return res.status === "success" && res.data != null ? res.data : null;
|
|
902
|
+
};
|
|
903
|
+
CalendarModel.getTimeZone = async (timezoneId) => {
|
|
904
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
905
|
+
const res = await reqGet("/Calendar/TimeZone/Get", { timezone_id: timezoneId });
|
|
906
|
+
return res.status === "success" && res.data != null ? res.data : null;
|
|
907
|
+
};
|
|
908
|
+
CalendarModel.getParticipants = async (calendarId) => {
|
|
909
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
910
|
+
const res = await reqGet("/Calendar/Participant/All", { calendar_id: calendarId });
|
|
911
|
+
if (res.status === "success" && Array.isArray(res.data)) {
|
|
912
|
+
return res.data.map(
|
|
913
|
+
(p) => CalendarParticipant_default.create({
|
|
914
|
+
...p,
|
|
915
|
+
participantId: p.participantId ?? p.participant_id ?? "",
|
|
916
|
+
calendarId: p.calendarId ?? p.calendar_id ?? calendarId,
|
|
917
|
+
calendarParticipantId: p.calendarParticipantId ?? p.calendarparticipant_id ?? ""
|
|
918
|
+
})
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
return null;
|
|
922
|
+
};
|
|
923
|
+
CalendarModel.getCalendarParticipant = async (calendarId) => {
|
|
924
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
925
|
+
const res = await reqGet("/Calendar/Participant/Get", { calendar_id: calendarId });
|
|
926
|
+
if (res.status === "success" && Array.isArray(res.data)) {
|
|
927
|
+
return res.data.map(
|
|
928
|
+
(p) => CalendarParticipant_default.create({
|
|
929
|
+
...p,
|
|
930
|
+
participantId: p.participantId ?? p.participant_id ?? "",
|
|
931
|
+
calendarId: p.calendarId ?? p.calendar_id ?? calendarId,
|
|
932
|
+
calendarParticipantId: p.calendarParticipantId ?? p.calendarparticipant_id ?? ""
|
|
933
|
+
})
|
|
934
|
+
);
|
|
935
|
+
}
|
|
936
|
+
return null;
|
|
937
|
+
};
|
|
938
|
+
CalendarModel.getParticipantsInfo = async (calendarId) => {
|
|
939
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
940
|
+
const res = await reqGet("/Calendar/Participants/GetInfo", { calendar_id: calendarId });
|
|
941
|
+
if (res.status === "success" && Array.isArray(res.data)) {
|
|
942
|
+
return res.data.map(
|
|
943
|
+
(p) => ParticipantInfo_default.create({
|
|
944
|
+
participantId: p.participantId ?? p.participant_id ?? "",
|
|
945
|
+
calendarParticipantId: p.calendarParticipantId ?? p.calendarparticipant_id ?? "",
|
|
946
|
+
alias: p.alias ?? null,
|
|
947
|
+
email: p.email ?? null,
|
|
948
|
+
isApproved: p.isApproved ?? p.is_approved ?? false,
|
|
949
|
+
emailProvider: p.emailProvider ?? p.email_provider ?? 0,
|
|
950
|
+
isAvailable: p.isAvailable ?? p.is_available ?? false
|
|
951
|
+
})
|
|
952
|
+
);
|
|
953
|
+
}
|
|
954
|
+
return null;
|
|
955
|
+
};
|
|
956
|
+
CalendarModel.getMonth = async (calendarId, year, month) => {
|
|
957
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
958
|
+
const res = await reqGet("/Calendar/Month/Get", { calendar_id: calendarId, year, month });
|
|
959
|
+
if (res.status === "success" && Array.isArray(res.data)) {
|
|
960
|
+
return res.data.map((d) => CalendarDay_default.create({ date: d.date ?? d.Date ?? "" }));
|
|
961
|
+
}
|
|
962
|
+
return null;
|
|
963
|
+
};
|
|
964
|
+
CalendarModel.getEvents = async (calendarId) => {
|
|
965
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
966
|
+
const res = await reqGet("/Calendar/Events/Get", { calendar_id: calendarId });
|
|
967
|
+
if (res.status === "success" && Array.isArray(res.data)) {
|
|
968
|
+
return res.data.map(
|
|
969
|
+
(ev) => Event_default.create(
|
|
970
|
+
{
|
|
971
|
+
...ev,
|
|
972
|
+
eventId: ev.eventId ?? ev.event_id ?? "",
|
|
973
|
+
calendarId: ev.calendarId ?? ev.calendar_id ?? calendarId
|
|
974
|
+
},
|
|
975
|
+
{ env: getConfig() }
|
|
976
|
+
)
|
|
977
|
+
);
|
|
978
|
+
}
|
|
979
|
+
return null;
|
|
980
|
+
};
|
|
981
|
+
CalendarModel.createWithParticipants = async (name, companyKey, participantIds, description, calendarId) => {
|
|
982
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
983
|
+
const q = {
|
|
984
|
+
name,
|
|
985
|
+
company_key: companyKey,
|
|
986
|
+
participantids: Array.isArray(participantIds) ? participantIds.join(",") : String(participantIds)
|
|
987
|
+
};
|
|
988
|
+
if (description) q.description = description;
|
|
989
|
+
if (calendarId) q.calendar_id = calendarId;
|
|
990
|
+
const res = await reqGet("/Calendar/CreateWithParticipants", q);
|
|
991
|
+
if (res.status === "success" && res.data) {
|
|
992
|
+
const id = typeof res.data === "string" ? res.data : res.data.calendarId ?? res.data.calendar_id;
|
|
993
|
+
return CalendarModel.get(id);
|
|
994
|
+
}
|
|
995
|
+
return null;
|
|
996
|
+
};
|
|
997
|
+
CalendarModel.editWithParticipants = async (calendarId, name, participantIds, description) => {
|
|
998
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
999
|
+
const q = {
|
|
1000
|
+
calendar_id: calendarId,
|
|
1001
|
+
name,
|
|
1002
|
+
participantids: Array.isArray(participantIds) ? participantIds.join(",") : String(participantIds)
|
|
1003
|
+
};
|
|
1004
|
+
if (description) q.description = description;
|
|
1005
|
+
const res = await reqGet("/Calendar/EditWithParticipants", q);
|
|
1006
|
+
if (res.status === "success") {
|
|
1007
|
+
return CalendarModel.get(calendarId);
|
|
1008
|
+
}
|
|
1009
|
+
return null;
|
|
1010
|
+
};
|
|
1011
|
+
var Calendar_default = CalendarModel;
|
|
573
1012
|
|
|
574
|
-
// src/models/appointment/
|
|
1013
|
+
// src/models/appointment/Availability.js
|
|
575
1014
|
var import_mobx_state_tree8 = require("mobx-state-tree");
|
|
576
|
-
var
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
setWithOffset(offsetMinutes) {
|
|
586
|
-
const start = new Date(self.startDate);
|
|
587
|
-
const end = new Date(self.endDate);
|
|
588
|
-
start.setMinutes(start.getMinutes() + offsetMinutes);
|
|
589
|
-
end.setMinutes(end.getMinutes() + offsetMinutes);
|
|
590
|
-
self.startDate = start.toISOString();
|
|
591
|
-
self.endDate = end.toISOString();
|
|
592
|
-
self.startHour = start.getHours();
|
|
593
|
-
self.startMinute = start.getMinutes();
|
|
594
|
-
self.endHour = end.getHours();
|
|
595
|
-
self.endMinute = end.getMinutes();
|
|
596
|
-
}
|
|
597
|
-
}));
|
|
598
|
-
var TimeSlot_default = TimeSlotModel;
|
|
1015
|
+
var AvailabilityModel = import_mobx_state_tree8.types.model("Availability", {
|
|
1016
|
+
id: import_mobx_state_tree8.types.maybeNull(import_mobx_state_tree8.types.number),
|
|
1017
|
+
availabilityId: import_mobx_state_tree8.types.string,
|
|
1018
|
+
calendarId: import_mobx_state_tree8.types.string,
|
|
1019
|
+
participantId: import_mobx_state_tree8.types.string,
|
|
1020
|
+
createdOn: import_mobx_state_tree8.types.maybeNull(import_mobx_state_tree8.types.string),
|
|
1021
|
+
modifiedOn: import_mobx_state_tree8.types.maybeNull(import_mobx_state_tree8.types.string)
|
|
1022
|
+
});
|
|
1023
|
+
var Availability_default = AvailabilityModel;
|
|
599
1024
|
|
|
600
|
-
// src/models/appointment/
|
|
1025
|
+
// src/models/appointment/AvailabilityDetail.js
|
|
601
1026
|
var import_mobx_state_tree9 = require("mobx-state-tree");
|
|
602
|
-
var
|
|
603
|
-
|
|
604
|
-
|
|
1027
|
+
var AvailabilityDetailModel = import_mobx_state_tree9.types.model("AvailabilityDetail", {
|
|
1028
|
+
id: import_mobx_state_tree9.types.maybeNull(import_mobx_state_tree9.types.number),
|
|
1029
|
+
availabilityId: import_mobx_state_tree9.types.string,
|
|
1030
|
+
sunday: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.boolean, false),
|
|
1031
|
+
monday: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.boolean, false),
|
|
1032
|
+
tuesday: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.boolean, false),
|
|
1033
|
+
wednesday: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.boolean, false),
|
|
1034
|
+
thursday: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.boolean, false),
|
|
1035
|
+
friday: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.boolean, false),
|
|
1036
|
+
saturday: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.boolean, false),
|
|
1037
|
+
startHour: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.number, 0),
|
|
1038
|
+
startMinute: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.number, 0),
|
|
1039
|
+
endHour: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.number, 0),
|
|
1040
|
+
endMinute: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.number, 0),
|
|
1041
|
+
createdOn: import_mobx_state_tree9.types.maybeNull(import_mobx_state_tree9.types.string),
|
|
1042
|
+
modifiedOn: import_mobx_state_tree9.types.maybeNull(import_mobx_state_tree9.types.string)
|
|
1043
|
+
});
|
|
1044
|
+
var AvailabilityDetail_default = AvailabilityDetailModel;
|
|
1045
|
+
|
|
1046
|
+
// src/models/appointment/Participant.js
|
|
1047
|
+
var import_mobx_state_tree10 = require("mobx-state-tree");
|
|
1048
|
+
var ParticipantModel = import_mobx_state_tree10.types.model("Participant", {
|
|
1049
|
+
id: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.maybeNull(import_mobx_state_tree10.types.number), null),
|
|
1050
|
+
participantId: import_mobx_state_tree10.types.identifier,
|
|
1051
|
+
companyKey: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.maybeNull(import_mobx_state_tree10.types.string), null),
|
|
1052
|
+
alias: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.string, ""),
|
|
1053
|
+
email: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.string, ""),
|
|
1054
|
+
isApproved: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.boolean, false),
|
|
1055
|
+
isAvailable: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.boolean, false),
|
|
1056
|
+
provider: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.number, 0),
|
|
1057
|
+
createdOn: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.maybeNull(import_mobx_state_tree10.types.string), null),
|
|
1058
|
+
modifiedOn: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.maybeNull(import_mobx_state_tree10.types.string), null),
|
|
1059
|
+
isDeleted: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.boolean, false)
|
|
1060
|
+
}).actions((self) => {
|
|
1061
|
+
const { reqGet, reqPost } = createRequestHelpers(self, import_mobx_state_tree10.getEnv);
|
|
1062
|
+
return {
|
|
1063
|
+
/** GET participant/get – fetch this participant */
|
|
1064
|
+
async get() {
|
|
1065
|
+
const res = await reqGet("/participant/get", { participant_id: self.participantId });
|
|
1066
|
+
if (res.status === "success" && res.data) (0, import_mobx_state_tree10.applySnapshot)(self, mapFromApi2(res.data));
|
|
1067
|
+
return res;
|
|
1068
|
+
},
|
|
1069
|
+
/** POST participant/save – save participant (add or update) */
|
|
1070
|
+
async save() {
|
|
1071
|
+
const payload = toPayload(self);
|
|
1072
|
+
const res = await reqPost("/participant/save", payload);
|
|
1073
|
+
if (res.status === "success" && res.data) (0, import_mobx_state_tree10.applySnapshot)(self, mapFromApi2(res.data));
|
|
1074
|
+
return res;
|
|
1075
|
+
},
|
|
1076
|
+
/** POST participant/update – update participant */
|
|
1077
|
+
async update() {
|
|
1078
|
+
const payload = toPayload(self);
|
|
1079
|
+
const res = await reqPost("/participant/update", payload);
|
|
1080
|
+
if (res.status === "success" && res.data) (0, import_mobx_state_tree10.applySnapshot)(self, mapFromApi2(res.data));
|
|
1081
|
+
return res;
|
|
1082
|
+
},
|
|
1083
|
+
/** GET participant/remove – remove this participant */
|
|
1084
|
+
async remove() {
|
|
1085
|
+
return reqGet("/participant/remove", { participant_id: self.participantId });
|
|
1086
|
+
},
|
|
1087
|
+
/** GET participant/sendemail – send email to this participant */
|
|
1088
|
+
async sendEmail() {
|
|
1089
|
+
return reqGet("/participant/sendemail", { participant_id: self.participantId });
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
});
|
|
1093
|
+
function mapFromApi2(d) {
|
|
1094
|
+
if (!d) return d;
|
|
1095
|
+
const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1096
|
+
const n = (v) => v != null && v !== "" ? Number(v) : void 0;
|
|
1097
|
+
return {
|
|
1098
|
+
participantId: String(pick("participantId", "ParticipantId", "participant_id") ?? ""),
|
|
1099
|
+
companyKey: pick("companyKey", "CompanyKey", "company_key") ?? null,
|
|
1100
|
+
alias: pick("alias", "Alias") ?? "",
|
|
1101
|
+
email: pick("email", "Email") ?? "",
|
|
1102
|
+
isApproved: Boolean(pick("isApproved", "IsApproved", "is_approved")),
|
|
1103
|
+
isAvailable: Boolean(pick("isAvailable", "IsAvailable", "is_available")),
|
|
1104
|
+
provider: n(pick("provider", "Provider")) ?? 0,
|
|
1105
|
+
createdOn: pick("createdOn", "CreatedOn", "created_on") ?? null,
|
|
1106
|
+
modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on") ?? null,
|
|
1107
|
+
isDeleted: Boolean(pick("isDeleted", "IsDeleted", "is_deleted"))
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
function toPayload(self) {
|
|
1111
|
+
return {
|
|
1112
|
+
participantId: self.participantId,
|
|
1113
|
+
companyKey: self.companyKey ?? void 0,
|
|
1114
|
+
alias: self.alias,
|
|
1115
|
+
email: self.email,
|
|
1116
|
+
isApproved: self.isApproved,
|
|
1117
|
+
isAvailable: self.isAvailable,
|
|
1118
|
+
provider: self.provider
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
ParticipantModel.get = async (participantId) => {
|
|
1122
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
1123
|
+
const res = await reqGet("/participant/get", { participant_id: participantId });
|
|
1124
|
+
if (res.status === "success" && res.data) {
|
|
1125
|
+
return ParticipantModel.create(mapFromApi2(res.data), { env: getConfig() });
|
|
1126
|
+
}
|
|
1127
|
+
return null;
|
|
1128
|
+
};
|
|
1129
|
+
ParticipantModel.getByIds = async (participantIds) => {
|
|
1130
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
1131
|
+
const ids = Array.isArray(participantIds) ? participantIds.join(",") : String(participantIds);
|
|
1132
|
+
const res = await reqGet("/participant/participants/get", { participantids: ids });
|
|
1133
|
+
if (res.status === "success" && Array.isArray(res.data)) {
|
|
1134
|
+
return res.data.map((p) => ParticipantModel.create(mapFromApi2(p), { env: getConfig() }));
|
|
1135
|
+
}
|
|
1136
|
+
return null;
|
|
1137
|
+
};
|
|
1138
|
+
ParticipantModel.getAll = async (companyKey) => {
|
|
1139
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
1140
|
+
const res = await reqGet("/Participant/All", { company_key: companyKey });
|
|
1141
|
+
if (res.status === "success" && Array.isArray(res.data)) {
|
|
1142
|
+
return res.data.map((p) => ParticipantModel.create(mapFromApi2(p), { env: getConfig() }));
|
|
1143
|
+
}
|
|
1144
|
+
return null;
|
|
1145
|
+
};
|
|
1146
|
+
ParticipantModel.add = async (payload, calendarId) => {
|
|
1147
|
+
const { reqPost } = createRequestHelpersFromEnv(getConfig());
|
|
1148
|
+
const query = calendarId ? { calendar_id: calendarId } : null;
|
|
1149
|
+
const res = await reqPost("/Participant/Add", payload, query);
|
|
1150
|
+
if (res.status === "success" && res.data) {
|
|
1151
|
+
return ParticipantModel.create(mapFromApi2(res.data), { env: getConfig() });
|
|
1152
|
+
}
|
|
1153
|
+
return null;
|
|
1154
|
+
};
|
|
1155
|
+
ParticipantModel.remove = async (participantId) => {
|
|
1156
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
1157
|
+
return reqGet("/participant/remove", { participant_id: participantId });
|
|
1158
|
+
};
|
|
1159
|
+
ParticipantModel.update = async (payload) => {
|
|
1160
|
+
const { reqPost } = createRequestHelpersFromEnv(getConfig());
|
|
1161
|
+
return reqPost("/participant/update", payload);
|
|
1162
|
+
};
|
|
1163
|
+
ParticipantModel.save = async (payload) => {
|
|
1164
|
+
const { reqPost } = createRequestHelpersFromEnv(getConfig());
|
|
1165
|
+
const res = await reqPost("/participant/save", payload);
|
|
1166
|
+
if (res.status === "success" && res.data) {
|
|
1167
|
+
return ParticipantModel.create(mapFromApi2(res.data), { env: getConfig() });
|
|
1168
|
+
}
|
|
1169
|
+
return null;
|
|
1170
|
+
};
|
|
1171
|
+
ParticipantModel.sendEmail = async (participantId) => {
|
|
1172
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
1173
|
+
return reqGet("/participant/sendemail", { participant_id: participantId });
|
|
1174
|
+
};
|
|
1175
|
+
var Participant_default = ParticipantModel;
|
|
1176
|
+
|
|
1177
|
+
// src/models/appointment/OpeningHour.js
|
|
1178
|
+
var import_mobx_state_tree11 = require("mobx-state-tree");
|
|
1179
|
+
var OpeningHourModel = import_mobx_state_tree11.types.model("OpeningHour", {
|
|
1180
|
+
id: import_mobx_state_tree11.types.maybeNull(import_mobx_state_tree11.types.number),
|
|
1181
|
+
openingHourId: import_mobx_state_tree11.types.optional(import_mobx_state_tree11.types.string, ""),
|
|
1182
|
+
calendarId: import_mobx_state_tree11.types.string,
|
|
1183
|
+
participantId: import_mobx_state_tree11.types.string,
|
|
1184
|
+
day: import_mobx_state_tree11.types.optional(import_mobx_state_tree11.types.number, 0),
|
|
1185
|
+
startHour: import_mobx_state_tree11.types.optional(import_mobx_state_tree11.types.number, 0),
|
|
1186
|
+
startMinute: import_mobx_state_tree11.types.optional(import_mobx_state_tree11.types.number, 0),
|
|
1187
|
+
endHour: import_mobx_state_tree11.types.optional(import_mobx_state_tree11.types.number, 0),
|
|
1188
|
+
endMinute: import_mobx_state_tree11.types.optional(import_mobx_state_tree11.types.number, 0),
|
|
1189
|
+
off: import_mobx_state_tree11.types.optional(import_mobx_state_tree11.types.boolean, false),
|
|
1190
|
+
createdOn: import_mobx_state_tree11.types.maybeNull(import_mobx_state_tree11.types.string),
|
|
1191
|
+
modifiedOn: import_mobx_state_tree11.types.maybeNull(import_mobx_state_tree11.types.string)
|
|
1192
|
+
});
|
|
1193
|
+
var OpeningHour_default = OpeningHourModel;
|
|
1194
|
+
|
|
1195
|
+
// src/models/appointment/TimeFrame.js
|
|
1196
|
+
var import_mobx_state_tree12 = require("mobx-state-tree");
|
|
1197
|
+
var TimeFrameModel = import_mobx_state_tree12.types.model("TimeFrame", {
|
|
1198
|
+
start: import_mobx_state_tree12.types.string,
|
|
1199
|
+
end: import_mobx_state_tree12.types.string
|
|
605
1200
|
}).actions((self) => ({
|
|
606
1201
|
buffer(bufferMinutes, unit) {
|
|
607
1202
|
const bfr = unit === Unit.Hours ? bufferMinutes * 60 : bufferMinutes;
|
|
@@ -651,28 +1246,238 @@ var TimeFrameModel = import_mobx_state_tree9.types.model("TimeFrame", {
|
|
|
651
1246
|
}));
|
|
652
1247
|
var TimeFrame_default = TimeFrameModel;
|
|
653
1248
|
|
|
654
|
-
// src/models/appointment/Setting.
|
|
655
|
-
var
|
|
656
|
-
var SettingModel =
|
|
657
|
-
id:
|
|
658
|
-
settingsId:
|
|
659
|
-
calendarId:
|
|
660
|
-
logo:
|
|
661
|
-
theme:
|
|
662
|
-
schedulingButtonText:
|
|
663
|
-
scheduledMessage:
|
|
1249
|
+
// src/models/appointment/Setting.js
|
|
1250
|
+
var import_mobx_state_tree13 = require("mobx-state-tree");
|
|
1251
|
+
var SettingModel = import_mobx_state_tree13.types.model("Setting", {
|
|
1252
|
+
id: import_mobx_state_tree13.types.optional(import_mobx_state_tree13.types.maybeNull(import_mobx_state_tree13.types.number), null),
|
|
1253
|
+
settingsId: import_mobx_state_tree13.types.optional(import_mobx_state_tree13.types.string, ""),
|
|
1254
|
+
calendarId: import_mobx_state_tree13.types.optional(import_mobx_state_tree13.types.string, ""),
|
|
1255
|
+
logo: import_mobx_state_tree13.types.optional(import_mobx_state_tree13.types.maybeNull(import_mobx_state_tree13.types.string), null),
|
|
1256
|
+
theme: import_mobx_state_tree13.types.optional(import_mobx_state_tree13.types.maybeNull(import_mobx_state_tree13.types.string), null),
|
|
1257
|
+
schedulingButtonText: import_mobx_state_tree13.types.optional(import_mobx_state_tree13.types.maybeNull(import_mobx_state_tree13.types.string), null),
|
|
1258
|
+
scheduledMessage: import_mobx_state_tree13.types.optional(import_mobx_state_tree13.types.maybeNull(import_mobx_state_tree13.types.string), null)
|
|
1259
|
+
}).actions((self) => {
|
|
1260
|
+
const { reqGet, reqPost } = createRequestHelpers(self, import_mobx_state_tree13.getEnv);
|
|
1261
|
+
return {
|
|
1262
|
+
/** GET setting/get – fetch setting for this calendar */
|
|
1263
|
+
async get() {
|
|
1264
|
+
const res = await reqGet("/setting/get", { calendar_id: self.calendarId });
|
|
1265
|
+
if (res.status === "success" && res.data) (0, import_mobx_state_tree13.applySnapshot)(self, mapFromApi3(res.data));
|
|
1266
|
+
return res;
|
|
1267
|
+
},
|
|
1268
|
+
/** POST setting/save – save this setting */
|
|
1269
|
+
async save() {
|
|
1270
|
+
const payload = toPayload2(self);
|
|
1271
|
+
const res = await reqPost("/setting/save", payload);
|
|
1272
|
+
if (res.status === "success" && res.data) (0, import_mobx_state_tree13.applySnapshot)(self, mapFromApi3(res.data));
|
|
1273
|
+
return res;
|
|
1274
|
+
},
|
|
1275
|
+
/** POST setting/logo/upload – upload logo file for this calendar */
|
|
1276
|
+
async uploadLogo(file) {
|
|
1277
|
+
return SettingModel.uploadLogo(self.calendarId, file);
|
|
1278
|
+
}
|
|
1279
|
+
};
|
|
664
1280
|
});
|
|
1281
|
+
function mapFromApi3(d) {
|
|
1282
|
+
if (!d) return d;
|
|
1283
|
+
const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1284
|
+
return {
|
|
1285
|
+
settingsId: String(pick("settingsId", "SettingsId", "settings_id") ?? ""),
|
|
1286
|
+
calendarId: String(pick("calendarId", "CalendarId", "calendar_id") ?? ""),
|
|
1287
|
+
logo: pick("logo", "Logo") ?? null,
|
|
1288
|
+
theme: pick("theme", "Theme") ?? null,
|
|
1289
|
+
schedulingButtonText: pick("schedulingButtonText", "SchedulingButtonText", "scheduling_button_text") ?? null,
|
|
1290
|
+
scheduledMessage: pick("scheduledMessage", "ScheduledMessage", "scheduled_message") ?? null
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
function toPayload2(self) {
|
|
1294
|
+
return {
|
|
1295
|
+
settingsId: self.settingsId || void 0,
|
|
1296
|
+
calendarId: self.calendarId,
|
|
1297
|
+
logo: self.logo ?? void 0,
|
|
1298
|
+
theme: self.theme ?? void 0,
|
|
1299
|
+
schedulingButtonText: self.schedulingButtonText ?? void 0,
|
|
1300
|
+
scheduledMessage: self.scheduledMessage ?? void 0
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
SettingModel.get = async (calendarId) => {
|
|
1304
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
1305
|
+
const res = await reqGet("/setting/get", { calendar_id: calendarId });
|
|
1306
|
+
if (res.status === "success" && res.data) {
|
|
1307
|
+
return SettingModel.create(mapFromApi3(res.data), { env: getConfig() });
|
|
1308
|
+
}
|
|
1309
|
+
return null;
|
|
1310
|
+
};
|
|
1311
|
+
SettingModel.save = async (payload) => {
|
|
1312
|
+
const { reqPost } = createRequestHelpersFromEnv(getConfig());
|
|
1313
|
+
return reqPost("/setting/save", payload);
|
|
1314
|
+
};
|
|
1315
|
+
SettingModel.uploadLogo = async (calendarId, file) => {
|
|
1316
|
+
const cfg = getConfig();
|
|
1317
|
+
if (!(cfg == null ? void 0 : cfg.baseUrl)) throw new Error("Configure baseUrl before uploadLogo");
|
|
1318
|
+
const fetchFn = cfg.fetch ?? (typeof fetch !== "undefined" ? fetch : () => {
|
|
1319
|
+
throw new Error("fetch not available");
|
|
1320
|
+
});
|
|
1321
|
+
const baseUrl = String(cfg.baseUrl).replace(/\/+$/, "");
|
|
1322
|
+
const url = `${baseUrl}/setting/logo/upload?calendar_id=${encodeURIComponent(calendarId)}`;
|
|
1323
|
+
const formData = new FormData();
|
|
1324
|
+
formData.append("file", file);
|
|
1325
|
+
const res = await fetchFn(url, {
|
|
1326
|
+
method: "POST",
|
|
1327
|
+
body: formData
|
|
1328
|
+
});
|
|
1329
|
+
const text = await res.text();
|
|
1330
|
+
let data;
|
|
1331
|
+
try {
|
|
1332
|
+
data = JSON.parse(text);
|
|
1333
|
+
} catch {
|
|
1334
|
+
data = { status: "failure", message: text || res.statusText };
|
|
1335
|
+
}
|
|
1336
|
+
if (!res.ok && data.status !== "failure") {
|
|
1337
|
+
data.status = "failure";
|
|
1338
|
+
data.message = data.message ?? `HTTP ${res.status}`;
|
|
1339
|
+
}
|
|
1340
|
+
return data;
|
|
1341
|
+
};
|
|
665
1342
|
var Setting_default = SettingModel;
|
|
666
1343
|
|
|
667
|
-
// src/models/appointment/
|
|
668
|
-
var
|
|
669
|
-
var
|
|
670
|
-
|
|
671
|
-
|
|
1344
|
+
// src/models/appointment/Company.js
|
|
1345
|
+
var import_mobx_state_tree14 = require("mobx-state-tree");
|
|
1346
|
+
var CompanyModel = import_mobx_state_tree14.types.model("Company", {
|
|
1347
|
+
id: import_mobx_state_tree14.types.optional(import_mobx_state_tree14.types.maybeNull(import_mobx_state_tree14.types.number), null),
|
|
1348
|
+
companyKey: import_mobx_state_tree14.types.identifier,
|
|
1349
|
+
companyName: import_mobx_state_tree14.types.optional(import_mobx_state_tree14.types.string, ""),
|
|
1350
|
+
createdOn: import_mobx_state_tree14.types.optional(import_mobx_state_tree14.types.maybeNull(import_mobx_state_tree14.types.string), null),
|
|
1351
|
+
modifiedOn: import_mobx_state_tree14.types.optional(import_mobx_state_tree14.types.maybeNull(import_mobx_state_tree14.types.string), null)
|
|
1352
|
+
}).actions((self) => {
|
|
1353
|
+
const { reqGet, reqPost } = createRequestHelpers(self, import_mobx_state_tree14.getEnv);
|
|
1354
|
+
return {
|
|
1355
|
+
/** GET Company/Get – fetch this company */
|
|
1356
|
+
async get() {
|
|
1357
|
+
const res = await reqGet("/Company/Get", { company_key: self.companyKey });
|
|
1358
|
+
if (res.status === "success" && res.data) (0, import_mobx_state_tree14.applySnapshot)(self, mapFromApi4(res.data));
|
|
1359
|
+
return res;
|
|
1360
|
+
},
|
|
1361
|
+
/** POST Company/Save – save this company */
|
|
1362
|
+
async save() {
|
|
1363
|
+
const payload = toPayload3(self);
|
|
1364
|
+
const res = await reqPost("/Company/Save", payload);
|
|
1365
|
+
if (res.status === "success" && res.data) (0, import_mobx_state_tree14.applySnapshot)(self, mapFromApi4(res.data));
|
|
1366
|
+
return res;
|
|
1367
|
+
}
|
|
1368
|
+
};
|
|
1369
|
+
});
|
|
1370
|
+
function mapFromApi4(d) {
|
|
1371
|
+
if (!d) return d;
|
|
1372
|
+
const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1373
|
+
return {
|
|
1374
|
+
companyKey: String(pick("companyKey", "CompanyKey", "company_key") ?? ""),
|
|
1375
|
+
companyName: pick("companyName", "CompanyName", "company_name") ?? "",
|
|
1376
|
+
createdOn: pick("createdOn", "CreatedOn", "created_on") ?? null,
|
|
1377
|
+
modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on") ?? null
|
|
1378
|
+
};
|
|
1379
|
+
}
|
|
1380
|
+
function toPayload3(self) {
|
|
1381
|
+
return {
|
|
1382
|
+
companyKey: self.companyKey,
|
|
1383
|
+
companyName: self.companyName ?? void 0
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1386
|
+
CompanyModel.get = async (companyKey) => {
|
|
1387
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
1388
|
+
const res = await reqGet("/Company/Get", { company_key: companyKey });
|
|
1389
|
+
if (res.status === "success" && res.data) {
|
|
1390
|
+
return CompanyModel.create(mapFromApi4(res.data), { env: getConfig() });
|
|
1391
|
+
}
|
|
1392
|
+
return null;
|
|
1393
|
+
};
|
|
1394
|
+
CompanyModel.getAll = async () => {
|
|
1395
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
1396
|
+
const res = await reqGet("/Company/All");
|
|
1397
|
+
if (res.status === "success" && Array.isArray(res.data)) {
|
|
1398
|
+
return res.data.map((c) => CompanyModel.create(mapFromApi4(c), { env: getConfig() }));
|
|
1399
|
+
}
|
|
1400
|
+
return null;
|
|
1401
|
+
};
|
|
1402
|
+
CompanyModel.save = async (payload) => {
|
|
1403
|
+
const { reqPost } = createRequestHelpersFromEnv(getConfig());
|
|
1404
|
+
const res = await reqPost("/Company/Save", payload);
|
|
1405
|
+
if (res.status === "success" && res.data) {
|
|
1406
|
+
return CompanyModel.create(mapFromApi4(res.data), { env: getConfig() });
|
|
1407
|
+
}
|
|
1408
|
+
return null;
|
|
1409
|
+
};
|
|
1410
|
+
var Company_default = CompanyModel;
|
|
1411
|
+
|
|
1412
|
+
// src/models/appointment/Preference.js
|
|
1413
|
+
var import_mobx_state_tree15 = require("mobx-state-tree");
|
|
1414
|
+
var PreferenceScope = {
|
|
1415
|
+
Global: 0,
|
|
1416
|
+
Consumer: 1,
|
|
1417
|
+
Company: 2,
|
|
1418
|
+
Calendar: 3,
|
|
1419
|
+
Event: 4
|
|
1420
|
+
};
|
|
1421
|
+
var SCOPE_NAMES = ["Global", "Consumer", "Company", "Calendar", "Event"];
|
|
1422
|
+
var PreferenceModel = import_mobx_state_tree15.types.model("Preference", {
|
|
1423
|
+
id: import_mobx_state_tree15.types.optional(import_mobx_state_tree15.types.maybeNull(import_mobx_state_tree15.types.number), null),
|
|
1424
|
+
preferenceId: import_mobx_state_tree15.types.optional(import_mobx_state_tree15.types.maybeNull(import_mobx_state_tree15.types.string), null),
|
|
1425
|
+
level: import_mobx_state_tree15.types.optional(import_mobx_state_tree15.types.number, 0),
|
|
1426
|
+
primaryKey: import_mobx_state_tree15.types.optional(import_mobx_state_tree15.types.string, ""),
|
|
1427
|
+
preferenceOption: import_mobx_state_tree15.types.optional(import_mobx_state_tree15.types.string, ""),
|
|
1428
|
+
optionsJson: import_mobx_state_tree15.types.optional(import_mobx_state_tree15.types.maybeNull(import_mobx_state_tree15.types.string), null)
|
|
672
1429
|
}).actions((self) => ({
|
|
673
|
-
|
|
674
|
-
|
|
1430
|
+
/** POST /preference/{scope}/{key}/{option} – save this preference to the API. */
|
|
1431
|
+
async save() {
|
|
1432
|
+
const scope = SCOPE_NAMES[self.level] ?? "Global";
|
|
1433
|
+
return PreferenceModel.set(scope, self.primaryKey, self.preferenceOption, self.optionsJson ?? "{}");
|
|
675
1434
|
},
|
|
1435
|
+
/** GET /preference/remove?preference_id={id} – remove this preference from the API. Requires preferenceId from a prior get. */
|
|
1436
|
+
async delete() {
|
|
1437
|
+
if (!self.preferenceId) throw new Error("preferenceId required for delete; use PreferenceModel.delete(preferenceId) or load preference from get first.");
|
|
1438
|
+
return PreferenceModel.delete(self.preferenceId);
|
|
1439
|
+
}
|
|
1440
|
+
}));
|
|
1441
|
+
PreferenceModel.getScopes = async () => {
|
|
1442
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
1443
|
+
const res = await reqGet("/preference/scopes");
|
|
1444
|
+
return res.status === "success" && res.data != null ? res.data : null;
|
|
1445
|
+
};
|
|
1446
|
+
PreferenceModel.getOptions = async () => {
|
|
1447
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
1448
|
+
const res = await reqGet("/preference/options");
|
|
1449
|
+
return res.status === "success" && res.data != null ? res.data : null;
|
|
1450
|
+
};
|
|
1451
|
+
PreferenceModel.getOptionTemplate = async (option) => {
|
|
1452
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
1453
|
+
const res = await reqGet(`/preference/options/${encodeURIComponent(option)}`);
|
|
1454
|
+
return res.status === "success" && res.data != null ? res.data : null;
|
|
1455
|
+
};
|
|
1456
|
+
PreferenceModel.get = async (option, keys) => {
|
|
1457
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
1458
|
+
const keysArr = Array.isArray(keys) ? keys : keys != null ? [String(keys)] : [];
|
|
1459
|
+
const query = keysArr.length ? { keys: keysArr } : {};
|
|
1460
|
+
const res = await reqGet(`/preference/${encodeURIComponent(option)}`, query);
|
|
1461
|
+
return res.status === "success" && res.data != null ? res.data : null;
|
|
1462
|
+
};
|
|
1463
|
+
PreferenceModel.set = async (scope, key, option, body) => {
|
|
1464
|
+
const { req } = createRequestHelpersFromEnv(getConfig());
|
|
1465
|
+
const path = `/preference/${encodeURIComponent(scope)}/${encodeURIComponent(key)}/${encodeURIComponent(option)}`;
|
|
1466
|
+
const payload = typeof body === "string" ? body : JSON.stringify(body ?? {});
|
|
1467
|
+
return req(path, { method: "POST", body: payload });
|
|
1468
|
+
};
|
|
1469
|
+
PreferenceModel.delete = async (preferenceId) => {
|
|
1470
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
1471
|
+
return reqGet("/preference/remove", { preference_id: preferenceId });
|
|
1472
|
+
};
|
|
1473
|
+
var Preference_default = PreferenceModel;
|
|
1474
|
+
|
|
1475
|
+
// src/models/appointment/index.js
|
|
1476
|
+
var import_mobx_state_tree16 = require("mobx-state-tree");
|
|
1477
|
+
var RootStore = import_mobx_state_tree16.types.model("RootStore", {
|
|
1478
|
+
calendars: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.map(Calendar_default), {}),
|
|
1479
|
+
events: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.map(Event_default), {})
|
|
1480
|
+
}).actions((self) => ({
|
|
676
1481
|
addCalendar(snapshot) {
|
|
677
1482
|
const cal = Calendar_default.create(snapshot);
|
|
678
1483
|
self.calendars.set(cal.calendarId, cal);
|
|
@@ -684,24 +1489,38 @@ var RootStore = import_mobx_state_tree11.types.model("RootStore", {
|
|
|
684
1489
|
return ev;
|
|
685
1490
|
}
|
|
686
1491
|
}));
|
|
1492
|
+
function createRootStore(initialState = {}) {
|
|
1493
|
+
const env = getConfig();
|
|
1494
|
+
if (!env) throw new Error("Call configure({ baseUrl }) before createRootStore()");
|
|
1495
|
+
return RootStore.create(initialState, { env });
|
|
1496
|
+
}
|
|
687
1497
|
// Annotate the CommonJS export names for ESM import in node:
|
|
688
1498
|
0 && (module.exports = {
|
|
689
|
-
AppointmentClient,
|
|
690
1499
|
AssignmentMethod,
|
|
691
1500
|
AttendeeStatus,
|
|
692
1501
|
AvailabilityDetailModel,
|
|
693
1502
|
AvailabilityModel,
|
|
1503
|
+
CalendarDayModel,
|
|
694
1504
|
CalendarModel,
|
|
695
1505
|
CalendarParticipantModel,
|
|
1506
|
+
CompanyModel,
|
|
1507
|
+
ConfigModel,
|
|
696
1508
|
DayOfWeek,
|
|
697
1509
|
EventModel,
|
|
698
1510
|
OpeningHourModel,
|
|
1511
|
+
ParticipantInfoModel,
|
|
699
1512
|
ParticipantModel,
|
|
1513
|
+
PreferenceModel,
|
|
1514
|
+
PreferenceScope,
|
|
700
1515
|
RecurringFrequency,
|
|
701
1516
|
RootStore,
|
|
702
1517
|
SettingModel,
|
|
703
1518
|
TimeFrameModel,
|
|
704
1519
|
TimeSlotModel,
|
|
705
1520
|
Unit,
|
|
706
|
-
|
|
1521
|
+
configure,
|
|
1522
|
+
createRootStore,
|
|
1523
|
+
getConfig,
|
|
1524
|
+
getConfigStore,
|
|
1525
|
+
setBaseUrl
|
|
707
1526
|
});
|