@ancon/wildcat-utils 1.18.2 → 1.18.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.
|
@@ -23,9 +23,11 @@ export declare type OpeningHoursTable = {
|
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
25
|
* Get an array of opening hours divided by order formats
|
|
26
|
-
* @param
|
|
26
|
+
* @param outlet Outlet from nearby endpoint
|
|
27
27
|
* @param nowISOString Optional ISO date string of current datetime
|
|
28
28
|
* @returns Opening hours table
|
|
29
29
|
*/
|
|
30
|
-
export default function getListOutletOpeningHoursTable(
|
|
30
|
+
export default function getListOutletOpeningHoursTable(outlet: {
|
|
31
|
+
serviceDateTimes: ServiceDateTime[];
|
|
32
|
+
}, nowISOString?: string): OpeningHoursTable[];
|
|
31
33
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const W=require("moment"),p=require("@ancon/wildcat-types"),s=require("../shared/enums.js"),F=require("../shared/isWithinFlag.js"),k=require("../shared/generateId.js"),
|
|
1
|
+
"use strict";const W=require("moment"),p=require("@ancon/wildcat-types"),s=require("../shared/enums.js"),F=require("../shared/isWithinFlag.js"),k=require("../shared/generateId.js"),l=[{id:p.OrderFormat.EatIn,name:"eatIn"},{id:p.OrderFormat.TakeAway,name:"takeaway"},{id:p.OrderFormat.TableOrder,name:"tableOrder"},{id:p.OrderFormat.Delivery,name:"delivery"}];function v(e){const r=W.utc(e).subtract(1,"day").startOf("day"),t=[];for(let i=0,o=r;i<7;i+=1)o=o.clone().add(1,"day").startOf("day"),t.push(o.clone());return t}function S(e){return[...e].sort((r,t)=>r.isoWeekday()-t.isoWeekday())}function g(e){return e.split(":").map(Number)}function T(e,r){const[t,i]=g(e.start),[o,a]=g(e.duration);if(e.type===s.IntervalType.Interval){const n=r.clone().add(t,"hour").add(i,"minute"),u=n.clone().add(o,"hour").add(a,"minute");return{id:e.id,start:n.toISOString(),end:u.toISOString()}}if(e.type===s.IntervalType.Exception){const n=W(e.fromDate),u=W(e.toDate);if(r.isBetween(n,u,void 0,"[]")){const O=r.clone().add(t,"hour").add(i,"minute"),y=O.clone().add(o,"hour").add(a,"minute");return{id:e.id,start:O.toISOString(),end:y.toISOString(),reason:e.reason}}return null}throw new Error("Invalid interval type")}function h(e,r,t){const i={[s.DayOfWeek.Monday]:1,[s.DayOfWeek.Tuesday]:2,[s.DayOfWeek.Wednesday]:3,[s.DayOfWeek.Thursday]:4,[s.DayOfWeek.Friday]:5,[s.DayOfWeek.Saturday]:6,[s.DayOfWeek.Sunday]:7};for(let o=0;o<r.length;o+=1){const a=r[o],n=a.isoWeekday(),u=e.dayOfWeek,y=(i[u]??null)===n||u===s.DayOfWeek.Everyday;if(t[n]||(t[n]={isoWeekday:n,key:"",open:[],adjusted:[],closed:[]}),y){const d=T(e,a);d&&(t[n].key+=d.id,e.type===s.IntervalType.Interval&&e.state===s.IntervalState.Open?t[n].open.push(d):e.type===s.IntervalType.Interval&&e.state===s.IntervalState.Closed?t[n].closed.push(d):e.type===s.IntervalType.Exception&&e.state===s.IntervalState.Open?t[n].adjusted.push(d):e.type===s.IntervalType.Exception&&e.state===s.IntervalState.Closed&&t[n].closed.push(d))}}}function D(e){switch(e.type){case s.IntervalType.Exception:return k("interval-exception");case s.IntervalType.Interval:return k("interval-normal");default:return k("interval-unknown")}}function M(e){const r=e.reduce((t,i)=>(l.forEach(o=>{F(o.id,i.orderFormats)&&(t[o.id]||(t[o.id]={orderFormat:o,intervals:[]}),t[o.id].intervals.push(...i.intervals.sort((a,n)=>a.dayOfWeek-n.dayOfWeek)))}),t),{});return Object.values(r)}function H(e){return e.reduce((r,t,i)=>{const o=r.findIndex(a=>a!==t&&!a.orderFormats.some(n=>t.orderFormats.some(u=>u.id===n.id))&&a.openingHours.every(n=>t.openingHours.some(u=>u.key===n.key))&&t.openingHours.every(n=>a.openingHours.some(u=>u.key===n.key)));if(o>=0){const a=r[o];return r.splice(o,1,{...a,orderFormats:[...t.orderFormats,...a.orderFormats]}),r.splice(i,1),r}return r},[...e])}function E(e){return e.map(r=>({...r,intervals:r.intervals.map(t=>({...t,id:D(t)}))}))}function w(e,r){const t=M(E(e.serviceDateTimes)),i=v(r),o=S(i),a=t.reduce((y,d)=>(y[d.orderFormat.id]||(y[d.orderFormat.id]={}),d.intervals.reduce((I,m)=>(h(m,o,I),I),y[d.orderFormat.id]),y),{}),n={[p.OrderFormat.EatIn]:l[0],[p.OrderFormat.TakeAway]:l[1],[p.OrderFormat.TableOrder]:l[2],[p.OrderFormat.Delivery]:l[3]},u=Object.entries(a).map(([y,d])=>({orderFormats:[n[Number(y)]],openingHours:Object.entries(d).map(([I,m])=>({isoWeekday:Number(I),key:m.key,open:m.open.sort((c,f)=>c.start.localeCompare(f.start)),adjusted:m.adjusted.sort((c,f)=>c.start.localeCompare(f.start)),closed:m.closed.sort((c,f)=>c.start.localeCompare(f.start))}))}));return H(u).sort((y,d)=>y.orderFormats[0].id-d.orderFormats[0].id)}module.exports=w;
|
|
@@ -15,13 +15,13 @@ function M(e) {
|
|
|
15
15
|
n = n.clone().add(1, "day").startOf("day"), t.push(n.clone());
|
|
16
16
|
return t;
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function v(e) {
|
|
19
19
|
return [...e].sort((r, t) => r.isoWeekday() - t.isoWeekday());
|
|
20
20
|
}
|
|
21
21
|
function S(e) {
|
|
22
22
|
return e.split(":").map(Number);
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function H(e, r) {
|
|
25
25
|
const [t, a] = S(e.start), [n, s] = S(
|
|
26
26
|
e.duration
|
|
27
27
|
);
|
|
@@ -67,12 +67,12 @@ function E(e, r, t) {
|
|
|
67
67
|
adjusted: [],
|
|
68
68
|
closed: []
|
|
69
69
|
}), u) {
|
|
70
|
-
const d =
|
|
70
|
+
const d = H(e, s);
|
|
71
71
|
d && (t[o].key += d.id, e.type === y.Interval && e.state === O.Open ? t[o].open.push(d) : e.type === y.Interval && e.state === O.Closed ? t[o].closed.push(d) : e.type === y.Exception && e.state === O.Open ? t[o].adjusted.push(d) : e.type === y.Exception && e.state === O.Closed && t[o].closed.push(d));
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
function
|
|
75
|
+
function T(e) {
|
|
76
76
|
switch (e.type) {
|
|
77
77
|
case y.Exception:
|
|
78
78
|
return W("interval-exception");
|
|
@@ -82,7 +82,7 @@ function x(e) {
|
|
|
82
82
|
return W("interval-unknown");
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
function
|
|
85
|
+
function x(e) {
|
|
86
86
|
const r = e.reduce(
|
|
87
87
|
(t, a) => (k.forEach((n) => {
|
|
88
88
|
h(n.id, a.orderFormats) && (t[n.id] || (t[n.id] = {
|
|
@@ -129,14 +129,14 @@ function w(e) {
|
|
|
129
129
|
...r,
|
|
130
130
|
intervals: r.intervals.map((t) => ({
|
|
131
131
|
...t,
|
|
132
|
-
id:
|
|
132
|
+
id: T(t)
|
|
133
133
|
}))
|
|
134
134
|
}));
|
|
135
135
|
}
|
|
136
136
|
function B(e, r) {
|
|
137
|
-
const t =
|
|
138
|
-
w(e)
|
|
139
|
-
), a = M(r), n =
|
|
137
|
+
const t = x(
|
|
138
|
+
w(e.serviceDateTimes)
|
|
139
|
+
), a = M(r), n = v(a), s = t.reduce(
|
|
140
140
|
(u, d) => (u[d.orderFormat.id] || (u[d.orderFormat.id] = {}), d.intervals.reduce((g, f) => (E(f, n, g), g), u[d.orderFormat.id]), u),
|
|
141
141
|
{}
|
|
142
142
|
), o = {
|