@stevenkellner/team-conduct-api 2.0.18 → 2.0.19
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/lib/src/functions/fine/add.d.ts +3 -8
- package/lib/src/functions/fine/add.js +1 -2
- package/lib/src/functions/fine/delete.d.ts +1 -6
- package/lib/src/functions/fine/delete.js +2 -3
- package/lib/src/functions/fine/update.d.ts +2 -8
- package/lib/src/functions/fine/update.js +1 -3
- package/lib/src/functions/fineTemplate/add.d.ts +3 -3
- package/lib/src/functions/fineTemplate/update.d.ts +3 -3
- package/lib/src/functions/firebaseFunctionsContext.d.ts +34 -1
- package/lib/src/functions/firebaseFunctionsContext.js +33 -33
- package/lib/src/functions/index.d.ts +10 -8
- package/lib/src/functions/index.js +11 -8
- package/lib/src/functions/notification/markNotificationAsRead.d.ts +14 -0
- package/lib/src/functions/notification/{subscribe.js → markNotificationAsRead.js} +5 -7
- package/lib/src/functions/person/kickout.d.ts +6 -6
- package/lib/src/functions/person/kickout.js +4 -4
- package/lib/src/functions/person/roleEdit.d.ts +5 -5
- package/lib/src/functions/person/roleEdit.js +3 -3
- package/lib/src/functions/{paypalMe/edit.d.ts → team/delete.d.ts} +5 -7
- package/lib/src/functions/{paypalMe/edit.js → team/delete.js} +4 -5
- package/lib/src/functions/team/new.d.ts +18 -18
- package/lib/src/functions/team/new.js +8 -4
- package/lib/src/functions/team/update.d.ts +34 -0
- package/lib/src/functions/team/update.js +23 -0
- package/lib/src/functions/user/register.d.ts +4 -0
- package/lib/src/functions/user/register.js +3 -1
- package/lib/src/functions/user/update.d.ts +26 -0
- package/lib/src/functions/user/update.js +15 -0
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +1 -1
- package/lib/src/locales/de.d.ts +1 -1
- package/lib/src/locales/de.js +6 -2
- package/lib/src/locales/en.d.ts +6 -2
- package/lib/src/locales/en.js +6 -2
- package/lib/src/types/{MoneyAmount.d.ts → Money.d.ts} +23 -23
- package/lib/src/types/{MoneyAmount.js → Money.js} +25 -25
- package/lib/src/types/fine/Fine.d.ts +275 -0
- package/lib/src/types/fine/Fine.js +318 -0
- package/lib/src/types/fine/FineTemplate.d.ts +154 -0
- package/lib/src/types/fine/FineTemplate.js +170 -0
- package/lib/src/types/{PayedState.d.ts → fine/PayedState.d.ts} +1 -1
- package/lib/src/types/{PayedState.js → fine/PayedState.js} +1 -1
- package/lib/src/types/fine/index.d.ts +3 -0
- package/lib/src/{firebase → types/fine}/index.js +3 -6
- package/lib/src/types/index.d.ts +7 -18
- package/lib/src/types/index.js +7 -18
- package/lib/src/types/{Localization.d.ts → localization/Localization.d.ts} +15 -43
- package/lib/src/types/localization/Localization.js +54 -0
- package/lib/src/types/localization/PluralLocalization.d.ts +23 -0
- package/lib/src/types/localization/PluralLocalization.js +35 -0
- package/lib/src/types/{Pluralization.d.ts → localization/Pluralization.d.ts} +1 -0
- package/lib/src/types/{Pluralization.js → localization/Pluralization.js} +1 -0
- package/lib/src/types/localization/ValueLocalization.d.ts +22 -0
- package/lib/src/types/localization/ValueLocalization.js +41 -0
- package/lib/src/types/localization/index.d.ts +5 -0
- package/lib/src/types/localization/index.js +21 -0
- package/lib/src/types/notification/InAppNotification.d.ts +152 -0
- package/lib/src/types/notification/InAppNotification.js +136 -0
- package/lib/src/types/notification/index.d.ts +1 -0
- package/lib/src/types/notification/index.js +17 -0
- package/lib/src/types/{Person.d.ts → person/Person.d.ts} +3 -3
- package/lib/src/types/{Person.js → person/Person.js} +3 -3
- package/lib/src/types/{PersonProperties.d.ts → person/PersonProperties.d.ts} +8 -7
- package/lib/src/types/{PersonProperties.js → person/PersonProperties.js} +7 -6
- package/lib/src/types/{PersonSignInProperties.d.ts → person/PersonSignInProperties.d.ts} +9 -11
- package/lib/src/types/{PersonSignInProperties.js → person/PersonSignInProperties.js} +7 -10
- package/lib/src/types/person/index.d.ts +3 -0
- package/lib/src/types/person/index.js +19 -0
- package/lib/src/types/{Invitation.d.ts → team/Invitation.d.ts} +1 -1
- package/lib/src/types/{Invitation.js → team/Invitation.js} +1 -1
- package/lib/src/types/team/Team.d.ts +144 -0
- package/lib/src/types/team/Team.js +141 -0
- package/lib/src/types/team/TeamRole.d.ts +30 -0
- package/lib/src/types/{UserRole.js → team/TeamRole.js} +16 -15
- package/lib/src/types/team/index.d.ts +3 -0
- package/lib/src/types/team/index.js +19 -0
- package/lib/src/types/{NotificationProperties.d.ts → user/NotificationProperties.d.ts} +8 -3
- package/lib/src/types/{NotificationProperties.js → user/NotificationProperties.js} +4 -0
- package/lib/src/types/user/User.d.ts +328 -0
- package/lib/src/types/user/User.js +355 -0
- package/lib/src/types/user/index.d.ts +2 -0
- package/lib/src/types/user/index.js +18 -0
- package/lib/src/utils/StaticUnionTypeBuilder.d.ts +9 -0
- package/lib/src/utils/StaticUnionTypeBuilder.js +23 -0
- package/lib/src/utils/index.d.ts +1 -0
- package/lib/src/utils/index.js +17 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
- package/src/functions/fine/add.ts +3 -5
- package/src/functions/fine/delete.ts +3 -5
- package/src/functions/fine/update.ts +2 -5
- package/src/functions/firebaseFunctionsContext.ts +40 -40
- package/src/functions/index.ts +11 -9
- package/src/functions/notification/markNotificationAsRead.ts +19 -0
- package/src/functions/person/add.ts +1 -1
- package/src/functions/person/kickout.ts +6 -6
- package/src/functions/person/roleEdit.ts +5 -5
- package/src/functions/{paypalMe/edit.ts → team/delete.ts} +5 -7
- package/src/functions/team/new.ts +19 -11
- package/src/functions/team/update.ts +40 -0
- package/src/functions/user/register.ts +7 -3
- package/src/functions/user/update.ts +29 -0
- package/src/index.ts +1 -1
- package/src/locales/de.ts +7 -3
- package/src/locales/en.ts +7 -3
- package/src/types/{MoneyAmount.ts → Money.ts} +29 -29
- package/src/types/fine/Fine.ts +399 -0
- package/src/types/fine/FineTemplate.ts +219 -0
- package/src/types/{PayedState.ts → fine/PayedState.ts} +2 -2
- package/src/types/fine/index.ts +3 -0
- package/src/types/index.ts +7 -18
- package/src/types/{Localization.ts → localization/Localization.ts} +7 -64
- package/src/types/localization/PluralLocalization.ts +32 -0
- package/src/types/{Pluralization.ts → localization/Pluralization.ts} +1 -0
- package/src/types/localization/ValueLocalization.ts +36 -0
- package/src/types/localization/index.ts +5 -0
- package/src/types/notification/InAppNotification.ts +184 -0
- package/src/types/notification/index.ts +1 -0
- package/src/types/{Person.ts → person/Person.ts} +3 -3
- package/src/types/{PersonProperties.ts → person/PersonProperties.ts} +8 -7
- package/src/types/{PersonSignInProperties.ts → person/PersonSignInProperties.ts} +13 -12
- package/src/types/person/index.ts +3 -0
- package/src/types/{Invitation.ts → team/Invitation.ts} +1 -1
- package/src/types/team/Team.ts +204 -0
- package/src/types/{UserRole.ts → team/TeamRole.ts} +19 -17
- package/src/types/team/index.ts +3 -0
- package/src/types/{NotificationProperties.ts → user/NotificationProperties.ts} +12 -3
- package/src/types/user/User.ts +451 -0
- package/src/types/user/index.ts +2 -0
- package/src/utils/StaticUnionTypeBuilder.ts +23 -0
- package/src/utils/index.ts +1 -0
- package/lib/src/firebase/FirebaseConfiguration.d.ts +0 -64
- package/lib/src/firebase/FirebaseConfiguration.js +0 -79
- package/lib/src/firebase/Firestore.d.ts +0 -201
- package/lib/src/firebase/Firestore.js +0 -244
- package/lib/src/firebase/FirestoreScheme.d.ts +0 -42
- package/lib/src/firebase/FirestoreScheme.js +0 -2
- package/lib/src/firebase/Messaging.d.ts +0 -90
- package/lib/src/firebase/Messaging.js +0 -2
- package/lib/src/firebase/checkAuthentication.d.ts +0 -38
- package/lib/src/firebase/checkAuthentication.js +0 -64
- package/lib/src/firebase/index.d.ts +0 -6
- package/lib/src/firebase/pushNotification.d.ts +0 -39
- package/lib/src/firebase/pushNotification.js +0 -88
- package/lib/src/functions/notification/subscribe.d.ts +0 -18
- package/lib/src/types/Configuration.d.ts +0 -46
- package/lib/src/types/Configuration.js +0 -51
- package/lib/src/types/Fine.d.ts +0 -71
- package/lib/src/types/Fine.js +0 -74
- package/lib/src/types/FineAmount.d.ts +0 -207
- package/lib/src/types/FineAmount.js +0 -238
- package/lib/src/types/FineTemplate.d.ts +0 -69
- package/lib/src/types/FineTemplate.js +0 -72
- package/lib/src/types/FineTemplateRepetition.d.ts +0 -87
- package/lib/src/types/FineTemplateRepetition.js +0 -103
- package/lib/src/types/Localization.js +0 -115
- package/lib/src/types/Team.d.ts +0 -62
- package/lib/src/types/Team.js +0 -64
- package/lib/src/types/User.d.ts +0 -221
- package/lib/src/types/User.js +0 -235
- package/lib/src/types/UserRole.d.ts +0 -29
- package/lib/test/firebase/FirebaseConfiguration.test.d.ts +0 -1
- package/lib/test/firebase/FirebaseConfiguration.test.js +0 -158
- package/lib/test/firebase/Firestore.test.d.ts +0 -1
- package/lib/test/firebase/Firestore.test.js +0 -46
- package/lib/test/firebase/checkAuthentication.test.d.ts +0 -1
- package/lib/test/firebase/checkAuthentication.test.js +0 -356
- package/lib/test/firebase/firebase-utils.d.ts +0 -32
- package/lib/test/firebase/firebase-utils.js +0 -134
- package/lib/test/firebase/pushNotification.test.d.ts +0 -1
- package/lib/test/firebase/pushNotification.test.js +0 -300
- package/lib/test/locales/localization.de.test.d.ts +0 -1
- package/lib/test/locales/localization.de.test.js +0 -144
- package/lib/test/locales/localization.en.test.d.ts +0 -1
- package/lib/test/locales/localization.en.test.js +0 -144
- package/lib/test/types/Configuration.test.d.ts +0 -1
- package/lib/test/types/Configuration.test.js +0 -84
- package/lib/test/types/Currency.test.d.ts +0 -1
- package/lib/test/types/Currency.test.js +0 -41
- package/lib/test/types/Fine.test.d.ts +0 -1
- package/lib/test/types/Fine.test.js +0 -265
- package/lib/test/types/FineAmount.test.d.ts +0 -1
- package/lib/test/types/FineAmount.test.js +0 -445
- package/lib/test/types/FineTemplate.test.d.ts +0 -1
- package/lib/test/types/FineTemplate.test.js +0 -271
- package/lib/test/types/FineTemplateRepetition.test.d.ts +0 -1
- package/lib/test/types/FineTemplateRepetition.test.js +0 -361
- package/lib/test/types/Invitation.test.d.ts +0 -1
- package/lib/test/types/Invitation.test.js +0 -269
- package/lib/test/types/Locale.test.d.ts +0 -1
- package/lib/test/types/Locale.test.js +0 -46
- package/lib/test/types/Localization.test.d.ts +0 -1
- package/lib/test/types/Localization.test.js +0 -241
- package/lib/test/types/MoneyAmount.test.d.ts +0 -1
- package/lib/test/types/MoneyAmount.test.js +0 -276
- package/lib/test/types/NotificationProperties.test.d.ts +0 -1
- package/lib/test/types/NotificationProperties.test.js +0 -258
- package/lib/test/types/PayedState.test.d.ts +0 -1
- package/lib/test/types/PayedState.test.js +0 -136
- package/lib/test/types/Person.test.d.ts +0 -1
- package/lib/test/types/Person.test.js +0 -266
- package/lib/test/types/PersonProperties.test.d.ts +0 -1
- package/lib/test/types/PersonProperties.test.js +0 -155
- package/lib/test/types/PersonSignInProperties.test.d.ts +0 -1
- package/lib/test/types/PersonSignInProperties.test.js +0 -208
- package/lib/test/types/Pluralization.test.d.ts +0 -1
- package/lib/test/types/Pluralization.test.js +0 -206
- package/lib/test/types/Team.test.d.ts +0 -1
- package/lib/test/types/Team.test.js +0 -145
- package/lib/test/types/User.test.d.ts +0 -1
- package/lib/test/types/User.test.js +0 -450
- package/lib/test/types/UserRole.test.d.ts +0 -1
- package/lib/test/types/UserRole.test.js +0 -140
- package/src/firebase/FirebaseConfiguration.ts +0 -99
- package/src/firebase/Firestore.ts +0 -258
- package/src/firebase/FirestoreScheme.ts +0 -41
- package/src/firebase/Messaging.ts +0 -93
- package/src/firebase/checkAuthentication.ts +0 -91
- package/src/firebase/index.ts +0 -7
- package/src/firebase/pushNotification.ts +0 -90
- package/src/functions/notification/subscribe.ts +0 -23
- package/src/types/Configuration.ts +0 -65
- package/src/types/Fine.ts +0 -100
- package/src/types/FineAmount.ts +0 -303
- package/src/types/FineTemplate.ts +0 -96
- package/src/types/FineTemplateRepetition.ts +0 -125
- package/src/types/Team.ts +0 -87
- package/src/types/User.ts +0 -302
- /package/lib/src/types/{Locale.d.ts → localization/Locale.d.ts} +0 -0
- /package/lib/src/types/{Locale.js → localization/Locale.js} +0 -0
- /package/src/types/{Locale.ts → localization/Locale.ts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Flattable, ITypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
-
import { Configuration } from './Configuration';
|
|
3
2
|
import { Currency } from './Currency';
|
|
3
|
+
import { Locale } from './localization/Locale';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Represents a monetary amount with integer value and subunit components.
|
|
@@ -8,10 +8,10 @@ import { Currency } from './Currency';
|
|
|
8
8
|
* Stores money as two parts: main value (e.g., dollars) and subunit value (e.g., cents).
|
|
9
9
|
* This prevents floating-point precision issues in financial calculations.
|
|
10
10
|
*/
|
|
11
|
-
export class
|
|
11
|
+
export class Money implements Flattable<Money.Flatten> {
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Creates a new
|
|
14
|
+
* Creates a new Money instance.
|
|
15
15
|
*
|
|
16
16
|
* @param value - The main value (e.g., dollars, euros)
|
|
17
17
|
* @param subunitValue - The subunit value (e.g., cents), should be 0-99
|
|
@@ -22,38 +22,38 @@ export class MoneyAmount implements Flattable<MoneyAmount.Flatten> {
|
|
|
22
22
|
) {}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* Returns a
|
|
25
|
+
* Returns a Money instance representing zero.
|
|
26
26
|
*/
|
|
27
|
-
public static get zero():
|
|
28
|
-
return new
|
|
27
|
+
public static get zero(): Money {
|
|
28
|
+
return new Money(0, 0);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* Adds another
|
|
32
|
+
* Adds another Money instance to this one and returns the result.
|
|
33
33
|
*
|
|
34
34
|
* Properly handles subunit overflow (e.g., 50 cents + 60 cents = 1 dollar 10 cents).
|
|
35
35
|
*
|
|
36
|
-
* @param amount - The
|
|
37
|
-
* @returns A new
|
|
36
|
+
* @param amount - The Money instance to add
|
|
37
|
+
* @returns A new Money instance representing the sum
|
|
38
38
|
*/
|
|
39
|
-
public added(amount:
|
|
39
|
+
public added(amount: Money): Money {
|
|
40
40
|
const subunitValue = this.subunitValue + amount.subunitValue;
|
|
41
41
|
const value = this.value + amount.value + Math.floor(subunitValue / 100);
|
|
42
|
-
return new
|
|
42
|
+
return new Money(value, subunitValue % 100);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* Multiplies this
|
|
46
|
+
* Multiplies this Money instance by a factor and returns the result.
|
|
47
47
|
*
|
|
48
48
|
* Properly handles subunit calculations and overflow.
|
|
49
49
|
*
|
|
50
50
|
* @param factor - The multiplication factor
|
|
51
|
-
* @returns A new
|
|
51
|
+
* @returns A new Money instance representing the product
|
|
52
52
|
*/
|
|
53
|
-
public multiplied(factor: number):
|
|
53
|
+
public multiplied(factor: number): Money {
|
|
54
54
|
const subunitValue = this.subunitValue * factor;
|
|
55
55
|
const value = this.value * factor + Math.floor(subunitValue / 100);
|
|
56
|
-
return new
|
|
56
|
+
return new Money(value, subunitValue % 100);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/**
|
|
@@ -62,11 +62,11 @@ export class MoneyAmount implements Flattable<MoneyAmount.Flatten> {
|
|
|
62
62
|
* Uses Intl.NumberFormat for proper currency formatting based on locale.
|
|
63
63
|
*
|
|
64
64
|
* @param currency - The currency code (e.g., 'USD', 'EUR')
|
|
65
|
-
* @param
|
|
65
|
+
* @param locale - The locale information for formatting
|
|
66
66
|
* @returns Formatted currency string (e.g., "$12.50", "12,50 €")
|
|
67
67
|
*/
|
|
68
|
-
public formatted(currency: Currency,
|
|
69
|
-
const numberFormat = Intl.NumberFormat(
|
|
68
|
+
public formatted(currency: Currency, locale: Locale): string {
|
|
69
|
+
const numberFormat = Intl.NumberFormat(locale, {
|
|
70
70
|
style: 'currency',
|
|
71
71
|
currency: currency
|
|
72
72
|
});
|
|
@@ -85,38 +85,38 @@ export class MoneyAmount implements Flattable<MoneyAmount.Flatten> {
|
|
|
85
85
|
/**
|
|
86
86
|
* Returns the flattened representation as a decimal number.
|
|
87
87
|
*/
|
|
88
|
-
public get flatten():
|
|
88
|
+
public get flatten(): Money.Flatten {
|
|
89
89
|
return this.value + this.subunitValue / 100;
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
export namespace
|
|
93
|
+
export namespace Money {
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
|
-
* Flattened representation of
|
|
96
|
+
* Flattened representation of Money as a decimal number.
|
|
97
97
|
*/
|
|
98
98
|
export type Flatten = number;
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
|
-
* Type builder for
|
|
101
|
+
* Type builder for Money serialization/deserialization.
|
|
102
102
|
*/
|
|
103
|
-
export class TypeBuilder implements ITypeBuilder<Flatten,
|
|
103
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, Money> {
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
|
-
* Builds a
|
|
106
|
+
* Builds a Money instance from a flattened decimal value.
|
|
107
107
|
*
|
|
108
108
|
* Separates the decimal into integer and subunit parts.
|
|
109
109
|
*
|
|
110
110
|
* @param value - Decimal value (e.g., 12.50)
|
|
111
|
-
* @returns
|
|
111
|
+
* @returns Money instance
|
|
112
112
|
*/
|
|
113
|
-
public build(value: Flatten):
|
|
114
|
-
return new
|
|
113
|
+
public build(value: Flatten): Money {
|
|
114
|
+
return new Money(Math.floor(value), Math.round((value - Math.floor(value)) * 100));
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
|
-
* Singleton instance of TypeBuilder for
|
|
119
|
+
* Singleton instance of TypeBuilder for Money.
|
|
120
120
|
*/
|
|
121
|
-
export const builder = new
|
|
121
|
+
export const builder = new Money.TypeBuilder();
|
|
122
122
|
}
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import { Flattable, Guid, ITypeBuilder, Tagged, UtcDate, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
+
import { Money as MoneyValue } from '../Money';
|
|
3
|
+
import { Localization } from '../localization/Localization';
|
|
4
|
+
import { Locale } from '../localization/Locale';
|
|
5
|
+
import { Currency } from '../Currency';
|
|
6
|
+
import { PayedState } from './PayedState';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Represents a fine assigned to a person in a team.
|
|
10
|
+
*
|
|
11
|
+
* Contains information about the fine's payment status, date, reason, and monetary amount.
|
|
12
|
+
*/
|
|
13
|
+
export class Fine implements Flattable<Fine.Flatten> {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new Fine instance.
|
|
17
|
+
*
|
|
18
|
+
* @param id - Unique identifier for the fine (GUID)
|
|
19
|
+
* @param payedState - Payment status ('payed' or 'notPayed')
|
|
20
|
+
* @param date - Date when the fine was issued
|
|
21
|
+
* @param reason - Description or reason for the fine
|
|
22
|
+
* @param amount - Monetary amount of the fine
|
|
23
|
+
*/
|
|
24
|
+
public constructor(
|
|
25
|
+
public id: Fine.Id,
|
|
26
|
+
public payedState: PayedState,
|
|
27
|
+
public date: UtcDate,
|
|
28
|
+
public reason: string,
|
|
29
|
+
public amount: Fine.Amount
|
|
30
|
+
) {}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Returns the flattened representation for serialization.
|
|
34
|
+
*/
|
|
35
|
+
public get flatten(): Fine.Flatten {
|
|
36
|
+
return {
|
|
37
|
+
id: this.id.flatten,
|
|
38
|
+
payedState: this.payedState,
|
|
39
|
+
date: this.date.flatten,
|
|
40
|
+
reason: this.reason,
|
|
41
|
+
amount: this.amount.flatten
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export namespace Fine {
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Tagged GUID type for fine identifiers.
|
|
50
|
+
*/
|
|
51
|
+
export type Id = Tagged<Guid, 'fine'>;
|
|
52
|
+
|
|
53
|
+
export namespace Id {
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Flattened representation of a fine ID (GUID string).
|
|
57
|
+
*/
|
|
58
|
+
export type Flatten = string;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Type builder for Fine.Id serialization/deserialization.
|
|
62
|
+
*/
|
|
63
|
+
export const builder = Tagged.builder('fine' as const, Guid.builder);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Represents the amount of a fine.
|
|
68
|
+
*
|
|
69
|
+
* Can be either Fine.Amount.Money (e.g., $10) or Fine.Amount.Item (e.g., 2 crates of beer).
|
|
70
|
+
*/
|
|
71
|
+
export type Amount =
|
|
72
|
+
| Amount.Money
|
|
73
|
+
| Amount.Item;
|
|
74
|
+
|
|
75
|
+
export namespace Amount {
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Represents a fine amount as a monetary value.
|
|
79
|
+
*/
|
|
80
|
+
export class Money implements Flattable<Money.Flatten> {
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Creates a new monetary fine amount.
|
|
84
|
+
*
|
|
85
|
+
* @param amount - The monetary amount
|
|
86
|
+
*/
|
|
87
|
+
public constructor(
|
|
88
|
+
public amount: MoneyValue
|
|
89
|
+
) {}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Returns a formatted string representation of the amount.
|
|
93
|
+
*
|
|
94
|
+
* @param currency - The currency code
|
|
95
|
+
* @param locale - The locale for formatting
|
|
96
|
+
* @returns Formatted currency string (e.g., "$10.50")
|
|
97
|
+
*/
|
|
98
|
+
public formatted(currency: Currency, locale: Locale): string {
|
|
99
|
+
return this.amount.formatted(currency, locale);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Returns a new Money instance with the amount multiplied by a factor.
|
|
104
|
+
*
|
|
105
|
+
* @param factor - The multiplication factor
|
|
106
|
+
* @returns New Money instance with multiplied amount
|
|
107
|
+
*/
|
|
108
|
+
public multiplied(factor: number): Money {
|
|
109
|
+
return new Money(this.amount.multiplied(factor));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Returns the flattened representation for serialization.
|
|
114
|
+
*/
|
|
115
|
+
public get flatten(): Money.Flatten {
|
|
116
|
+
return {
|
|
117
|
+
type: 'money',
|
|
118
|
+
amount: this.amount.flatten
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export namespace Money {
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Flattened representation of Money for serialization.
|
|
127
|
+
*/
|
|
128
|
+
export type Flatten = {
|
|
129
|
+
type: 'money',
|
|
130
|
+
amount: MoneyValue.Flatten
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Type builder for Money serialization/deserialization.
|
|
135
|
+
*/
|
|
136
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, Money> {
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Builds a Money instance from flattened data.
|
|
140
|
+
*
|
|
141
|
+
* @param value - Flattened money data
|
|
142
|
+
* @returns Money instance
|
|
143
|
+
*/
|
|
144
|
+
public build(value: Flatten): Money {
|
|
145
|
+
return new Money(MoneyValue.builder.build(value.amount));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Singleton instance of TypeBuilder for Money.
|
|
151
|
+
*/
|
|
152
|
+
export const builder = new TypeBuilder();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Represents a fine amount as a quantity of items.
|
|
157
|
+
*/
|
|
158
|
+
export class Item implements Flattable<Item.Flatten> {
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Creates a new item fine amount.
|
|
162
|
+
*
|
|
163
|
+
* @param item - The item type (e.g., 'crateOfBeer')
|
|
164
|
+
* @param count - The number of items
|
|
165
|
+
*/
|
|
166
|
+
public constructor(
|
|
167
|
+
public item: Item.Type,
|
|
168
|
+
public count: number
|
|
169
|
+
) {}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Returns a formatted string representation including count.
|
|
173
|
+
*
|
|
174
|
+
* @param currency - The currency (unused for items, included for interface consistency)
|
|
175
|
+
* @param locale - The locale for formatting
|
|
176
|
+
* @returns Formatted string (e.g., "2 crates of beer")
|
|
177
|
+
*/
|
|
178
|
+
public formatted(currency: Currency, locale: Locale): string {
|
|
179
|
+
return Localization.shared(locale).fineAmount.item.type[this.item].withCount.value(this.count);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Returns a formatted string representation without explicitly showing count.
|
|
184
|
+
*
|
|
185
|
+
* @param locale - The locale for formatting
|
|
186
|
+
* @returns Formatted string without count display
|
|
187
|
+
*/
|
|
188
|
+
public formattedWithoutCount(locale: Locale): string {
|
|
189
|
+
return Localization.shared(locale).fineAmount.item.type[this.item].withoutCount.value(this.count);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Returns a new Item instance with the count multiplied by a factor.
|
|
194
|
+
*
|
|
195
|
+
* @param factor - The multiplication factor
|
|
196
|
+
* @returns New Item instance with multiplied count
|
|
197
|
+
*/
|
|
198
|
+
public multiplied(factor: number): Item {
|
|
199
|
+
return new Item(this.item, this.count * factor);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Returns the flattened representation for serialization.
|
|
204
|
+
*/
|
|
205
|
+
public get flatten(): Item.Flatten {
|
|
206
|
+
return {
|
|
207
|
+
type: 'item',
|
|
208
|
+
item: this.item,
|
|
209
|
+
count: this.count
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export namespace Item {
|
|
215
|
+
|
|
216
|
+
const itemTypes = ['crateOfBeer'] as const;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Item type: currently only 'crateOfBeer'.
|
|
220
|
+
*/
|
|
221
|
+
export type Type = typeof itemTypes[number];
|
|
222
|
+
|
|
223
|
+
export namespace Type {
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Array containing all possible item types.
|
|
227
|
+
*/
|
|
228
|
+
export const all: readonly Type[] = itemTypes;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Returns the localized name for an item type.
|
|
232
|
+
*
|
|
233
|
+
* @param type - The item type
|
|
234
|
+
* @param locale - The locale to use for formatting
|
|
235
|
+
* @returns Localized item name
|
|
236
|
+
*/
|
|
237
|
+
export function formatted(type: Type, locale: Locale): string {
|
|
238
|
+
return Localization.shared(locale).fineAmount.item.type[type].name.value();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Type builder for Item.Type serialization/deserialization.
|
|
243
|
+
*/
|
|
244
|
+
export const builder = new ValueTypeBuilder<Type>();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Flattened representation of Item for serialization.
|
|
249
|
+
*/
|
|
250
|
+
export type Flatten = {
|
|
251
|
+
type: 'item',
|
|
252
|
+
item: Item.Type,
|
|
253
|
+
count: number
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Type builder for Item serialization/deserialization.
|
|
258
|
+
*/
|
|
259
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, Item> {
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Builds an Item instance from flattened data.
|
|
263
|
+
*
|
|
264
|
+
* @param value - Flattened item data
|
|
265
|
+
* @returns Item instance
|
|
266
|
+
*/
|
|
267
|
+
public build(value: Flatten): Item {
|
|
268
|
+
return new Item(value.item, value.count);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Singleton instance of TypeBuilder for Item.
|
|
274
|
+
*/
|
|
275
|
+
export const builder = new TypeBuilder();
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Creates a monetary fine amount.
|
|
280
|
+
*
|
|
281
|
+
* @param amount - The monetary amount
|
|
282
|
+
* @returns Money instance
|
|
283
|
+
*/
|
|
284
|
+
export function money(amount: MoneyValue): Money {
|
|
285
|
+
return new Money(amount);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Creates an item fine amount.
|
|
290
|
+
*
|
|
291
|
+
* @param item - The item type
|
|
292
|
+
* @param count - The number of items
|
|
293
|
+
* @returns Item instance
|
|
294
|
+
*/
|
|
295
|
+
export function item(item: Item.Type, count: number): Item {
|
|
296
|
+
return new Item(item, count);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Compares two fine amounts and returns their relative ordering.
|
|
301
|
+
*
|
|
302
|
+
* Money amounts are considered greater than Item amounts.
|
|
303
|
+
* Within the same type, values are compared numerically.
|
|
304
|
+
*
|
|
305
|
+
* @param lhs - First fine amount to compare
|
|
306
|
+
* @param rhs - Second fine amount to compare
|
|
307
|
+
* @returns 'less' if lhs < rhs, 'equal' if lhs === rhs, 'greater' if lhs > rhs
|
|
308
|
+
*/
|
|
309
|
+
export function compare(lhs: Amount, rhs: Amount): 'less' | 'equal' | 'greater' {
|
|
310
|
+
if (lhs instanceof Money) {
|
|
311
|
+
if (!(rhs instanceof Money))
|
|
312
|
+
return 'greater';
|
|
313
|
+
const lhsAmount = lhs.amount.completeValue;
|
|
314
|
+
const rhsAmount = rhs.amount.completeValue;
|
|
315
|
+
if (lhsAmount !== rhsAmount)
|
|
316
|
+
return lhsAmount < rhsAmount ? 'less' : 'greater';
|
|
317
|
+
}
|
|
318
|
+
if (lhs instanceof Item) {
|
|
319
|
+
if (!(rhs instanceof Item))
|
|
320
|
+
return 'less';
|
|
321
|
+
if (lhs.count === rhs.count)
|
|
322
|
+
return 'equal';
|
|
323
|
+
return lhs.count < rhs.count ? 'less' : 'greater';
|
|
324
|
+
}
|
|
325
|
+
return 'equal';
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Flattened representation of Amount (union of Money.Flatten and Item.Flatten).
|
|
330
|
+
*/
|
|
331
|
+
export type Flatten = Money.Flatten | Item.Flatten;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Type builder for Amount serialization/deserialization.
|
|
335
|
+
*/
|
|
336
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, Amount> {
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Builds an Amount instance from flattened data.
|
|
340
|
+
*
|
|
341
|
+
* Determines the type based on the 'type' discriminator field.
|
|
342
|
+
*
|
|
343
|
+
* @param value - Flattened fine amount data
|
|
344
|
+
* @returns Amount instance (Money or Item)
|
|
345
|
+
*/
|
|
346
|
+
public build(value: Flatten): Amount {
|
|
347
|
+
switch (value.type) {
|
|
348
|
+
case 'money':
|
|
349
|
+
return Money.builder.build(value);
|
|
350
|
+
case 'item':
|
|
351
|
+
return Item.builder.build(value);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Singleton instance of TypeBuilder for Amount.
|
|
358
|
+
*/
|
|
359
|
+
export const builder = new TypeBuilder();
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Flattened representation of a Fine for serialization.
|
|
364
|
+
*/
|
|
365
|
+
export type Flatten = {
|
|
366
|
+
id: Id.Flatten,
|
|
367
|
+
payedState: PayedState,
|
|
368
|
+
date: UtcDate.Flatten,
|
|
369
|
+
reason: string,
|
|
370
|
+
amount: Amount.Flatten
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Type builder for Fine serialization/deserialization.
|
|
375
|
+
*/
|
|
376
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, Fine> {
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Builds a Fine instance from flattened data.
|
|
380
|
+
*
|
|
381
|
+
* @param value - Flattened fine data
|
|
382
|
+
* @returns Fine instance
|
|
383
|
+
*/
|
|
384
|
+
public build(value: Flatten): Fine {
|
|
385
|
+
return new Fine(
|
|
386
|
+
Id.builder.build(value.id),
|
|
387
|
+
value.payedState,
|
|
388
|
+
UtcDate.builder.build(value.date),
|
|
389
|
+
value.reason,
|
|
390
|
+
Amount.builder.build(value.amount)
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Singleton instance of TypeBuilder for Fine.
|
|
397
|
+
*/
|
|
398
|
+
export const builder = new TypeBuilder();
|
|
399
|
+
}
|