@bash-app/bash-common 30.3.0 → 30.5.0
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.
- package/package.json +1 -1
- package/prisma/schema.prisma +140 -87
- package/scripts/symlinks.sh +2 -0
- package/src/definitions.ts +37 -43
- package/src/extendedSchemas.ts +122 -104
- package/src/index.ts +4 -3
- package/src/utils/arrayUtils.ts +8 -0
- package/src/utils/luxonUtils.ts +78 -15
- package/src/utils/service/apiServiceBookingApiUtils.ts +222 -0
- package/src/utils/service/frontendServiceBookingUtils.ts +310 -0
- package/src/utils/service/serviceBookingStatusUtils.ts +96 -27
- package/src/utils/service/serviceBookingTypes.ts +56 -0
- package/src/utils/service/serviceDBUtils.ts +35 -35
- package/src/utils/service/serviceRateDBUtils.ts +179 -179
- package/src/utils/service/serviceRateTypes.ts +18 -0
- package/src/utils/service/serviceRateUtils.ts +38 -64
- package/src/utils/service/serviceUtils.ts +35 -3
- package/src/utils/stringUtils.ts +1 -1
- package/src/utils/service/serviceBookingApiUtils.ts +0 -259
- package/src/utils/service/serviceBookingUtils.ts +0 -391
|
@@ -5,54 +5,109 @@ export interface ValidationResult {
|
|
|
5
5
|
errorMessage?: string;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
export function serviceBookingIsRequest(booking: ServiceBookingExt): boolean {
|
|
9
|
+
return booking.bookingType === "Request";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function serviceBookingIsConfirmed(booking: ServiceBookingExt): boolean {
|
|
13
|
+
return booking.status === "Confirmed";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function serviceBookingIsPaid(booking: ServiceBookingExt): boolean {
|
|
17
|
+
return booking.checkout?.paidOn != null;
|
|
18
|
+
}
|
|
19
|
+
export function serviceBookingIsRefunded(booking: ServiceBookingExt): boolean {
|
|
20
|
+
return booking.checkout?.refundedOn != null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function serviceBookingAllowPromisePay(
|
|
24
|
+
booking: ServiceBookingExt
|
|
25
|
+
): boolean {
|
|
26
|
+
return booking.allowPromiseToPay === true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function serviceBookingIsCanceled(booking: ServiceBookingExt): boolean {
|
|
30
|
+
return booking.status === "Canceled";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function serviceBookingIsApproved(booking: ServiceBookingExt): boolean {
|
|
34
|
+
return booking.status === "Approved";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function serviceBookingIsDeclined(booking: ServiceBookingExt): boolean {
|
|
38
|
+
return booking.status === "Rejected";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function serviceBookingIsPending(booking: ServiceBookingExt): boolean {
|
|
42
|
+
return booking.status === "Pending";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function serviceBookingCanBePaid(
|
|
46
|
+
booking: ServiceBookingExt
|
|
47
|
+
): ValidationResult {
|
|
48
|
+
if (serviceBookingIsCanceled(booking)) {
|
|
49
|
+
return {
|
|
50
|
+
valid: false,
|
|
51
|
+
errorMessage: "You can not pay for a canceled booking.",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (serviceBookingIsPaid(booking)) {
|
|
55
|
+
return {
|
|
56
|
+
valid: false,
|
|
57
|
+
errorMessage:
|
|
58
|
+
"You cannot pay for a booking that has already been paid for.",
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (serviceBookingIsDeclined(booking)) {
|
|
62
|
+
return {
|
|
63
|
+
valid: false,
|
|
64
|
+
errorMessage: "You can not pay for a declined booking request.",
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (serviceBookingIsPending(booking) && serviceBookingIsRequest(booking)) {
|
|
13
68
|
return {
|
|
14
69
|
valid: false,
|
|
15
|
-
errorMessage: "
|
|
70
|
+
errorMessage: "You cannot pay for a pending booking request.",
|
|
16
71
|
};
|
|
17
72
|
}
|
|
73
|
+
return { valid: true };
|
|
18
74
|
}
|
|
19
75
|
|
|
20
|
-
export function
|
|
21
|
-
service: ServiceExt,
|
|
76
|
+
export function serviceBookingCanBeRefunded(
|
|
22
77
|
booking: ServiceBookingExt
|
|
23
78
|
): ValidationResult {
|
|
24
|
-
if (booking
|
|
79
|
+
if (serviceBookingIsCanceled(booking)) {
|
|
25
80
|
return {
|
|
26
81
|
valid: false,
|
|
27
|
-
errorMessage: "
|
|
82
|
+
errorMessage: "You cannot refund an already canceled booking.",
|
|
28
83
|
};
|
|
29
84
|
}
|
|
30
|
-
if (booking
|
|
85
|
+
if (serviceBookingIsRefunded(booking)) {
|
|
31
86
|
return {
|
|
32
87
|
valid: false,
|
|
33
|
-
errorMessage: "You cannot
|
|
88
|
+
errorMessage: "You cannot refund an already refunded booking.",
|
|
34
89
|
};
|
|
35
90
|
}
|
|
36
|
-
if (booking
|
|
91
|
+
if (!serviceBookingIsPaid(booking)) {
|
|
37
92
|
return {
|
|
38
93
|
valid: false,
|
|
39
|
-
errorMessage: "You
|
|
94
|
+
errorMessage: "You can not refund a booking that has not been paid for.",
|
|
40
95
|
};
|
|
41
96
|
}
|
|
97
|
+
|
|
42
98
|
return { valid: true };
|
|
43
99
|
}
|
|
44
100
|
|
|
45
101
|
export function serviceBookingCanHaveApprovalDecision(
|
|
46
|
-
service: ServiceExt,
|
|
47
102
|
booking: ServiceBookingExt
|
|
48
103
|
): ValidationResult {
|
|
49
|
-
if (booking
|
|
104
|
+
if (!serviceBookingIsRequest(booking)) {
|
|
50
105
|
return {
|
|
51
106
|
valid: false,
|
|
52
107
|
errorMessage: "Approval decisions can only be made on booking requests.",
|
|
53
108
|
};
|
|
54
109
|
}
|
|
55
|
-
if (booking
|
|
110
|
+
if (!serviceBookingIsPending(booking)) {
|
|
56
111
|
return {
|
|
57
112
|
valid: false,
|
|
58
113
|
errorMessage:
|
|
@@ -63,20 +118,19 @@ export function serviceBookingCanHaveApprovalDecision(
|
|
|
63
118
|
return { valid: true };
|
|
64
119
|
}
|
|
65
120
|
|
|
66
|
-
export function
|
|
67
|
-
service: ServiceExt,
|
|
121
|
+
export function serviceBookingHasApprovalDecision(
|
|
68
122
|
booking: ServiceBookingExt
|
|
69
123
|
): ValidationResult {
|
|
70
|
-
if (booking
|
|
124
|
+
if (!serviceBookingIsRequest(booking)) {
|
|
71
125
|
return {
|
|
72
126
|
valid: false,
|
|
73
127
|
errorMessage: "Only booking requests can have a decision.",
|
|
74
128
|
};
|
|
75
129
|
}
|
|
76
|
-
if (booking
|
|
130
|
+
if (serviceBookingIsPending(booking)) {
|
|
77
131
|
return {
|
|
78
132
|
valid: false,
|
|
79
|
-
errorMessage: "
|
|
133
|
+
errorMessage: "This request has not been approved yet.",
|
|
80
134
|
};
|
|
81
135
|
}
|
|
82
136
|
return { valid: true };
|
|
@@ -86,21 +140,36 @@ export function serviceBookingCanBeCanceled(
|
|
|
86
140
|
service: ServiceExt,
|
|
87
141
|
booking: ServiceBookingExt
|
|
88
142
|
): ValidationResult {
|
|
89
|
-
if (booking
|
|
143
|
+
if (serviceBookingIsCanceled(booking)) {
|
|
144
|
+
return {
|
|
145
|
+
valid: false,
|
|
146
|
+
errorMessage: "Canceled booking or booking requests may not be canceled.",
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
if (serviceBookingIsRefunded(booking)) {
|
|
150
|
+
return {
|
|
151
|
+
valid: false,
|
|
152
|
+
errorMessage: "You can not cancel an already refunded booking.",
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (serviceBookingIsDeclined(booking)) {
|
|
90
156
|
return {
|
|
91
157
|
valid: false,
|
|
92
|
-
errorMessage: "
|
|
158
|
+
errorMessage: "Declined booking requests may not be canceled.",
|
|
93
159
|
};
|
|
94
160
|
}
|
|
95
161
|
return { valid: true };
|
|
96
162
|
}
|
|
97
163
|
|
|
98
164
|
export function serviceBookingCanBeConfirmed(
|
|
99
|
-
service: ServiceExt,
|
|
100
165
|
booking: ServiceBookingExt
|
|
101
166
|
): ValidationResult {
|
|
102
|
-
if (booking
|
|
103
|
-
return {
|
|
167
|
+
if (serviceBookingIsCanceled(booking)) {
|
|
168
|
+
return {
|
|
169
|
+
valid: false,
|
|
170
|
+
errorMessage:
|
|
171
|
+
"Canceled bookings or booking requests can not be confirmed.",
|
|
172
|
+
};
|
|
104
173
|
}
|
|
105
174
|
return { valid: true };
|
|
106
175
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ServiceBookingAddOnExt,
|
|
3
|
+
ServiceBookingFeeExt,
|
|
4
|
+
ServiceBookingPriceBreakdownExt,
|
|
5
|
+
ServiceBookingDayExt,
|
|
6
|
+
ServiceDailyRatesExt,
|
|
7
|
+
ServiceSpecialRatesExt,
|
|
8
|
+
ServiceBookingExt,
|
|
9
|
+
} from "../../extendedSchemas";
|
|
10
|
+
import { LuxonDateRange } from "../luxonUtils";
|
|
11
|
+
|
|
12
|
+
export type ServiceBookingAddOnBase = Omit<
|
|
13
|
+
ServiceBookingAddOnExt,
|
|
14
|
+
"id" | "serviceBookingDayId" | "serviceBookingDay"
|
|
15
|
+
>;
|
|
16
|
+
export type ServiceBookingPackageBase = Omit<
|
|
17
|
+
ServiceBookingAddOnExt,
|
|
18
|
+
"id" | "serviceBookingDayId" | "serviceBookingDay"
|
|
19
|
+
>;
|
|
20
|
+
export type ServiceBookingFeeBase = Omit<
|
|
21
|
+
ServiceBookingFeeExt,
|
|
22
|
+
| "id"
|
|
23
|
+
| "serviceBookingDayId"
|
|
24
|
+
| "serviceBookingDay"
|
|
25
|
+
| "serviceBookingId"
|
|
26
|
+
| "serviceBooking"
|
|
27
|
+
>;
|
|
28
|
+
export type ServiceBookingPriceBreakdownBase = Omit<
|
|
29
|
+
ServiceBookingPriceBreakdownExt,
|
|
30
|
+
"id" | "serviceBookingDayId" | "serviceBookingDay"
|
|
31
|
+
>;
|
|
32
|
+
export type ServiceBookingDayBase = Omit<
|
|
33
|
+
ServiceBookingDayExt,
|
|
34
|
+
"id" | "serviceBookingRequestId" | "serviceBookingRequest"
|
|
35
|
+
>;
|
|
36
|
+
export type ServiceBookingBase = Pick<
|
|
37
|
+
ServiceBookingExt,
|
|
38
|
+
"bookedDays" | "timezone" | "additionalFees"
|
|
39
|
+
>;
|
|
40
|
+
|
|
41
|
+
export type ServiceBookingAddonBaseT = ServiceBookingAddOnBase; //T for Transformed/Processed aka used for logic
|
|
42
|
+
export type ServiceBookingPackageBaseT = ServiceBookingPackageBase;
|
|
43
|
+
export type ServiceBookingFeeBaseT = ServiceBookingFeeBase;
|
|
44
|
+
export type ServiceBookingPriceBreakdownBaseT = Omit<
|
|
45
|
+
ServiceBookingPriceBreakdownBase,
|
|
46
|
+
"startDate" | "endDate"
|
|
47
|
+
> & {
|
|
48
|
+
dateTimeRange: LuxonDateRange;
|
|
49
|
+
};
|
|
50
|
+
export type ServiceBookingDayBaseT = Omit<
|
|
51
|
+
ServiceBookingDayBase,
|
|
52
|
+
"startDate" | "endDate"
|
|
53
|
+
> & {
|
|
54
|
+
dateTimeRange: LuxonDateRange;
|
|
55
|
+
};
|
|
56
|
+
export type ServiceBookingBaseT = ServiceBookingBase;
|
|
@@ -1,50 +1,50 @@
|
|
|
1
1
|
import { ServiceRate } from "@prisma/client";
|
|
2
2
|
import { ServiceExt, ServiceSpecialRatesExt } from "../../extendedSchemas";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "./serviceRateDBUtils";
|
|
3
|
+
// import {
|
|
4
|
+
// specialRateConvertToDb,
|
|
5
|
+
// generalRatesConvertRatesToDB,
|
|
6
|
+
// specialRateConvertFromDb,
|
|
7
|
+
// generalRatesConvertRatesFromDB,
|
|
8
|
+
// } from "./serviceRateDBUtils";
|
|
9
9
|
|
|
10
10
|
export function serviceToDb(service: Partial<ServiceExt>): Partial<ServiceExt> {
|
|
11
11
|
if (service.serviceRatesAssociation) {
|
|
12
|
-
service.serviceRatesAssociation.serviceSpecialRates =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (service.serviceRatesAssociation.serviceGeneralRates) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
12
|
+
// service.serviceRatesAssociation.serviceSpecialRates =
|
|
13
|
+
// service.serviceRatesAssociation.serviceSpecialRates?.map(
|
|
14
|
+
// (
|
|
15
|
+
// serviceSpecialRate: Partial<ServiceSpecialRatesExt>
|
|
16
|
+
// ): ServiceSpecialRatesExt => {
|
|
17
|
+
// return specialRateConvertToDb(
|
|
18
|
+
// serviceSpecialRate
|
|
19
|
+
// ) as ServiceSpecialRatesExt;
|
|
20
|
+
// }
|
|
21
|
+
// );
|
|
22
|
+
// if (service.serviceRatesAssociation.serviceGeneralRates) {
|
|
23
|
+
// service.serviceRatesAssociation.serviceGeneralRates =
|
|
24
|
+
// generalRatesConvertRatesToDB(
|
|
25
|
+
// service.serviceRatesAssociation.serviceGeneralRates
|
|
26
|
+
// ) as ServiceRate;
|
|
27
|
+
// }
|
|
28
28
|
}
|
|
29
29
|
return service;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export function serviceFromDb(service: ServiceExt): ServiceExt {
|
|
33
33
|
if (service.serviceRatesAssociation) {
|
|
34
|
-
service.serviceRatesAssociation.serviceSpecialRates =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
// service.serviceRatesAssociation.serviceSpecialRates =
|
|
35
|
+
// service.serviceRatesAssociation.serviceSpecialRates?.map(
|
|
36
|
+
// (
|
|
37
|
+
// serviceSpecialRate: ServiceSpecialRatesExt
|
|
38
|
+
// ): ServiceSpecialRatesExt => {
|
|
39
|
+
// return specialRateConvertFromDb(serviceSpecialRate);
|
|
40
|
+
// }
|
|
41
|
+
// );
|
|
42
42
|
if (service.serviceRatesAssociation.serviceGeneralRates) {
|
|
43
|
-
console.log("updating general rates from db");
|
|
44
|
-
service.serviceRatesAssociation.serviceGeneralRates =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
// console.log("updating general rates from db");
|
|
44
|
+
// service.serviceRatesAssociation.serviceGeneralRates =
|
|
45
|
+
// generalRatesConvertRatesFromDB(
|
|
46
|
+
// service.serviceRatesAssociation.serviceGeneralRates
|
|
47
|
+
// );
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
return service;
|