diff --git a/src/components/CustomScheduleModal.vue b/src/components/CustomScheduleModal.vue index 021c7b42..b61f6676 100644 --- a/src/components/CustomScheduleModal.vue +++ b/src/components/CustomScheduleModal.vue @@ -161,33 +161,9 @@ export default defineComponent({ this.isDailyTimingsChecked = !this.isDailyTimingsChecked this.days = this.isDailyTimingsChecked ? ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'] : ['Daily'] }, - async saveCustomSchedule() { - if(this.facilityCalendar?.calendarId) { - try { - const resp = await FacilityService.removeFacilityCalendar({ - facilityId: this.facilityId, - calendarId: this.facilityCalendar.calendarId, - facilityCalendarTypeId: this.facilityCalendar.facilityCalendarTypeId, - fromDate: this.facilityCalendar.fromDate - }) - - if(!hasError(resp)) { - await this.addCustomSchedule() - } else { - throw resp.data; - } - } catch(err) { - logger.error(err) - } - } else { - await this.addCustomSchedule() - } - }, - async addCustomSchedule() { - let resp; - let calendarId; + async saveCustomSchedule() { let payload = {} as any - + if(this.days.length === 1) { const days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'] const dailyStartTime = DateTime.fromISO(this.selectedTimesForWeek['DailyStartTime'], {setZone: true}).toFormat('HH:mm:ss') @@ -214,6 +190,31 @@ export default defineComponent({ return; } + if(this.facilityCalendar?.calendarId) { + try { + const resp = await FacilityService.removeFacilityCalendar({ + facilityId: this.facilityId, + calendarId: this.facilityCalendar.calendarId, + facilityCalendarTypeId: this.facilityCalendar.facilityCalendarTypeId, + fromDate: this.facilityCalendar.fromDate + }) + + if(!hasError(resp)) { + await this.addCustomSchedule(payload) + } else { + throw resp.data; + } + } catch(err) { + logger.error(err) + } + } else { + await this.addCustomSchedule(payload) + } + }, + async addCustomSchedule(payload: any) { + let resp; + let calendarId; + try { resp = await FacilityService.createFacilityCalendar({ ...payload, description: this.selectedTimesForWeek.description}) if(!hasError(resp)) {