@stevenkellner/team-conduct-api 1.0.5 → 1.0.6
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/index.ts +4 -0
- package/package.json +4 -2
- package/src/Firestore.ts +63 -0
- package/src/FirestoreScheme.ts +24 -0
- package/src/checkAuthentication.ts +36 -0
- package/src/firebase/FirebaseConfiguration.ts +39 -0
- package/src/firebase/Messaging.ts +29 -0
- package/src/firebase/index.ts +2 -0
- package/src/firebaseFunctionCreators.ts +56 -0
- package/src/functions/fine/add.ts +54 -0
- package/src/functions/fine/delete.ts +54 -0
- package/src/functions/fine/update.ts +55 -0
- package/src/functions/fineTemplate/add.ts +34 -0
- package/src/functions/fineTemplate/delete.ts +34 -0
- package/src/functions/fineTemplate/update.ts +34 -0
- package/src/functions/invitation/invite.ts +28 -0
- package/src/functions/invitation/register.ts +54 -0
- package/src/functions/invitation/withdraw.ts +24 -0
- package/src/functions/notification/register.ts +39 -0
- package/src/functions/notification/subscribe.ts +38 -0
- package/src/functions/paypalMe/edit.ts +36 -0
- package/src/functions/person/add.ts +36 -0
- package/src/functions/person/delete.ts +37 -0
- package/src/functions/person/update.ts +37 -0
- package/src/functions/team/new.ts +54 -0
- package/src/functions/user/login.ts +25 -0
- package/src/functions/user/roleEdit.ts +44 -0
- package/src/locales/de.json +30 -0
- package/src/locales/en.json +30 -0
- package/src/pushNotification.ts +37 -0
- package/src/types/Configuration.ts +54 -0
- package/src/types/Fine.ts +59 -0
- package/src/types/FineAmount.ts +123 -0
- package/src/types/FineTemplate.ts +55 -0
- package/src/types/FineTemplateRepetition.ts +54 -0
- package/src/types/Invitation.ts +56 -0
- package/src/types/MoneyAmount.ts +41 -0
- package/src/types/NotificationProperties.ts +67 -0
- package/src/types/PayedState.ts +12 -0
- package/src/types/Person.ts +56 -0
- package/src/types/PersonPrivateProperties.ts +37 -0
- package/src/types/PersonSignInProperties.ts +42 -0
- package/src/types/Team.ts +49 -0
- package/src/types/User.ts +76 -0
- package/src/types/UserRole.ts +19 -0
- package/src/types/index.ts +15 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Flattable, ITypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
+
import { MoneyAmount } from './MoneyAmount';
|
|
3
|
+
import * as i18n from 'i18n';
|
|
4
|
+
import { Configuration } from './Configuration';
|
|
5
|
+
|
|
6
|
+
export type FineAmount =
|
|
7
|
+
| FineAmount.Money
|
|
8
|
+
| FineAmount.Item;
|
|
9
|
+
|
|
10
|
+
export namespace FineAmount {
|
|
11
|
+
|
|
12
|
+
export class Money implements Flattable<Money.Flatten> {
|
|
13
|
+
|
|
14
|
+
public constructor(
|
|
15
|
+
public amount: MoneyAmount
|
|
16
|
+
) {}
|
|
17
|
+
|
|
18
|
+
public formatted(configuration: Configuration): string {
|
|
19
|
+
return this.amount.formatted(configuration.currency);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public get flatten(): Money.Flatten {
|
|
23
|
+
return {
|
|
24
|
+
type: 'money',
|
|
25
|
+
amount: this.amount.flatten
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export namespace Money {
|
|
31
|
+
|
|
32
|
+
export type Flatten = {
|
|
33
|
+
type: 'money',
|
|
34
|
+
amount: MoneyAmount.Flatten
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, Money> {
|
|
38
|
+
|
|
39
|
+
public build(value: Flatten): Money {
|
|
40
|
+
return new Money(MoneyAmount.builder.build(value.amount));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const builder = new TypeBuilder();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class Item implements Flattable<Item.Flatten> {
|
|
48
|
+
|
|
49
|
+
public constructor(
|
|
50
|
+
public item: Item.Type,
|
|
51
|
+
public count: number
|
|
52
|
+
) {}
|
|
53
|
+
|
|
54
|
+
public formatted(configuration: Configuration): string {
|
|
55
|
+
const numberFormat = Intl.NumberFormat(configuration.locale, {
|
|
56
|
+
minimumFractionDigits: 0,
|
|
57
|
+
maximumFractionDigits: 0
|
|
58
|
+
});
|
|
59
|
+
if (this.count === 1)
|
|
60
|
+
return i18n.__(`FineAmount.Item.Type.${this.item}.singular`, numberFormat.format(this.count));
|
|
61
|
+
return i18n.__(`FineAmount.Item.Type.${this.item}.plural`, numberFormat.format(this.count));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public get flatten(): Item.Flatten {
|
|
65
|
+
return {
|
|
66
|
+
type: 'item',
|
|
67
|
+
item: this.item,
|
|
68
|
+
count: this.count
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export namespace Item {
|
|
74
|
+
|
|
75
|
+
export type Type =
|
|
76
|
+
| 'crateOfBeer';
|
|
77
|
+
|
|
78
|
+
export namespace Type {
|
|
79
|
+
|
|
80
|
+
export const all: Type[] = ['crateOfBeer'];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type Flatten = {
|
|
84
|
+
type: 'item',
|
|
85
|
+
item: Item.Type,
|
|
86
|
+
count: number
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, Item> {
|
|
90
|
+
|
|
91
|
+
public build(value: Flatten): Item {
|
|
92
|
+
return new Item(value.item, value.count);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export const builder = new TypeBuilder();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
export function money(MoneyAmount: MoneyAmount): Money {
|
|
101
|
+
return new Money(MoneyAmount);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function item(item: Item.Type, count: number): Item {
|
|
105
|
+
return new Item(item, count);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export type Flatten = Money.Flatten | Item.Flatten;
|
|
109
|
+
|
|
110
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, FineAmount> {
|
|
111
|
+
|
|
112
|
+
public build(value: Flatten): FineAmount {
|
|
113
|
+
switch (value.type) {
|
|
114
|
+
case 'money':
|
|
115
|
+
return Money.builder.build(value);
|
|
116
|
+
case 'item':
|
|
117
|
+
return Item.builder.build(value);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export const builder = new TypeBuilder();
|
|
123
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Flattable, Guid, ITypeBuilder, Tagged } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
+
import { FineAmount } from './FineAmount';
|
|
3
|
+
import { FineTemplateRepetition } from './FineTemplateRepetition';
|
|
4
|
+
|
|
5
|
+
export class FineTemplate implements Flattable<FineTemplate.Flatten> {
|
|
6
|
+
|
|
7
|
+
public constructor(
|
|
8
|
+
public id: FineTemplate.Id,
|
|
9
|
+
public reason: string,
|
|
10
|
+
public amount: FineAmount,
|
|
11
|
+
public repetition: FineTemplateRepetition | null
|
|
12
|
+
) {}
|
|
13
|
+
|
|
14
|
+
public get flatten(): FineTemplate.Flatten {
|
|
15
|
+
return {
|
|
16
|
+
id: this.id.flatten,
|
|
17
|
+
reason: this.reason,
|
|
18
|
+
amount: this.amount.flatten,
|
|
19
|
+
repetition: this.repetition === null ? null : this.repetition.flatten
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export namespace FineTemplate {
|
|
25
|
+
|
|
26
|
+
export type Id = Tagged<Guid, 'fineTemplate'>;
|
|
27
|
+
|
|
28
|
+
export namespace Id {
|
|
29
|
+
|
|
30
|
+
export type Flatten = string;
|
|
31
|
+
|
|
32
|
+
export const builder = Tagged.builder('fineTemplate' as const, Guid.builder);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type Flatten = {
|
|
36
|
+
id: Id.Flatten,
|
|
37
|
+
reason: string,
|
|
38
|
+
amount: FineAmount.Flatten,
|
|
39
|
+
repetition: FineTemplateRepetition.Flatten | null
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, FineTemplate> {
|
|
43
|
+
|
|
44
|
+
public build(value: Flatten): FineTemplate {
|
|
45
|
+
return new FineTemplate(
|
|
46
|
+
Id.builder.build(value.id),
|
|
47
|
+
value.reason,
|
|
48
|
+
FineAmount.builder.build(value.amount),
|
|
49
|
+
value.repetition === null ? null : FineTemplateRepetition.builder.build(value.repetition)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const builder = new TypeBuilder();
|
|
55
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Flattable, ITypeBuilder, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
+
|
|
3
|
+
export class FineTemplateRepetition implements Flattable<FineTemplateRepetition.Flatten> {
|
|
4
|
+
|
|
5
|
+
public constructor(
|
|
6
|
+
public item: FineTemplateRepetition.Item,
|
|
7
|
+
public maxCount: number | null
|
|
8
|
+
) {}
|
|
9
|
+
|
|
10
|
+
public get flatten(): FineTemplateRepetition.Flatten {
|
|
11
|
+
return {
|
|
12
|
+
item: this.item,
|
|
13
|
+
maxCount: this.maxCount
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export namespace FineTemplateRepetition {
|
|
19
|
+
|
|
20
|
+
export type Item =
|
|
21
|
+
| 'minute'
|
|
22
|
+
| 'day'
|
|
23
|
+
| 'item'
|
|
24
|
+
| 'count';
|
|
25
|
+
|
|
26
|
+
export namespace Item {
|
|
27
|
+
|
|
28
|
+
export const all: Item[] = [
|
|
29
|
+
'minute',
|
|
30
|
+
'day',
|
|
31
|
+
'item',
|
|
32
|
+
'count'
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
export const builder = new ValueTypeBuilder<Item>();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type Flatten = {
|
|
39
|
+
item: Item,
|
|
40
|
+
maxCount: number | null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, FineTemplateRepetition> {
|
|
44
|
+
|
|
45
|
+
public build(flatten: Flatten): FineTemplateRepetition {
|
|
46
|
+
return new FineTemplateRepetition(
|
|
47
|
+
flatten.item,
|
|
48
|
+
flatten.maxCount
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const builder = new TypeBuilder();
|
|
54
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { BytesCoder, Flattable, ITypeBuilder, Sha512, Tagged, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
+
import { Team } from './Team';
|
|
3
|
+
import { Person } from './Person';
|
|
4
|
+
|
|
5
|
+
export class Invitation implements Flattable<Invitation.Flatten> {
|
|
6
|
+
|
|
7
|
+
constructor(
|
|
8
|
+
public teamId: Team.Id,
|
|
9
|
+
public personId: Person.Id
|
|
10
|
+
) {}
|
|
11
|
+
|
|
12
|
+
public createId(): Invitation.Id {
|
|
13
|
+
const hasher = new Sha512();
|
|
14
|
+
const teamIdBytes = BytesCoder.fromUtf8(this.teamId.guidString);
|
|
15
|
+
const personIdBytes = BytesCoder.fromUtf8(this.personId.guidString);
|
|
16
|
+
const hashedInvitationBytes = hasher.hash(new Uint8Array([...teamIdBytes, ...personIdBytes]));
|
|
17
|
+
const rawId = BytesCoder.toHex(hashedInvitationBytes).slice(0, 12);
|
|
18
|
+
return new Tagged(rawId, 'invitation');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public get flatten(): Invitation.Flatten {
|
|
22
|
+
return {
|
|
23
|
+
teamId: this.teamId.flatten,
|
|
24
|
+
personId: this.personId.flatten
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export namespace Invitation {
|
|
30
|
+
|
|
31
|
+
export type Id = Tagged<string, 'invitation'>;
|
|
32
|
+
|
|
33
|
+
export namespace Id {
|
|
34
|
+
|
|
35
|
+
export type Flatten = string;
|
|
36
|
+
|
|
37
|
+
export const builder = Tagged.builder('invitation' as const, new ValueTypeBuilder<string>());
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type Flatten = {
|
|
41
|
+
teamId: Team.Id.Flatten,
|
|
42
|
+
personId: Person.Id.Flatten
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, Invitation> {
|
|
46
|
+
|
|
47
|
+
public build(value: Flatten): Invitation {
|
|
48
|
+
return new Invitation(
|
|
49
|
+
Team.Id.builder.build(value.teamId),
|
|
50
|
+
Person.Id.builder.build(value.personId)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const builder = new TypeBuilder();
|
|
56
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Flattable, ITypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
+
import * as i18n from 'i18n';
|
|
3
|
+
import { Configuration } from './Configuration';
|
|
4
|
+
|
|
5
|
+
export class MoneyAmount implements Flattable<MoneyAmount.Flatten> {
|
|
6
|
+
|
|
7
|
+
public constructor(
|
|
8
|
+
public value: number,
|
|
9
|
+
public subunitValue: number
|
|
10
|
+
) {}
|
|
11
|
+
|
|
12
|
+
public static zero(): MoneyAmount {
|
|
13
|
+
return new MoneyAmount(0, 0);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public formatted(currency: Configuration.Currency): string {
|
|
17
|
+
const numberFormat = Intl.NumberFormat(i18n.getLocale(), {
|
|
18
|
+
style: 'currency',
|
|
19
|
+
currency: currency
|
|
20
|
+
});
|
|
21
|
+
return numberFormat.format(this.value + this.subunitValue / 100);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public get flatten(): MoneyAmount.Flatten {
|
|
25
|
+
return this.value + this.subunitValue / 100;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export namespace MoneyAmount {
|
|
30
|
+
|
|
31
|
+
export type Flatten = number;
|
|
32
|
+
|
|
33
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, MoneyAmount> {
|
|
34
|
+
|
|
35
|
+
public build(value: Flatten): MoneyAmount {
|
|
36
|
+
return new MoneyAmount(Math.floor(value), Math.round((value - Math.floor(value)) * 100));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const builder = new MoneyAmount.TypeBuilder();
|
|
41
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { BytesCoder, Dictionary, Flattable, ITypeBuilder, Sha512, Tagged, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
+
|
|
3
|
+
export class NotificationProperties implements Flattable<NotificationProperties.Flatten> {
|
|
4
|
+
|
|
5
|
+
public constructor(
|
|
6
|
+
public tokens: Dictionary<NotificationProperties.TokenId, string> = new Dictionary(NotificationProperties.TokenId.builder),
|
|
7
|
+
public subscriptions: NotificationProperties.Subscription[] = []
|
|
8
|
+
) {}
|
|
9
|
+
|
|
10
|
+
public get flatten(): NotificationProperties.Flatten {
|
|
11
|
+
return {
|
|
12
|
+
tokens: this.tokens.flatten,
|
|
13
|
+
subscriptions: this.subscriptions
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export namespace NotificationProperties {
|
|
19
|
+
|
|
20
|
+
export type TokenId = Tagged<string, 'notificationToken'>;
|
|
21
|
+
|
|
22
|
+
export namespace TokenId {
|
|
23
|
+
|
|
24
|
+
export function create(token: string): TokenId {
|
|
25
|
+
const hasher = new Sha512();
|
|
26
|
+
const tokenBytes = BytesCoder.fromUtf8(token);
|
|
27
|
+
const tokenIdBytes = hasher.hash(tokenBytes);
|
|
28
|
+
const tokenId = BytesCoder.toHex(tokenIdBytes);
|
|
29
|
+
const rawId = tokenId.slice(0, 16);
|
|
30
|
+
return new Tagged(rawId, 'notificationToken');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type Flatten = string;
|
|
34
|
+
|
|
35
|
+
export const builder = Tagged.builder('notificationToken' as const, new ValueTypeBuilder<string>());
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type Subscription =
|
|
39
|
+
| 'new-fine'
|
|
40
|
+
| 'fine-reminder'
|
|
41
|
+
| 'fine-state-change';
|
|
42
|
+
|
|
43
|
+
export namespace Subscription {
|
|
44
|
+
|
|
45
|
+
export const all: Subscription[] = [
|
|
46
|
+
'new-fine',
|
|
47
|
+
'fine-reminder',
|
|
48
|
+
'fine-state-change'
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
export const builder = new ValueTypeBuilder<Subscription>();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type Flatten = {
|
|
55
|
+
tokens: Dictionary.Flatten<string>,
|
|
56
|
+
subscriptions: Subscription[]
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, NotificationProperties> {
|
|
60
|
+
|
|
61
|
+
public build(value: Flatten): NotificationProperties {
|
|
62
|
+
return new NotificationProperties(Dictionary.builder(TokenId.builder, new ValueTypeBuilder<string>()).build(value.tokens), value.subscriptions);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const builder = new TypeBuilder();
|
|
67
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
+
|
|
3
|
+
export type PayedState =
|
|
4
|
+
| 'payed'
|
|
5
|
+
| 'notPayed';
|
|
6
|
+
|
|
7
|
+
export namespace PayedState {
|
|
8
|
+
|
|
9
|
+
export const all: PayedState[] = ['payed', 'notPayed'];
|
|
10
|
+
|
|
11
|
+
export const builder = new ValueTypeBuilder<PayedState>();
|
|
12
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { PersonPrivateProperties } from './PersonPrivateProperties';
|
|
2
|
+
import { PersonSignInProperties } from './PersonSignInProperties';
|
|
3
|
+
import { Fine } from './Fine';
|
|
4
|
+
import { Flattable, Guid, ITypeBuilder, Tagged } from '@stevenkellner/typescript-common-functionality';
|
|
5
|
+
|
|
6
|
+
export class Person implements Flattable<Person.Flatten> {
|
|
7
|
+
|
|
8
|
+
public constructor(
|
|
9
|
+
public id: Person.Id,
|
|
10
|
+
public properties: PersonPrivateProperties,
|
|
11
|
+
public fineIds: Fine.Id[] = [],
|
|
12
|
+
public signInProperties: PersonSignInProperties | null = null
|
|
13
|
+
) {}
|
|
14
|
+
|
|
15
|
+
public get flatten(): Person.Flatten {
|
|
16
|
+
return {
|
|
17
|
+
id: this.id.flatten,
|
|
18
|
+
properties: this.properties.flatten,
|
|
19
|
+
fineIds: this.fineIds.map(fineId => fineId.flatten),
|
|
20
|
+
signInProperties: this.signInProperties?.flatten ?? null
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export namespace Person {
|
|
26
|
+
|
|
27
|
+
export type Id = Tagged<Guid, 'person'>;
|
|
28
|
+
|
|
29
|
+
export namespace Id {
|
|
30
|
+
|
|
31
|
+
export type Flatten = string;
|
|
32
|
+
|
|
33
|
+
export const builder = Tagged.builder('person' as const, Guid.builder);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type Flatten = {
|
|
37
|
+
id: Id.Flatten,
|
|
38
|
+
properties: PersonPrivateProperties.Flatten,
|
|
39
|
+
fineIds: Fine.Id.Flatten[],
|
|
40
|
+
signInProperties: PersonSignInProperties.Flatten | null,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, Person> {
|
|
44
|
+
|
|
45
|
+
public build(value: Flatten): Person {
|
|
46
|
+
return new Person(
|
|
47
|
+
Id.builder.build(value.id),
|
|
48
|
+
PersonPrivateProperties.builder.build(value.properties),
|
|
49
|
+
value.fineIds.map(fineId => Fine.Id.builder.build(fineId)),
|
|
50
|
+
value.signInProperties ? PersonSignInProperties.builder.build(value.signInProperties) : null
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const builder = new TypeBuilder();
|
|
56
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Flattable, ITypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
+
|
|
3
|
+
export class PersonPrivateProperties implements Flattable<PersonPrivateProperties.Flatten> {
|
|
4
|
+
|
|
5
|
+
constructor(
|
|
6
|
+
public firstName: string,
|
|
7
|
+
public lastName: string | null
|
|
8
|
+
) {}
|
|
9
|
+
|
|
10
|
+
public get flatten(): PersonPrivateProperties.Flatten {
|
|
11
|
+
return {
|
|
12
|
+
firstName: this.firstName,
|
|
13
|
+
lastName: this.lastName
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export namespace PersonPrivateProperties {
|
|
19
|
+
|
|
20
|
+
export type Flatten = {
|
|
21
|
+
firstName: string;
|
|
22
|
+
lastName: string | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, PersonPrivateProperties> {
|
|
26
|
+
|
|
27
|
+
public build(value: Flatten): PersonPrivateProperties {
|
|
28
|
+
return new PersonPrivateProperties(
|
|
29
|
+
value.firstName,
|
|
30
|
+
value.lastName
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const builder = new TypeBuilder();
|
|
36
|
+
}
|
|
37
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Flattable, ITypeBuilder, UtcDate } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
+
import { NotificationProperties } from './NotificationProperties';
|
|
3
|
+
import { User } from './User';
|
|
4
|
+
import { UserRole } from './UserRole';
|
|
5
|
+
|
|
6
|
+
export class PersonSignInProperties implements Flattable<PersonSignInProperties.Flatten> {
|
|
7
|
+
|
|
8
|
+
public constructor(
|
|
9
|
+
public userId: User.Id,
|
|
10
|
+
public signInDate: UtcDate,
|
|
11
|
+
public notificationProperties: NotificationProperties = new NotificationProperties(),
|
|
12
|
+
public roles: UserRole[] = []
|
|
13
|
+
) {}
|
|
14
|
+
|
|
15
|
+
public get flatten(): PersonSignInProperties.Flatten {
|
|
16
|
+
return {
|
|
17
|
+
userId: this.userId.flatten,
|
|
18
|
+
signInDate: this.signInDate.flatten,
|
|
19
|
+
notificationProperties: this.notificationProperties.flatten,
|
|
20
|
+
roles: this.roles
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export namespace PersonSignInProperties {
|
|
26
|
+
|
|
27
|
+
export type Flatten = {
|
|
28
|
+
userId: User.Id.Flatten
|
|
29
|
+
signInDate: UtcDate.Flatten,
|
|
30
|
+
notificationProperties: NotificationProperties.Flatten,
|
|
31
|
+
roles: UserRole[]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, PersonSignInProperties> {
|
|
35
|
+
|
|
36
|
+
public build(value: Flatten): PersonSignInProperties {
|
|
37
|
+
return new PersonSignInProperties(User.Id.builder.build(value.userId), UtcDate.builder.build(value.signInDate), NotificationProperties.builder.build(value.notificationProperties), value.roles);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const builder = new TypeBuilder();
|
|
42
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Flattable, Guid, ITypeBuilder, Tagged } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
+
|
|
3
|
+
export class Team implements Flattable<Team.Flatten> {
|
|
4
|
+
|
|
5
|
+
public constructor(
|
|
6
|
+
public id: Team.Id,
|
|
7
|
+
public name: string,
|
|
8
|
+
public paypalMeLink: string | null
|
|
9
|
+
) {}
|
|
10
|
+
|
|
11
|
+
public get flatten(): Team.Flatten {
|
|
12
|
+
return {
|
|
13
|
+
id: this.id.flatten,
|
|
14
|
+
name: this.name,
|
|
15
|
+
paypalMeLink: this.paypalMeLink
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export namespace Team {
|
|
21
|
+
|
|
22
|
+
export type Id = Tagged<Guid, 'team'>;
|
|
23
|
+
|
|
24
|
+
export namespace Id {
|
|
25
|
+
|
|
26
|
+
export type Flatten = string;
|
|
27
|
+
|
|
28
|
+
export const builder = Tagged.builder('team' as const, Guid.builder);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type Flatten = {
|
|
32
|
+
id: Id.Flatten,
|
|
33
|
+
name: string,
|
|
34
|
+
paypalMeLink: string | null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, Team> {
|
|
38
|
+
|
|
39
|
+
public build(value: Flatten): Team {
|
|
40
|
+
return new Team(
|
|
41
|
+
Id.builder.build(value.id),
|
|
42
|
+
value.name,
|
|
43
|
+
value.paypalMeLink
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const builder = new TypeBuilder();
|
|
49
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Dictionary, Flattable, ITypeBuilder, Tagged, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
+
import { Team } from './Team';
|
|
3
|
+
import { Person } from './Person';
|
|
4
|
+
|
|
5
|
+
export class User implements Flattable<User.Flatten> {
|
|
6
|
+
|
|
7
|
+
public constructor(
|
|
8
|
+
public id: User.Id,
|
|
9
|
+
public teams: Dictionary<Team.Id, User.TeamProperties> = new Dictionary(Team.Id.builder)
|
|
10
|
+
) {}
|
|
11
|
+
|
|
12
|
+
public get flatten(): User.Flatten {
|
|
13
|
+
return {
|
|
14
|
+
id: this.id.flatten,
|
|
15
|
+
teams: this.teams.flatten
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export namespace User {
|
|
21
|
+
|
|
22
|
+
export type Id = Tagged<string, 'user'>;
|
|
23
|
+
|
|
24
|
+
export namespace Id {
|
|
25
|
+
|
|
26
|
+
export type Flatten = string;
|
|
27
|
+
|
|
28
|
+
export const builder = Tagged.builder('user' as const, new ValueTypeBuilder<string>());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class TeamProperties implements Flattable<TeamProperties.Flatten> {
|
|
32
|
+
|
|
33
|
+
public constructor(
|
|
34
|
+
public name: string,
|
|
35
|
+
public personId: Person.Id
|
|
36
|
+
) {}
|
|
37
|
+
|
|
38
|
+
public get flatten(): TeamProperties.Flatten {
|
|
39
|
+
return {
|
|
40
|
+
name: this.name,
|
|
41
|
+
personId: this.personId.flatten
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export namespace TeamProperties {
|
|
47
|
+
|
|
48
|
+
export type Flatten = {
|
|
49
|
+
name: string,
|
|
50
|
+
personId: Person.Id.Flatten
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, TeamProperties> {
|
|
54
|
+
|
|
55
|
+
public build(value: Flatten): TeamProperties {
|
|
56
|
+
return new TeamProperties(value.name, Person.Id.builder.build(value.personId));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const builder = new TypeBuilder();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type Flatten = {
|
|
64
|
+
id: Id.Flatten,
|
|
65
|
+
teams: Dictionary.Flatten<TeamProperties>
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, User> {
|
|
69
|
+
|
|
70
|
+
public build(value: Flatten): User {
|
|
71
|
+
return new User(Id.builder.build(value.id), Dictionary.builder(Team.Id.builder, User.TeamProperties.builder).build(value.teams));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const builder = new TypeBuilder();
|
|
76
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
+
|
|
3
|
+
export type UserRole =
|
|
4
|
+
| 'person-manager'
|
|
5
|
+
| 'fineTemplate-manager'
|
|
6
|
+
| 'fine-manager'
|
|
7
|
+
| 'team-manager';
|
|
8
|
+
|
|
9
|
+
export namespace UserRole {
|
|
10
|
+
|
|
11
|
+
export const all: UserRole[] = [
|
|
12
|
+
'person-manager',
|
|
13
|
+
'fineTemplate-manager',
|
|
14
|
+
'fine-manager',
|
|
15
|
+
'team-manager'
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export const builder = new ValueTypeBuilder<UserRole>();
|
|
19
|
+
}
|