@open-tender/utils 0.4.10 → 0.4.11

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.
@@ -1,2 +1,4 @@
1
- import { Discounts, OrderType, ServiceType } from '@open-tender/types';
1
+ import { Discount, DiscountEnhanced, Discounts, OrderType, ServiceType } from '@open-tender/types';
2
2
  export declare const makeValidDeals: (deals: Discounts | null, orderType?: OrderType | null, serviceType?: ServiceType | null, revenueCenterId?: number | null) => Discounts;
3
+ export declare const makeLimitations: (item: Discount) => string;
4
+ export declare const makeDiscountEnhanced: (item: Discount) => DiscountEnhanced;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeValidDeals = void 0;
3
+ exports.makeDiscountEnhanced = exports.makeLimitations = exports.makeValidDeals = void 0;
4
4
  const datetimes_1 = require("./datetimes");
5
+ const helpers_1 = require("./helpers");
5
6
  const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) => {
6
7
  if (!deals || !deals.length)
7
8
  return [];
@@ -34,3 +35,72 @@ const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) => {
34
35
  return deals;
35
36
  };
36
37
  exports.makeValidDeals = makeValidDeals;
38
+ const makeDiscountServiceType = (serviceType) => {
39
+ switch (serviceType) {
40
+ case 'WALKIN':
41
+ return 'In-store only';
42
+ case 'PICKUP':
43
+ return 'Pickup only';
44
+ case 'DELIVERY':
45
+ return 'Delivery only';
46
+ default:
47
+ return null;
48
+ }
49
+ };
50
+ const makeDiscountOrderType = (orderType) => {
51
+ switch (orderType) {
52
+ case 'OLO':
53
+ return null;
54
+ case 'CATERING':
55
+ return 'Catering only';
56
+ case 'MERCH':
57
+ return 'Merch only';
58
+ default:
59
+ return null;
60
+ }
61
+ };
62
+ const makeChannelType = (channelType) => {
63
+ switch (channelType) {
64
+ case 'APP':
65
+ return 'App Only!';
66
+ case 'ONLINE':
67
+ return 'Online Only!';
68
+ case 'POS':
69
+ return 'At POS Only!';
70
+ case 'KIOSK':
71
+ return 'Kiosk Only!';
72
+ default:
73
+ return null;
74
+ }
75
+ };
76
+ const makeLimitations = (item) => {
77
+ const { channel_type, order_type, service_type } = item;
78
+ const serviceType = makeDiscountServiceType(service_type);
79
+ const orderType = makeDiscountOrderType(order_type);
80
+ const channelType = channel_type && makeChannelType(channel_type);
81
+ const comma = serviceType && orderType ? ', ' : null;
82
+ const dash = (serviceType || orderType) && channelType ? ' - ' : null;
83
+ if (serviceType || orderType || channelType) {
84
+ return `
85
+ ${serviceType}
86
+ ${comma}
87
+ ${orderType}
88
+ ${dash}
89
+ ${channelType}
90
+ `;
91
+ }
92
+ return 'Valid on all online & app orders';
93
+ };
94
+ exports.makeLimitations = makeLimitations;
95
+ const makeDiscountEnhanced = (item) => {
96
+ const today = (0, datetimes_1.makeLocalDateStr)(new Date(), 0, 'yyyy-MM-dd');
97
+ const imageMap = (0, helpers_1.makeImageMap)(item.images);
98
+ const imageUrl = imageMap.SMALL_IMAGE || imageMap.APP_IMAGE || imageMap.LARGE_IMAGE || null;
99
+ const todayOnly = item.end_date === today;
100
+ const expiration = item.end_date
101
+ ? (0, datetimes_1.formatDateStr)(item.end_date, 'MMM d')
102
+ : null;
103
+ const limitations = (0, exports.makeLimitations)(item);
104
+ return Object.assign(Object.assign({}, item), { imageUrl, expiration, todayOnly, limitations });
105
+ };
106
+ exports.makeDiscountEnhanced = makeDiscountEnhanced;
@@ -1,2 +1,4 @@
1
- import { Discounts, OrderType, ServiceType } from '@open-tender/types';
1
+ import { Discount, DiscountEnhanced, Discounts, OrderType, ServiceType } from '@open-tender/types';
2
2
  export declare const makeValidDeals: (deals: Discounts | null, orderType?: OrderType | null, serviceType?: ServiceType | null, revenueCenterId?: number | null) => Discounts;
