UNPKG

wix-twix

Version:

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

3 lines (2 loc) 3.08 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@wix/business-tools");class p{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:i,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:i&&o?[i,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:i,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,description:t,phone:i,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:i}){return{openDay:this.getDayOfWeek(e),openTime:t,closeDay:this.getDayOfWeek(s),closeTime:i}}getSpecialHours({startDate:e,endDate:t,isClosed:s,comment:i}){return{startDate:this.getDayOfWeek(e),endDate:this.getDayOfWeek(t),isClosed:s,comment:i}}getDayOfWeek(e){switch(e){case"MONDAY":return r.locations.DayOfWeek.MONDAY;case"TUESDAY":return r.locations.DayOfWeek.TUESDAY;case"WEDNESDAY":return r.locations.DayOfWeek.WEDNESDAY;case"THURSDAY":return r.locations.DayOfWeek.THURSDAY;case"FRIDAY":return r.locations.DayOfWeek.FRIDAY;case"SATURDAY":return r.locations.DayOfWeek.SATURDAY;case"SUNDAY":return r.locations.DayOfWeek.SUNDAY;default:throw new Error(`Invalid day of week: ${e}`)}}}exports.WixBusinessLocation=p; //# sourceMappingURL=wixBusinessLocation.js.map