meemup-library 1.6.6 → 1.6.7

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.
@@ -0,0 +1,42 @@
1
+ import EnumPointOfSaleOrderItemSharingType from "../enums/EnumPointOfSaleOrderItemSharingType";
2
+ import IPointOfSaleOrderItem from "../interfaces/pos/IPointOfSaleOrderItem";
3
+ import PointOfSaleOrderItemSeat from "../interfaces/pos/point-of-sale-order-item-seat";
4
+ import IOrderDetailProduct from "../interfaces/print/IOrderDetailProduct";
5
+ declare class TagToolController {
6
+ static SeatTagPreName: string;
7
+ static SharingTypeTagPreName: string;
8
+ static BundleGroupPreName: string;
9
+ static BundleIdPreName: string;
10
+ static BundleProductQuantityPreName: string;
11
+ static BundleFeeKey: string;
12
+ private static instance;
13
+ private constructor();
14
+ static getInstance(): TagToolController;
15
+ get BundleFeeKey(): string;
16
+ orderItemSeatsToTags(seats: PointOfSaleOrderItemSeat[]): string[];
17
+ tagsToOrderItemSeats(tags: string[] | null): PointOfSaleOrderItemSeat[];
18
+ sharingTypeToTag(value: EnumPointOfSaleOrderItemSharingType): string;
19
+ findTagSharingType(tags: string[] | undefined | null): string | undefined;
20
+ findTagBundleGroup(tags: string[] | undefined | null): string | undefined;
21
+ findTagBundleId(tags: string[] | undefined | null): string | undefined;
22
+ findTagBundleQuantity(tags: string[] | undefined | null): string | undefined;
23
+ bundleGroup(tag: string | undefined | null): string | undefined;
24
+ bundleId(tag: string | undefined | null): number | undefined;
25
+ bundleQuantity(tag: string | undefined | null): number | undefined;
26
+ createBundleGroupTag(group: string): string;
27
+ createBundleIdTag(bundleId: string | number): string;
28
+ createBundleRatioTag(ratio: string | number): string;
29
+ tagToSharingType(value: string | undefined): EnumPointOfSaleOrderItemSharingType;
30
+ seatToTag(seat: PointOfSaleOrderItemSeat): string;
31
+ seatToTagForDisplay(seat: PointOfSaleOrderItemSeat, shareType: EnumPointOfSaleOrderItemSharingType): string;
32
+ tagToSeat(tag: string): PointOfSaleOrderItemSeat;
33
+ allSeatInOrder(products: IPointOfSaleOrderItem[]): number[];
34
+ allSeatInOrderDetail(products: IOrderDetailProduct[]): number[];
35
+ allSeats(tags: string[] | undefined | null): string[];
36
+ seatNumber(tag: string, init?: number): number;
37
+ allTagsWithoutSeats(tags: string[] | null | undefined): string[];
38
+ allTagsWithoutSeatsAndSharingType(tags: string[] | null | undefined): string[];
39
+ allTagsWithoutBundles(tags: string[] | null | undefined): string[];
40
+ createSeatLabel(num: number): string;
41
+ }
42
+ export default TagToolController;
@@ -0,0 +1,173 @@
1
+ import EnumPointOfSaleOrderItemSharingType from "../enums/EnumPointOfSaleOrderItemSharingType";
2
+ class TagToolController {
3
+ constructor() {
4
+ }
5
+ static getInstance() {
6
+ if (!TagToolController.instance) {
7
+ TagToolController.instance = new TagToolController();
8
+ }
9
+ return TagToolController.instance;
10
+ }
11
+ get BundleFeeKey() {
12
+ return TagToolController.BundleFeeKey;
13
+ }
14
+ orderItemSeatsToTags(seats) {
15
+ try {
16
+ return (seats === null || seats === void 0 ? void 0 : seats.map(i => this.seatToTag(i))) || [];
17
+ }
18
+ catch (e) {
19
+ console.log("orderItemSeatsToTags : ", e);
20
+ return [];
21
+ }
22
+ }
23
+ tagsToOrderItemSeats(tags) {
24
+ try {
25
+ if (!tags)
26
+ return [];
27
+ const validTags = tags.filter(i => i.startsWith(TagToolController.SeatTagPreName));
28
+ return validTags.map(i => this.tagToSeat(i));
29
+ }
30
+ catch (e) {
31
+ console.log("tagsToOrderItemSeats : ", e);
32
+ return [];
33
+ }
34
+ }
35
+ sharingTypeToTag(value) {
36
+ return `${TagToolController.SharingTypeTagPreName}${value}`;
37
+ }
38
+ findTagSharingType(tags) {
39
+ return (tags || []).find(i => i.startsWith(TagToolController.SharingTypeTagPreName));
40
+ }
41
+ findTagBundleGroup(tags) {
42
+ return (tags || []).find(i => i.startsWith(TagToolController.BundleGroupPreName));
43
+ }
44
+ findTagBundleId(tags) {
45
+ return (tags || []).find(i => i.startsWith(TagToolController.BundleIdPreName));
46
+ }
47
+ findTagBundleQuantity(tags) {
48
+ return (tags || []).find(i => i.startsWith(TagToolController.BundleProductQuantityPreName));
49
+ }
50
+ bundleGroup(tag) {
51
+ if (!tag)
52
+ return undefined;
53
+ try {
54
+ return tag.split(TagToolController.BundleGroupPreName)[1];
55
+ }
56
+ catch (e) {
57
+ return undefined;
58
+ }
59
+ }
60
+ bundleId(tag) {
61
+ if (!tag)
62
+ return undefined;
63
+ try {
64
+ return +(tag.split(TagToolController.BundleIdPreName)[1]);
65
+ }
66
+ catch (e) {
67
+ return undefined;
68
+ }
69
+ }
70
+ bundleQuantity(tag) {
71
+ if (!tag)
72
+ return undefined;
73
+ try {
74
+ return +(tag.split(TagToolController.BundleProductQuantityPreName)[1]);
75
+ }
76
+ catch (e) {
77
+ return undefined;
78
+ }
79
+ }
80
+ createBundleGroupTag(group) {
81
+ return TagToolController.BundleGroupPreName + group;
82
+ }
83
+ createBundleIdTag(bundleId) {
84
+ return TagToolController.BundleIdPreName + bundleId;
85
+ }
86
+ createBundleRatioTag(ratio) {
87
+ return TagToolController.BundleProductQuantityPreName + ratio;
88
+ }
89
+ tagToSharingType(value) {
90
+ if (!value)
91
+ return EnumPointOfSaleOrderItemSharingType.None;
92
+ if (value.startsWith(TagToolController.SharingTypeTagPreName)) {
93
+ const [_preTagName, sharingTypeStr] = value.split(TagToolController.SharingTypeTagPreName);
94
+ if (!isNaN(+sharingTypeStr)) {
95
+ return +sharingTypeStr;
96
+ }
97
+ }
98
+ return EnumPointOfSaleOrderItemSharingType.None;
99
+ }
100
+ seatToTag(seat) {
101
+ return `${TagToolController.SeatTagPreName}${seat.seatId} - ${seat.ratio} - ${seat.isPaid ? "1" : "0"}`;
102
+ }
103
+ seatToTagForDisplay(seat, shareType) {
104
+ switch (shareType) {
105
+ case EnumPointOfSaleOrderItemSharingType.EqualSplit:
106
+ return `Seat #${seat.seatId} ${seat.isPaid ? "PAID" : ""}`.trim();
107
+ case EnumPointOfSaleOrderItemSharingType.Single:
108
+ return `Seat #${seat.seatId} ${seat.ratio}x ${seat.isPaid ? "PAID" : ""}`.trim();
109
+ case EnumPointOfSaleOrderItemSharingType.Shared:
110
+ return `Seat #${seat.seatId} ${seat.ratio}share ${seat.isPaid ? "PAID" : ""}`;
111
+ case EnumPointOfSaleOrderItemSharingType.None:
112
+ return "";
113
+ default:
114
+ return "Unknown share type";
115
+ }
116
+ }
117
+ tagToSeat(tag) {
118
+ const cleanTag = tag.replace(TagToolController.SeatTagPreName, "");
119
+ const [seatIdStr, ratioStr, isPaidStr, transactionIdStr] = cleanTag.split("-");
120
+ return {
121
+ seatId: Number(seatIdStr === null || seatIdStr === void 0 ? void 0 : seatIdStr.trim()), ratio: Number(ratioStr === null || ratioStr === void 0 ? void 0 : ratioStr.trim()), isPaid: isPaidStr === "1", transactionId: isNaN(+transactionIdStr) ? undefined : +transactionIdStr
122
+ };
123
+ }
124
+ allSeatInOrder(products) {
125
+ let list = [];
126
+ products.forEach(product => {
127
+ list.push(...product.seats.map(i => i.seatId));
128
+ });
129
+ return Array.from(new Set(list));
130
+ }
131
+ allSeatInOrderDetail(products) {
132
+ let list = [];
133
+ products.forEach(product => {
134
+ list.push(...this.tagsToOrderItemSeats(product.tags || []).map(i => i.seatId));
135
+ });
136
+ return Array.from(new Set(list));
137
+ }
138
+ allSeats(tags) {
139
+ if (!Array.isArray(tags))
140
+ return [];
141
+ return tags.filter(i => i.startsWith(TagToolController.SeatTagPreName));
142
+ }
143
+ seatNumber(tag, init = 1) {
144
+ try {
145
+ return +tag.split(TagToolController.SeatTagPreName)[1];
146
+ }
147
+ catch (e) {
148
+ console.log(e);
149
+ return init;
150
+ }
151
+ }
152
+ allTagsWithoutSeats(tags) {
153
+ if (!Array.isArray(tags))
154
+ return [];
155
+ return tags.filter(i => !i.startsWith(TagToolController.SeatTagPreName));
156
+ }
157
+ allTagsWithoutSeatsAndSharingType(tags) {
158
+ return this.allTagsWithoutSeats(tags).filter(i => !i.startsWith(TagToolController.SharingTypeTagPreName));
159
+ }
160
+ allTagsWithoutBundles(tags) {
161
+ return this.allTagsWithoutSeats(tags).filter(i => !i.startsWith(TagToolController.SharingTypeTagPreName));
162
+ }
163
+ createSeatLabel(num) {
164
+ return `${TagToolController.SeatTagPreName}${num}`;
165
+ }
166
+ }
167
+ TagToolController.SeatTagPreName = 'Seat #';
168
+ TagToolController.SharingTypeTagPreName = 'SharingType #';
169
+ TagToolController.BundleGroupPreName = 'BG #';
170
+ TagToolController.BundleIdPreName = 'BI #';
171
+ TagToolController.BundleProductQuantityPreName = 'BQ #';
172
+ TagToolController.BundleFeeKey = 'BundleProduct';
173
+ export default TagToolController;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meemup-library",
3
- "version": "1.6.6",
3
+ "version": "1.6.7",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,7 +11,7 @@
11
11
  "remove:one": "rimraf dist",
12
12
  "remove:two": "rimraf ./src/dist",
13
13
  "test": "echo \"Error: no test specified\" && exit 1",
14
- "commit": "git add . && git commit -m \"version.1.6.6\" && git push origin "
14
+ "commit": "git add . && git commit -m \"version.1.6.7\" && git push origin "
15
15
  },
16
16
  "files": [
17
17
  "/dist"