3
+ export declare const makeLimitations: (item: Discount) => string;
4
+ export declare const makeDiscountEnhanced: (item: Discount) => DiscountEnhanced;
@@ -1,4 +1,5 @@
1
- import { getMinutesfromDate, time24ToMinutes } from './datetimes';
1
+ import { formatDateStr, getMinutesfromDate, makeLocalDateStr, time24ToMinutes } from './datetimes';
2
+ import { makeImageMap } from './helpers';
2
3
  export const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) => {
3
4
  if (!deals || !deals.length)
4
5
  return [];
@@ -30,3 +31,70 @@ export const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) =
30
31
  });
31
32
  return deals;
32
33
  };
34
+ const makeDiscountServiceType = (serviceType) => {
35
+ switch (serviceType) {
36
+ case 'WALKIN':
37
+ return 'In-store only';
38
+ case 'PICKUP':
39
+ return 'Pickup only';
40
+ case 'DELIVERY':
41
+ return 'Delivery only';
42
+ default:
43
+ return null;
44
+ }
45
+ };
46
+ const makeDiscountOrderType = (orderType) => {
47
+ switch (orderType) {
48
+ case 'OLO':
49
+ return null;
50
+ case 'CATERING':
51
+ return 'Catering only';
52
+ case 'MERCH':
53
+ return 'Merch only';
54
+ default:
55
+ return null;
56
+ }
57
+ };
58
+ const makeChannelType = (channelType) => {
59
+ switch (channelType) {
60
+ case 'APP':
61
+ return 'App Only!';
62
+ case 'ONLINE':
63
+ return 'Online Only!';
64
+ case 'POS':
65
+ return 'At POS Only!';
66
+ case 'KIOSK':
67
+ return 'Kiosk Only!';
68
+ default:
69
+ return null;
70
+ }
71
+ };
72
+ export const makeLimitations = (item) => {
73
+ const { channel_type, order_type, service_type } = item;
74
+ const serviceType = makeDiscountServiceType(service_type);
75
+ const orderType = makeDiscountOrderType(order_type);
76
+ const channelType = channel_type && makeChannelType(channel_type);
77
+ const comma = serviceType && orderType ? ', ' : null;
78
+ const dash = (serviceType || orderType) && channelType ? ' - ' : null;
79
+ if (serviceType || orderType || channelType) {
80
+ return `
81
+ ${serviceType}
82
+ ${comma}
83
+ ${orderType}
84
+ ${dash}
85
+ ${channelType}
86
+ `;
87
+ }
88
+ return 'Valid on all online & app orders';
89
+ };
90
+ export const makeDiscountEnhanced = (item) => {
91
+ const today = makeLocalDateStr(new Date(), 0, 'yyyy-MM-dd');
92
+ const imageMap = makeImageMap(item.images);
93
+ const imageUrl = imageMap.SMALL_IMAGE || imageMap.APP_IMAGE || imageMap.LARGE_IMAGE || null;
94
+ const todayOnly = item.end_date === today;
95
+ const expiration = item.end_date
96
+ ? formatDateStr(item.end_date, 'MMM d')
97
+ : null;
98
+ const limitations = makeLimitations(item);
99
+ return Object.assign(Object.assign({}, item), { imageUrl, expiration, todayOnly, limitations });
100
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.4.10",
3
+ "version": "0.4.11",
4
4
  "description": "A library of utils for use with Open Tender applications that utilize our cloud-based Order API.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -36,7 +36,7 @@
36
36
  "private": false,
37
37
  "devDependencies": {
38
38
  "@emotion/react": "^11.10.4",
39
- "@open-tender/types": "^0.4.31",
39
+ "@open-tender/types": "^0.4.34",
40
40
  "@reduxjs/toolkit": "^1.8.5",
41
41
  "@types/google.maps": "^3.53.5",
42
42
  "@types/jest": "^29.5.11",