admin.js
1 month ago
appointment.js
1 month ago
booking.js
1 day ago
customers.js
1 day ago
event.js
1 month ago
package.js
1 month ago
payment.js
1 month ago
socialAuthOptions.js
1 month ago
status.js
1 month ago
useReactiveCustomize.js
1 week ago
booking.js
86 lines
| 1 | function useParams(store, cabinetType) { |
| 2 | return { |
| 3 | source: 'cabinet-' + cabinetType.value, |
| 4 | timeZone: store.getters['cabinet/getTimeZone'], |
| 5 | } |
| 6 | } |
| 7 | |
| 8 | function getCabinetSource(userType) { |
| 9 | return userType === 'employee' || userType === 'provider' |
| 10 | ? 'cabinet-provider' |
| 11 | : 'cabinet-customer' |
| 12 | } |
| 13 | |
| 14 | function useCustomFieldsData(bookings, userType) { |
| 15 | let result = [] |
| 16 | |
| 17 | bookings.forEach((booking) => { |
| 18 | if (['approved', 'pending'].includes(booking.status) && booking.customFields) { |
| 19 | let customFields = JSON.parse(booking.customFields) |
| 20 | |
| 21 | Object.keys(customFields).forEach((customFieldId) => { |
| 22 | if (customFields[customFieldId]) { |
| 23 | let value = |
| 24 | customFields[customFieldId].type === 'file' |
| 25 | ? customFields[customFieldId]?.value |
| 26 | ? customFields[customFieldId].value |
| 27 | : '' |
| 28 | : customFields[customFieldId].value |
| 29 | |
| 30 | if (Array.isArray(value) ? value.length : value) { |
| 31 | result.push({ |
| 32 | label: customFields[customFieldId].label, |
| 33 | value: value, |
| 34 | type: customFields[customFieldId].type, |
| 35 | id: customFieldId, |
| 36 | entityId: booking.id, |
| 37 | customerId: booking.customer?.id, |
| 38 | source: getCabinetSource(userType), |
| 39 | }) |
| 40 | } |
| 41 | } |
| 42 | }) |
| 43 | } |
| 44 | }) |
| 45 | |
| 46 | if (userType === 'customer') { |
| 47 | return result |
| 48 | } |
| 49 | |
| 50 | // For employee view, keep unique custom fields with their values |
| 51 | const uniqueFields = new Map() |
| 52 | result |
| 53 | .filter((i) => i.value) |
| 54 | .forEach((item) => { |
| 55 | if (!uniqueFields.has(item.label)) { |
| 56 | uniqueFields.set(item.label, item) |
| 57 | } |
| 58 | }) |
| 59 | return Array.from(uniqueFields.values()) |
| 60 | } |
| 61 | |
| 62 | function useExtrasData(bookings, bookable) { |
| 63 | let result = {} |
| 64 | |
| 65 | bookings.forEach((booking) => { |
| 66 | if (['approved', 'pending'].includes(booking.status)) { |
| 67 | booking.extras.forEach((bookingExtra) => { |
| 68 | if (!(bookingExtra.extraId in result)) { |
| 69 | result[bookingExtra.extraId] = { |
| 70 | quantity: 0, |
| 71 | price: bookingExtra.price, |
| 72 | name: bookable.extras.find((i) => i.id === bookingExtra.extraId).name, |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | result[bookingExtra.extraId].quantity = |
| 77 | result[bookingExtra.extraId].quantity + bookingExtra.quantity |
| 78 | }) |
| 79 | } |
| 80 | }) |
| 81 | |
| 82 | return result |
| 83 | } |
| 84 | |
| 85 | export { useParams, useCustomFieldsData, useExtrasData } |
| 86 |