@stevenkellner/team-conduct-api 2.0.18 → 2.0.20

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.
Files changed (231) hide show
  1. package/lib/src/functions/fine/add.d.ts +3 -8
  2. package/lib/src/functions/fine/add.js +1 -2
  3. package/lib/src/functions/fine/delete.d.ts +1 -6
  4. package/lib/src/functions/fine/delete.js +2 -3
  5. package/lib/src/functions/fine/update.d.ts +2 -8
  6. package/lib/src/functions/fine/update.js +1 -3
  7. package/lib/src/functions/fineTemplate/add.d.ts +3 -3
  8. package/lib/src/functions/fineTemplate/update.d.ts +3 -3
  9. package/lib/src/functions/firebaseFunctionsContext.d.ts +34 -1
  10. package/lib/src/functions/firebaseFunctionsContext.js +33 -33
  11. package/lib/src/functions/index.d.ts +10 -8
  12. package/lib/src/functions/index.js +11 -8
  13. package/lib/src/functions/notification/markNotificationAsRead.d.ts +14 -0
  14. package/lib/src/functions/notification/{subscribe.js → markNotificationAsRead.js} +5 -7
  15. package/lib/src/functions/person/kickout.d.ts +6 -6
  16. package/lib/src/functions/person/kickout.js +4 -4
  17. package/lib/src/functions/person/roleEdit.d.ts +5 -5
  18. package/lib/src/functions/person/roleEdit.js +3 -3
  19. package/lib/src/functions/{paypalMe/edit.d.ts → team/delete.d.ts} +5 -7
  20. package/lib/src/functions/{paypalMe/edit.js → team/delete.js} +4 -5
  21. package/lib/src/functions/team/new.d.ts +18 -18
  22. package/lib/src/functions/team/new.js +8 -4
  23. package/lib/src/functions/team/update.d.ts +34 -0
  24. package/lib/src/functions/team/update.js +23 -0
  25. package/lib/src/functions/user/register.d.ts +4 -0
  26. package/lib/src/functions/user/register.js +3 -1
  27. package/lib/src/functions/user/update.d.ts +26 -0
  28. package/lib/src/functions/user/update.js +15 -0
  29. package/lib/src/index.d.ts +1 -1
  30. package/lib/src/index.js +1 -1
  31. package/lib/src/locales/de.d.ts +1 -1
  32. package/lib/src/locales/de.js +6 -2
  33. package/lib/src/locales/en.d.ts +6 -2
  34. package/lib/src/locales/en.js +6 -2
  35. package/lib/src/types/{MoneyAmount.d.ts → Money.d.ts} +23 -23
  36. package/lib/src/types/{MoneyAmount.js → Money.js} +25 -25
  37. package/lib/src/types/fine/Fine.d.ts +275 -0
  38. package/lib/src/types/fine/Fine.js +318 -0
  39. package/lib/src/types/fine/FineTemplate.d.ts +154 -0
  40. package/lib/src/types/fine/FineTemplate.js +170 -0
  41. package/lib/src/types/{PayedState.d.ts → fine/PayedState.d.ts} +1 -1
  42. package/lib/src/types/{PayedState.js → fine/PayedState.js} +1 -1
  43. package/lib/src/types/fine/index.d.ts +3 -0
  44. package/lib/src/{firebase → types/fine}/index.js +3 -6
  45. package/lib/src/types/index.d.ts +7 -18
  46. package/lib/src/types/index.js +7 -18
  47. package/lib/src/types/{Localization.d.ts → localization/Localization.d.ts} +15 -43
  48. package/lib/src/types/localization/Localization.js +54 -0
  49. package/lib/src/types/localization/PluralLocalization.d.ts +23 -0
  50. package/lib/src/types/localization/PluralLocalization.js +35 -0
  51. package/lib/src/types/{Pluralization.d.ts → localization/Pluralization.d.ts} +1 -0
  52. package/lib/src/types/{Pluralization.js → localization/Pluralization.js} +1 -0
  53. package/lib/src/types/localization/ValueLocalization.d.ts +22 -0
  54. package/lib/src/types/localization/ValueLocalization.js +41 -0
  55. package/lib/src/types/localization/index.d.ts +5 -0
  56. package/lib/src/types/localization/index.js +21 -0
  57. package/lib/src/types/notification/InAppNotification.d.ts +152 -0
  58. package/lib/src/types/notification/InAppNotification.js +136 -0
  59. package/lib/src/types/notification/index.d.ts +1 -0
  60. package/lib/src/types/notification/index.js +17 -0
  61. package/lib/src/types/{Person.d.ts → person/Person.d.ts} +3 -3
  62. package/lib/src/types/{Person.js → person/Person.js} +3 -3
  63. package/lib/src/types/{PersonProperties.d.ts → person/PersonProperties.d.ts} +8 -7
  64. package/lib/src/types/{PersonProperties.js → person/PersonProperties.js} +7 -6
  65. package/lib/src/types/{PersonSignInProperties.d.ts → person/PersonSignInProperties.d.ts} +9 -11
  66. package/lib/src/types/{PersonSignInProperties.js → person/PersonSignInProperties.js} +7 -10
  67. package/lib/src/types/person/index.d.ts +3 -0
  68. package/lib/src/types/person/index.js +19 -0
  69. package/lib/src/types/{Invitation.d.ts → team/Invitation.d.ts} +1 -1
  70. package/lib/src/types/{Invitation.js → team/Invitation.js} +1 -1
  71. package/lib/src/types/team/Team.d.ts +144 -0
  72. package/lib/src/types/team/Team.js +141 -0
  73. package/lib/src/types/team/TeamRole.d.ts +30 -0
  74. package/lib/src/types/{UserRole.js → team/TeamRole.js} +16 -15
  75. package/lib/src/types/team/index.d.ts +3 -0
  76. package/lib/src/types/team/index.js +19 -0
  77. package/lib/src/types/{NotificationProperties.d.ts → user/NotificationProperties.d.ts} +8 -3
  78. package/lib/src/types/{NotificationProperties.js → user/NotificationProperties.js} +4 -0
  79. package/lib/src/types/user/User.d.ts +328 -0
  80. package/lib/src/types/user/User.js +355 -0
  81. package/lib/src/types/user/index.d.ts +2 -0
  82. package/lib/src/types/user/index.js +18 -0
  83. package/lib/src/utils/StaticUnionTypeBuilder.d.ts +9 -0
  84. package/lib/src/utils/StaticUnionTypeBuilder.js +23 -0
  85. package/lib/src/utils/index.d.ts +1 -0
  86. package/lib/src/utils/index.js +17 -0
  87. package/lib/tsconfig.tsbuildinfo +1 -1
  88. package/package.json +4 -3
  89. package/src/functions/fine/add.ts +3 -5
  90. package/src/functions/fine/delete.ts +3 -5
  91. package/src/functions/fine/update.ts +2 -5
  92. package/src/functions/firebaseFunctionsContext.ts +40 -40
  93. package/src/functions/index.ts +11 -9
  94. package/src/functions/notification/markNotificationAsRead.ts +19 -0
  95. package/src/functions/person/add.ts +1 -1
  96. package/src/functions/person/kickout.ts +6 -6
  97. package/src/functions/person/roleEdit.ts +5 -5
  98. package/src/functions/{paypalMe/edit.ts → team/delete.ts} +5 -7
  99. package/src/functions/team/new.ts +19 -11
  100. package/src/functions/team/update.ts +40 -0
  101. package/src/functions/user/register.ts +7 -3
  102. package/src/functions/user/update.ts +29 -0
  103. package/src/index.ts +1 -1
  104. package/src/locales/de.ts +7 -3
  105. package/src/locales/en.ts +7 -3
  106. package/src/types/{MoneyAmount.ts → Money.ts} +29 -29
  107. package/src/types/fine/Fine.ts +399 -0
  108. package/src/types/fine/FineTemplate.ts +219 -0
  109. package/src/types/{PayedState.ts → fine/PayedState.ts} +2 -2
  110. package/src/types/fine/index.ts +3 -0
  111. package/src/types/index.ts +7 -18
  112. package/src/types/{Localization.ts → localization/Localization.ts} +7 -64
  113. package/src/types/localization/PluralLocalization.ts +32 -0
  114. package/src/types/{Pluralization.ts → localization/Pluralization.ts} +1 -0
  115. package/src/types/localization/ValueLocalization.ts +36 -0
  116. package/src/types/localization/index.ts +5 -0
  117. package/src/types/notification/InAppNotification.ts +184 -0
  118. package/src/types/notification/index.ts +1 -0
  119. package/src/types/{Person.ts → person/Person.ts} +3 -3
  120. package/src/types/{PersonProperties.ts → person/PersonProperties.ts} +8 -7
  121. package/src/types/{PersonSignInProperties.ts → person/PersonSignInProperties.ts} +13 -12
  122. package/src/types/person/index.ts +3 -0
  123. package/src/types/{Invitation.ts → team/Invitation.ts} +1 -1
  124. package/src/types/team/Team.ts +204 -0
  125. package/src/types/{UserRole.ts → team/TeamRole.ts} +19 -17
  126. package/src/types/team/index.ts +3 -0
  127. package/src/types/{NotificationProperties.ts → user/NotificationProperties.ts} +12 -3
  128. package/src/types/user/User.ts +451 -0
  129. package/src/types/user/index.ts +2 -0
  130. package/src/utils/StaticUnionTypeBuilder.ts +23 -0
  131. package/src/utils/index.ts +1 -0
  132. package/lib/src/firebase/FirebaseConfiguration.d.ts +0 -64
  133. package/lib/src/firebase/FirebaseConfiguration.js +0 -79
  134. package/lib/src/firebase/Firestore.d.ts +0 -201
  135. package/lib/src/firebase/Firestore.js +0 -244
  136. package/lib/src/firebase/FirestoreScheme.d.ts +0 -42
  137. package/lib/src/firebase/FirestoreScheme.js +0 -2
  138. package/lib/src/firebase/Messaging.d.ts +0 -90
  139. package/lib/src/firebase/Messaging.js +0 -2
  140. package/lib/src/firebase/checkAuthentication.d.ts +0 -38
  141. package/lib/src/firebase/checkAuthentication.js +0 -64
  142. package/lib/src/firebase/index.d.ts +0 -6
  143. package/lib/src/firebase/pushNotification.d.ts +0 -39
  144. package/lib/src/firebase/pushNotification.js +0 -88
  145. package/lib/src/functions/notification/subscribe.d.ts +0 -18
  146. package/lib/src/types/Configuration.d.ts +0 -46
  147. package/lib/src/types/Configuration.js +0 -51
  148. package/lib/src/types/Fine.d.ts +0 -71
  149. package/lib/src/types/Fine.js +0 -74
  150. package/lib/src/types/FineAmount.d.ts +0 -207
  151. package/lib/src/types/FineAmount.js +0 -238
  152. package/lib/src/types/FineTemplate.d.ts +0 -69
  153. package/lib/src/types/FineTemplate.js +0 -72
  154. package/lib/src/types/FineTemplateRepetition.d.ts +0 -87
  155. package/lib/src/types/FineTemplateRepetition.js +0 -103
  156. package/lib/src/types/Localization.js +0 -115
  157. package/lib/src/types/Team.d.ts +0 -62
  158. package/lib/src/types/Team.js +0 -64
  159. package/lib/src/types/User.d.ts +0 -221
  160. package/lib/src/types/User.js +0 -235
  161. package/lib/src/types/UserRole.d.ts +0 -29
  162. package/lib/test/firebase/FirebaseConfiguration.test.d.ts +0 -1
  163. package/lib/test/firebase/FirebaseConfiguration.test.js +0 -158
  164. package/lib/test/firebase/Firestore.test.d.ts +0 -1
  165. package/lib/test/firebase/Firestore.test.js +0 -46
  166. package/lib/test/firebase/checkAuthentication.test.d.ts +0 -1
  167. package/lib/test/firebase/checkAuthentication.test.js +0 -356
  168. package/lib/test/firebase/firebase-utils.d.ts +0 -32
  169. package/lib/test/firebase/firebase-utils.js +0 -134
  170. package/lib/test/firebase/pushNotification.test.d.ts +0 -1
  171. package/lib/test/firebase/pushNotification.test.js +0 -300
  172. package/lib/test/locales/localization.de.test.d.ts +0 -1
  173. package/lib/test/locales/localization.de.test.js +0 -144
  174. package/lib/test/locales/localization.en.test.d.ts +0 -1
  175. package/lib/test/locales/localization.en.test.js +0 -144
  176. package/lib/test/types/Configuration.test.d.ts +0 -1
  177. package/lib/test/types/Configuration.test.js +0 -84
  178. package/lib/test/types/Currency.test.d.ts +0 -1
  179. package/lib/test/types/Currency.test.js +0 -41
  180. package/lib/test/types/Fine.test.d.ts +0 -1
  181. package/lib/test/types/Fine.test.js +0 -265
  182. package/lib/test/types/FineAmount.test.d.ts +0 -1
  183. package/lib/test/types/FineAmount.test.js +0 -445
  184. package/lib/test/types/FineTemplate.test.d.ts +0 -1
  185. package/lib/test/types/FineTemplate.test.js +0 -271
  186. package/lib/test/types/FineTemplateRepetition.test.d.ts +0 -1
  187. package/lib/test/types/FineTemplateRepetition.test.js +0 -361
  188. package/lib/test/types/Invitation.test.d.ts +0 -1
  189. package/lib/test/types/Invitation.test.js +0 -269
  190. package/lib/test/types/Locale.test.d.ts +0 -1
  191. package/lib/test/types/Locale.test.js +0 -46
  192. package/lib/test/types/Localization.test.d.ts +0 -1
  193. package/lib/test/types/Localization.test.js +0 -241
  194. package/lib/test/types/MoneyAmount.test.d.ts +0 -1
  195. package/lib/test/types/MoneyAmount.test.js +0 -276
  196. package/lib/test/types/NotificationProperties.test.d.ts +0 -1
  197. package/lib/test/types/NotificationProperties.test.js +0 -258
  198. package/lib/test/types/PayedState.test.d.ts +0 -1
  199. package/lib/test/types/PayedState.test.js +0 -136
  200. package/lib/test/types/Person.test.d.ts +0 -1
  201. package/lib/test/types/Person.test.js +0 -266
  202. package/lib/test/types/PersonProperties.test.d.ts +0 -1
  203. package/lib/test/types/PersonProperties.test.js +0 -155
  204. package/lib/test/types/PersonSignInProperties.test.d.ts +0 -1
  205. package/lib/test/types/PersonSignInProperties.test.js +0 -208
  206. package/lib/test/types/Pluralization.test.d.ts +0 -1
  207. package/lib/test/types/Pluralization.test.js +0 -206
  208. package/lib/test/types/Team.test.d.ts +0 -1
  209. package/lib/test/types/Team.test.js +0 -145
  210. package/lib/test/types/User.test.d.ts +0 -1
  211. package/lib/test/types/User.test.js +0 -450
  212. package/lib/test/types/UserRole.test.d.ts +0 -1
  213. package/lib/test/types/UserRole.test.js +0 -140
  214. package/src/firebase/FirebaseConfiguration.ts +0 -99
  215. package/src/firebase/Firestore.ts +0 -258
  216. package/src/firebase/FirestoreScheme.ts +0 -41
  217. package/src/firebase/Messaging.ts +0 -93
  218. package/src/firebase/checkAuthentication.ts +0 -91
  219. package/src/firebase/index.ts +0 -7
  220. package/src/firebase/pushNotification.ts +0 -90
  221. package/src/functions/notification/subscribe.ts +0 -23
  222. package/src/types/Configuration.ts +0 -65
  223. package/src/types/Fine.ts +0 -100
  224. package/src/types/FineAmount.ts +0 -303
  225. package/src/types/FineTemplate.ts +0 -96
  226. package/src/types/FineTemplateRepetition.ts +0 -125
  227. package/src/types/Team.ts +0 -87
  228. package/src/types/User.ts +0 -302
  229. /package/lib/src/types/{Locale.d.ts → localization/Locale.d.ts} +0 -0
  230. /package/lib/src/types/{Locale.js → localization/Locale.js} +0 -0
  231. /package/src/types/{Locale.ts → localization/Locale.ts} +0 -0
