UNPKG

wix-twix

Version:

A simple library for managing server and web Wix clients built on top of Wix SDK.

153 lines (152 loc) 4.01 kB
import { locations as i } from "@wix/business-tools"; class l { constructor(e, t) { if (this.client = e, this.props = t, !t._id) throw new Error("Location id is required"); if (!t.revision) throw new Error("Location revision is required"); this.props = t; } get revision() { return this.props.revision; } get isArchived() { return this.props.archived; } get id() { return this.props._id; } get name() { return this.props.name; } get description() { return this.props.description; } get isDefault() { return this.props.default; } get status() { return this.props.status; } get fax() { return this.props.fax; } get timeZone() { return this.props.timeZone; } get email() { return this.props.email; } get phone() { return this.props.phone; } get address() { var n, a, u, c, h, d; const { number: e, name: t, apt: s } = ((n = this.props.address) == null ? void 0 : n.streetAddress) || {}, { latitude: r, longitude: o } = ((a = this.props.address) == null ? void 0 : a.location) || {}; return { street: [e, t].filter(Boolean).join(", "), street2: s || "", city: ((u = this.props.address) == null ? void 0 : u.city) || "", state: ((c = this.props.address) == null ? void 0 : c.subdivision) || "", country: ((h = this.props.address) == null ? void 0 : h.country) || "", postalCode: ((d = this.props.address) == null ? void 0 : d.postalCode) || "", coordinates: r && o ? [r, o] : void 0 }; } get hours() { var t; const e = (t = this.props.businessSchedule) == null ? void 0 : t.periods; return e ? e.map((s) => this.getHours({ closeDay: s.closeDay, closeTime: s.openTime, openTime: s.closeTime, openDay: s.openDay })) : []; } get specialHours() { var t; const e = (t = this.props.businessSchedule) == null ? void 0 : t.specialHourPeriod; return e ? e.map((s) => this.getSpecialHours({ startDate: s.startDate, endDate: s.endDate, isClosed: s.isClosed, comment: s.comment })) : []; } update({ name: e, description: t, email: s, phone: r, fax: o, timeZone: n }) { if (this.isArchived) throw new Error("Cannot update archived location"); return this.client.locations.updateLocation(this.id, { revision: this.revision, default: this.isDefault, name: e || this.name, timeZone: n || this.timeZone, address: this.props.address, // TODO: convert to wix format description: t, phone: r, email: s, fax: o }); } async setAsDefault() { this.isDefault || this.client.locations.setDefaultLocation(this.id); } async archive() { if (!this.isArchived) { if (this.isDefault) throw new Error("Cannot archive default location"); return this.client.locations.archiveLocation(this.id); } } getHours({ openDay: e, openTime: t, closeDay: s, closeTime: r }) { return { openDay: this.getDayOfWeek(e), openTime: t, closeDay: this.getDayOfWeek(s), closeTime: r }; } getSpecialHours({ startDate: e, endDate: t, isClosed: s, comment: r }) { return { startDate: this.getDayOfWeek(e), endDate: this.getDayOfWeek(t), isClosed: s, comment: r }; } getDayOfWeek(e) { switch (e) { case "MONDAY": return i.DayOfWeek.MONDAY; case "TUESDAY": return i.DayOfWeek.TUESDAY; case "WEDNESDAY": return i.DayOfWeek.WEDNESDAY; case "THURSDAY": return i.DayOfWeek.THURSDAY; case "FRIDAY": return i.DayOfWeek.FRIDAY; case "SATURDAY": return i.DayOfWeek.SATURDAY; case "SUNDAY": return i.DayOfWeek.SUNDAY; default: throw new Error(`Invalid day of week: ${e}`); } } } export { l as WixBusinessLocation }; //# sourceMappingURL=wixBusinessLocation.js.map