@@ -1,23 +0,0 @@
1
- import { FirebaseFunction } from '@stevenkellner/firebase-function';
2
- import { NotificationProperties, Person, Team } from '../../types';
3
- import { ArrayTypeBuilder, Flattable, ObjectTypeBuilder, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
4
-
5
- export namespace NotificationSubscribeFunction {
6
-
7
- export type Parameters = {
8
- teamId: Team.Id,
9
- personId: Person.Id,
10
- subscriptions: NotificationProperties.Subscription[]
11
- };
12
- }
13
-
14
- export class NotificationSubscribeFunction implements FirebaseFunction<NotificationSubscribeFunction.Parameters, void> {
15
-
16
- public parametersBuilder = new ObjectTypeBuilder<Flattable.Flatten<NotificationSubscribeFunction.Parameters>, NotificationSubscribeFunction.Parameters>({
17
- teamId: Team.Id.builder,
18
- personId: Person.Id.builder,
19
- subscriptions: new ArrayTypeBuilder(new ValueTypeBuilder())
20
- });
21
-
22
- public returnTypeBuilder = new ValueTypeBuilder<void>();
23
- }
@@ -1,65 +0,0 @@
1
- import { Flattable, ITypeBuilder } from '@stevenkellner/typescript-common-functionality';
2
- import { Currency } from './Currency';
3
- import { Locale } from './Locale';
4
-
5
- /**
6
- * Represents the configuration settings that will be passed to the functions parameters.
7
- * Contains currency and locale preferences.
8
- */
9
- export class Configuration implements Flattable<Configuration.Flatten> {
10
-
11
- /**
12
- * Creates a new Configuration instance.
13
- * @param currency - The currency to use for monetary values (EUR, USD, ...)
14
- * @param locale - The locale for localization (language/region)
15
- */
16
- public constructor(
17
- public currency: Currency,
18
- public locale: Locale
19
- ) {}
20
-
21
- /**
22
- * Returns the flattened representation of the configuration.
23
- * @returns The flattened configuration object
24
- */
25
- public get flatten(): Configuration.Flatten {
26
- return {
27
- currency: this.currency,
28
- locale: this.locale
29
- };
30
- }
31
- }
32
-
33
- export namespace Configuration {
34
-
35
- /**
36
- * Flattened representation of Configuration for serialization.
37
- */
38
- export type Flatten = {
39
- currency: Currency,
40
- locale: Locale
41
- };
42
-
43
- /**
44
- * TypeBuilder for constructing Configuration instances from flattened data.
45
- */
46
- export class TypeBuilder implements ITypeBuilder<Flatten, Configuration> {
47
-
48
- /**
49
- * Builds a Configuration instance from flattened data.
50
- * @param flatten - The flattened configuration data
51
- * @returns A new Configuration instance
52
- */
53
- public build(flatten: Flatten): Configuration {
54
- return new Configuration(
55
- flatten.currency,
56
- flatten.locale
57
- );
58
- }
59
- }
60
-
61
- /**
62
- * Singleton builder instance for Configuration.
63
- */
64
- export const builder = new TypeBuilder();
65
- }
package/src/types/Fine.ts DELETED
@@ -1,100 +0,0 @@
1
- import { Flattable, Guid, ITypeBuilder, Tagged, UtcDate } from '@stevenkellner/typescript-common-functionality';
2
- import { FineAmount } from './FineAmount';
3
- import { PayedState } from './PayedState';
4
-
5
- /**
6
- * Represents a fine assigned to a person in a team.
7
- *
8
- * Contains information about the fine's payment status, date, reason, and monetary amount.
9
- */
10
- export class Fine implements Flattable<Fine.Flatten> {
11
-
12
- /**
13
- * Creates a new Fine instance.
14
- *
15
- * @param id - Unique identifier for the fine (GUID)
16
- * @param payedState - Payment status ('payed' or 'notPayed')
17
- * @param date - Date when the fine was issued
18
- * @param reason - Description or reason for the fine
19
- * @param amount - Monetary amount of the fine
20
- */
21
- public constructor(
22
- public id: Fine.Id,
23
- public payedState: PayedState,
24
- public date: UtcDate,
25
- public reason: string,
26
- public amount: FineAmount
27
- ) {}
28
-
29
- /**
30
- * Returns the flattened representation for serialization.
31
- */
32
- public get flatten(): Fine.Flatten {
33
- return {
34
- id: this.id.flatten,
35
- payedState: this.payedState,
36
- date: this.date.flatten,
37
- reason: this.reason,
38
- amount: this.amount.flatten
39
- };
40
- }
41
- }
42
-
43
- export namespace Fine {
44
-
45
- /**
46
- * Tagged GUID type for fine identifiers.
47
- */
48
- export type Id = Tagged<Guid, 'fine'>;
49
-
50
- export namespace Id {
51
-
52
- /**
53
- * Flattened representation of a fine ID (GUID string).
54
- */
55
- export type Flatten = string;
56
-
57
- /**
58
- * Type builder for Fine.Id serialization/deserialization.
59
- */
60
- export const builder = Tagged.builder('fine' as const, Guid.builder);
61
- }
62
-
63
- /**
64
- * Flattened representation of a Fine for serialization.
65
- */
66
- export type Flatten = {
67
- id: Id.Flatten,
68
- payedState: PayedState,
69
- date: UtcDate.Flatten,
70
- reason: string,
71
- amount: FineAmount.Flatten
72
- };
73
-
74
- /**
75
- * Type builder for Fine serialization/deserialization.
76
- */
77
- export class TypeBuilder implements ITypeBuilder<Flatten, Fine> {
78
-
79
- /**
80
- * Builds a Fine instance from flattened data.
81
- *
82
- * @param value - Flattened fine data
83
- * @returns Fine instance
84
- */
85
- public build(value: Flatten): Fine {
86
- return new Fine(
87
- Id.builder.build(value.id),
88
- value.payedState,
89
- UtcDate.builder.build(value.date),
90
- value.reason,
91
- FineAmount.builder.build(value.amount)
92
- );
93
- }
94
- }
95
-
96
- /**
97
- * Singleton instance of TypeBuilder for Fine.
98
- */
99
- export const builder = new TypeBuilder();
100
- }
@@ -1,303 +0,0 @@
1
- import { Flattable, ITypeBuilder } from '@stevenkellner/typescript-common-functionality';
2
- import { MoneyAmount } from './MoneyAmount';
3
- import { Configuration } from './Configuration';
4
- import { Localization } from './Localization';
5
- import { Locale } from './Locale';
6
-
7
- /**
8
- * Represents the amount of a fine, either as a monetary value or as items.
9
- *
10
- * Can be either FineAmount.Money (e.g., $10) or FineAmount.Item (e.g., 2 crates of beer).
11
- */
12
- export type FineAmount =
13
- | FineAmount.Money
14
- | FineAmount.Item;
15
-
16
- export namespace FineAmount {
17
-
18
- /**
19
- * Represents a fine amount as a monetary value.
20
- */
21
- export class Money implements Flattable<Money.Flatten> {
22
-
23
- /**
24
- * Creates a new Money fine amount.
25
- *
26
- * @param amount - The monetary amount
27
- */
28
- public constructor(
29
- public amount: MoneyAmount
30
- ) {}
31
-
32
- /**
33
- * Returns a formatted string representation of the amount.
34
- *
35
- * @param configuration - Configuration containing currency and locale
36
- * @returns Formatted currency string (e.g., "$10.50")
37
- */
38
- public formatted(configuration: Configuration): string {
39
- return this.amount.formatted(configuration.currency, configuration);
40
- }
41
-
42
- /**
43
- * Returns a new Money instance with the amount multiplied by a factor.
44
- *
45
- * @param factor - The multiplication factor
46
- * @returns New Money instance with multiplied amount
47
- */
48
- public multiplied(factor: number): Money {
49
- return new Money(this.amount.multiplied(factor));
50
- }
51
-
52
- /**
53
- * Returns the flattened representation for serialization.
54
- */
55
- public get flatten(): Money.Flatten {
56
- return {
57
- type: 'money',
58
- amount: this.amount.flatten
59
- };
60
- }
61
- }
62
-
63
- export namespace Money {
64
-
65
- /**
66
- * Flattened representation of Money for serialization.
67
- */
68
- export type Flatten = {
69
- type: 'money',
70
- amount: MoneyAmount.Flatten
71
- }
72
-
73
- /**
74
- * Type builder for Money serialization/deserialization.
75
- */
76
- export class TypeBuilder implements ITypeBuilder<Flatten, Money> {
77
-
78
- /**
79
- * Builds a Money instance from flattened data.
80
- *
81
- * @param value - Flattened money data
82
- * @returns Money instance
83
- */
84
- public build(value: Flatten): Money {
85
- return new Money(MoneyAmount.builder.build(value.amount));
86
- }
87
- }
88
-
89
- /**
90
- * Singleton instance of TypeBuilder for Money.
91
- */
92
- export const builder = new TypeBuilder();
93
- }
94
-
95
- /**
96
- * Represents a fine amount as a quantity of items.
97
- */
98
- export class Item implements Flattable<Item.Flatten> {
99
-
100
- /**
101
- * Creates a new Item fine amount.
102
- *
103
- * @param item - The item type (e.g., 'crateOfBeer')
104
- * @param count - The number of items
105
- */
106
- public constructor(
107
- public item: Item.Type,
108
- public count: number
109
- ) {}
110
-
111
- /**
112
- * Returns a formatted string representation including count.
113
- *
114
- * @param locale - The locale for formatting
115
- * @returns Formatted string (e.g., "2 crates of beer")
116
- */
117
- public formatted(locale: Locale): string;
118
- /**
119
- * Returns a formatted string representation including count.
120
- *
121
- * @param configuration - Configuration containing locale
122
- * @returns Formatted string (e.g., "2 crates of beer")
123
- */
124
- public formatted(configuration: Configuration): string;
125
- public formatted(configurationOrLocale: Configuration | Locale): string {
126
- const locale = configurationOrLocale instanceof Configuration ? configurationOrLocale.locale : configurationOrLocale;
127
- return Localization.shared(locale).fineAmount.item.type[this.item].withCount.value(this.count);
128
- }
129
-
130
- /**
131
- * Returns a formatted string representation without explicitly showing count.
132
- *
133
- * @param locale - The locale for formatting
134
- * @returns Formatted string without count display
135
- */
136
- public formattedWithoutCount(locale: Locale): string {
137
- return Localization.shared(locale).fineAmount.item.type[this.item].withoutCount.value(this.count);
138
- }
139
-
140
- /**
141
- * Returns a new Item instance with the count multiplied by a factor.
142
- *
143
- * @param factor - The multiplication factor
144
- * @returns New Item instance with multiplied count
145
- */
146
- public multiplied(factor: number): Item {
147
- return new Item(this.item, this.count * factor);
148
- }
149
-
150
- /**
151
- * Returns the flattened representation for serialization.
152
- */
153
- public get flatten(): Item.Flatten {
154
- return {
155
- type: 'item',
156
- item: this.item,
157
- count: this.count
158
- };
159
- }
160
- }
161
-
162
- export namespace Item {
163
-
164
- const itemTypes = ['crateOfBeer'] as const;
165
-
166
- /**
167
- * Item type: currently only 'crateOfBeer'.
168
- */
169
- export type Type = typeof itemTypes[number];
170
-
171
- export namespace Type {
172
-
173
- /**
174
- * Array containing all possible item types.
175
- */
176
- export const all: readonly Type[] = itemTypes;
177
-
178
- /**
179
- * Returns the localized name for an item type.
180
- *
181
- * @param type - The item type
182
- * @param locale - The locale to use for formatting
183
- * @returns Localized item name
184
- */
185
- export function formatted(type: Type, locale: Locale): string {
186
- return Localization.shared(locale).fineAmount.item.type[type].name.value();
187
- }
188
- }
189
-
190
- /**
191
- * Flattened representation of Item for serialization.
192
- */
193
- export type Flatten = {
194
- type: 'item',
195
- item: Item.Type,
196
- count: number
197
- }
198
-
199
- /**
200
- * Type builder for Item serialization/deserialization.
201
- */
202
- export class TypeBuilder implements ITypeBuilder<Flatten, Item> {
203
-
204
- /**
205
- * Builds an Item instance from flattened data.
206
- *
207
- * @param value - Flattened item data
208
- * @returns Item instance
209
- */
210
- public build(value: Flatten): Item {
211
- return new Item(value.item, value.count);
212
- }
213
- }
214
-
215
- /**
216
- * Singleton instance of TypeBuilder for Item.
217
- */
218
- export const builder = new TypeBuilder();
219
- }
220
-
221
- /**
222
- * Creates a Money fine amount.
223
- *
224
- * @param MoneyAmount - The monetary amount
225
- * @returns Money instance
226
- */
227
- export function money(MoneyAmount: MoneyAmount): Money {
228
- return new Money(MoneyAmount);
229
- }
230
-
231
- /**
232
- * Creates an Item fine amount.
233
- *
234
- * @param item - The item type
235
- * @param count - The number of items
236
- * @returns Item instance
237
- */
238
- export function item(item: Item.Type, count: number): Item {
239
- return new Item(item, count);
240
- }
241
-
242
- /**
243
- * Compares two fine amounts and returns their relative ordering.
244
- *
245
- * Money amounts are considered greater than Item amounts.
246
- * Within the same type, values are compared numerically.
247
- *
248
- * @param lhs - First fine amount to compare
249
- * @param rhs - Second fine amount to compare
250
- * @returns 'less' if lhs < rhs, 'equal' if lhs === rhs, 'greater' if lhs > rhs
251
- */
252
- export function compare(lhs: FineAmount, rhs: FineAmount): 'less' | 'equal' | 'greater' {
253
- if (lhs instanceof Money) {
254
- if (!(rhs instanceof Money))
255
- return 'greater';
256
- const lhsAmount = lhs.amount.completeValue;
257
- const rhsAmount = rhs.amount.completeValue;
258
- if (lhsAmount !== rhsAmount)
259
- return lhsAmount < rhsAmount ? 'less' : 'greater';
260
- }
261
- if (lhs instanceof Item) {
262
- if (!(rhs instanceof Item))
263
- return 'less';
264
- if (lhs.count === rhs.count)
265
- return 'equal';
266
- return lhs.count < rhs.count ? 'less' : 'greater';
267
- }
268
- return 'equal';
269
- }
270
-
271
- /**
272
- * Flattened representation of FineAmount (union of Money.Flatten and Item.Flatten).
273
- */
274
- export type Flatten = Money.Flatten | Item.Flatten;
275
-
276
- /**
277
- * Type builder for FineAmount serialization/deserialization.
278
- */
279
- export class TypeBuilder implements ITypeBuilder<Flatten, FineAmount> {
280
-
281
- /**
282
- * Builds a FineAmount instance from flattened data.
283
- *
284
- * Determines the type based on the 'type' discriminator field.
285
- *
286
- * @param value - Flattened fine amount data
287
- * @returns FineAmount instance (Money or Item)
288
- */
289
- public build(value: Flatten): FineAmount {
290
- switch (value.type) {
291
- case 'money':
292
- return Money.builder.build(value);
293
- case 'item':
294
- return Item.builder.build(value);
295
- }
296
- }
297
- }
298
-
299
- /**
300
- * Singleton instance of TypeBuilder for FineAmount.
301
- */
302
- export const builder = new TypeBuilder();
303
- }
@@ -1,96 +0,0 @@
1
- import { Flattable, Guid, ITypeBuilder, Tagged } from '@stevenkellner/typescript-common-functionality';
2
- import { FineAmount } from './FineAmount';
3
- import { FineTemplateRepetition } from './FineTemplateRepetition';
4
-
5
- /**
6
- * Represents a template for creating fines with predefined reason, amount, and optional repetition rules.
7
- *
8
- * Fine templates allow teams to quickly create recurring or standard fines without entering
9
- * the same information repeatedly.
10
- */
11
- export class FineTemplate implements Flattable<FineTemplate.Flatten> {
12
-
13
- /**
14
- * Creates a new FineTemplate instance.
15
- *
16
- * @param id - Unique identifier for the fine template (GUID)
17
- * @param reason - The reason or description for the fine
18
- * @param amount - The monetary or item-based amount of the fine
19
- * @param repetition - Optional repetition rules (null for non-recurring templates)
20
- */
21
- public constructor(
22
- public id: FineTemplate.Id,
23
- public reason: string,
24
- public amount: FineAmount,
25
- public repetition: FineTemplateRepetition | null
26
- ) {}
27
-
28
- /**
29
- * Returns the flattened representation for serialization.
30
- */
31
- public get flatten(): FineTemplate.Flatten {
32
- return {
33
- id: this.id.flatten,
34
- reason: this.reason,
35
- amount: this.amount.flatten,
36
- repetition: this.repetition === null ? null : this.repetition.flatten
37
- };
38
- }
39
- }
40
-
41
- export namespace FineTemplate {
42
-
43
- /**
44
- * Tagged GUID type for fine template identifiers.
45
- */
46
- export type Id = Tagged<Guid, 'fineTemplate'>;
47
-
48
- export namespace Id {
49
-
50
- /**
51
- * Flattened representation of a fine template ID (GUID string).
52
- */
53
- export type Flatten = string;
54
-
55
- /**
56
- * Type builder for FineTemplate.Id serialization/deserialization.
57
- */
58
- export const builder = Tagged.builder('fineTemplate' as const, Guid.builder);
59
- }
60
-
61
- /**
62
- * Flattened representation of a FineTemplate for serialization.
63
- */
64
- export type Flatten = {
65
- id: Id.Flatten,
66
- reason: string,
67
- amount: FineAmount.Flatten,
68
- repetition: FineTemplateRepetition.Flatten | null
69
- };
70
-
71
- /**
72
- * Type builder for FineTemplate serialization/deserialization.
73
- */
74
- export class TypeBuilder implements ITypeBuilder<Flatten, FineTemplate> {
75
-
76
- /**
77
- * Builds a FineTemplate instance from flattened data.
78
- *
79
- * @param value - Flattened fine template data
80
- * @returns FineTemplate instance
81
- */
82
- public build(value: Flatten): FineTemplate {
83
- return new FineTemplate(
84
- Id.builder.build(value.id),
85
- value.reason,
86
- FineAmount.builder.build(value.amount),
87
- value.repetition === null ? null : FineTemplateRepetition.builder.build(value.repetition)
88
- );
89
- }
90
- }
91
-
92
- /**
93
- * Singleton instance of TypeBuilder for FineTemplate.
94
- */
95
- export const builder = new TypeBuilder();
96
- }