@stevenkellner/team-conduct-api 1.0.4 → 1.0.5
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/Firestore.d.ts +15 -0
- package/lib/src/Firestore.js +53 -0
- package/{src/FirestoreScheme.ts → lib/src/FirestoreScheme.d.ts} +12 -13
- package/lib/src/FirestoreScheme.js +2 -0
- package/lib/src/checkAuthentication.d.ts +2 -0
- package/lib/src/checkAuthentication.js +31 -0
- package/lib/src/firebase/FirebaseConfiguration.d.ts +15 -0
- package/{src/firebase/FirebaseConfiguration.ts → lib/src/firebase/FirebaseConfiguration.js} +13 -24
- package/{src/firebase/Messaging.ts → lib/src/firebase/Messaging.d.ts} +0 -3
- package/lib/src/firebase/Messaging.js +2 -0
- package/lib/src/firebase/index.js +18 -0
- package/lib/src/firebaseFunctionCreators.d.ts +50 -0
- package/lib/src/firebaseFunctionCreators.js +58 -0
- package/lib/src/functions/fine/add.d.ts +37 -0
- package/lib/src/functions/fine/add.js +71 -0
- package/lib/src/functions/fine/delete.d.ts +24 -0
- package/lib/src/functions/fine/delete.js +71 -0
- package/lib/src/functions/fine/update.d.ts +38 -0
- package/lib/src/functions/fine/update.js +73 -0
- package/lib/src/functions/fineTemplate/add.d.ts +32 -0
- package/lib/src/functions/fineTemplate/add.js +23 -0
- package/lib/src/functions/fineTemplate/delete.d.ts +17 -0
- package/lib/src/functions/fineTemplate/delete.js +23 -0
- package/lib/src/functions/fineTemplate/update.d.ts +32 -0
- package/lib/src/functions/fineTemplate/update.js +23 -0
- package/lib/src/functions/invitation/invite.d.ts +7 -0
- package/lib/src/functions/invitation/invite.js +23 -0
- package/lib/src/functions/invitation/register.d.ts +7 -0
- package/lib/src/functions/invitation/register.js +43 -0
- package/lib/src/functions/invitation/withdraw.d.ts +8 -0
- package/lib/src/functions/invitation/withdraw.js +21 -0
- package/lib/src/functions/notification/register.d.ts +19 -0
- package/lib/src/functions/notification/register.js +27 -0
- package/lib/src/functions/notification/subscribe.d.ts +19 -0
- package/lib/src/functions/notification/subscribe.js +26 -0
- package/lib/src/functions/paypalMe/edit.d.ts +17 -0
- package/lib/src/functions/paypalMe/edit.js +25 -0
- package/lib/src/functions/person/add.d.ts +22 -0
- package/lib/src/functions/person/add.js +24 -0
- package/lib/src/functions/person/delete.d.ts +17 -0
- package/lib/src/functions/person/delete.js +25 -0
- package/lib/src/functions/person/update.d.ts +22 -0
- package/lib/src/functions/person/update.js +25 -0
- package/lib/src/functions/team/new.d.ts +26 -0
- package/lib/src/functions/team/new.js +36 -0
- package/lib/src/functions/user/login.d.ts +8 -0
- package/lib/src/functions/user/login.js +21 -0
- package/lib/src/functions/user/roleEdit.d.ts +19 -0
- package/lib/src/functions/user/roleEdit.js +30 -0
- package/lib/src/pushNotification.d.ts +3 -0
- package/lib/src/pushNotification.js +35 -0
- package/lib/src/types/Configuration.d.ts +27 -0
- package/lib/src/types/Configuration.js +38 -0
- package/lib/src/types/Fine.d.ts +30 -0
- package/lib/src/types/Fine.js +42 -0
- package/lib/src/types/FineAmount.d.ts +51 -0
- package/lib/src/types/FineAmount.js +124 -0
- package/lib/src/types/FineTemplate.d.ts +28 -0
- package/lib/src/types/FineTemplate.js +40 -0
- package/lib/src/types/FineTemplateRepetition.d.ts +22 -0
- package/lib/src/types/FineTemplateRepetition.js +38 -0
- package/lib/src/types/Invitation.d.ts +25 -0
- package/lib/src/types/Invitation.js +42 -0
- package/lib/src/types/MoneyAmount.d.ts +17 -0
- package/lib/src/types/MoneyAmount.js +68 -0
- package/lib/src/types/NotificationProperties.d.ts +28 -0
- package/lib/src/types/NotificationProperties.js +50 -0
- package/lib/src/types/PayedState.d.ts +6 -0
- package/lib/src/types/PayedState.js +9 -0
- package/lib/src/types/Person.d.ts +29 -0
- package/lib/src/types/Person.js +41 -0
- package/lib/src/types/PersonPrivateProperties.d.ts +17 -0
- package/lib/src/types/PersonPrivateProperties.js +27 -0
- package/lib/src/types/PersonSignInProperties.d.ts +24 -0
- package/lib/src/types/PersonSignInProperties.js +36 -0
- package/lib/src/types/Team.d.ts +24 -0
- package/lib/src/types/Team.js +35 -0
- package/lib/src/types/User.d.ts +40 -0
- package/lib/src/types/User.js +58 -0
- package/lib/src/types/UserRole.d.ts +6 -0
- package/lib/src/types/UserRole.js +14 -0
- package/lib/src/types/index.js +31 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +4 -1
- package/eslint.config.js +0 -72
- package/src/Firestore.ts +0 -63
- package/src/checkAuthentication.ts +0 -36
- package/src/firebaseFunctionCreators.ts +0 -56
- package/src/functions/fine/add.ts +0 -54
- package/src/functions/fine/delete.ts +0 -54
- package/src/functions/fine/update.ts +0 -55
- package/src/functions/fineTemplate/add.ts +0 -34
- package/src/functions/fineTemplate/delete.ts +0 -34
- package/src/functions/fineTemplate/update.ts +0 -34
- package/src/functions/invitation/invite.ts +0 -28
- package/src/functions/invitation/register.ts +0 -54
- package/src/functions/invitation/withdraw.ts +0 -24
- package/src/functions/notification/register.ts +0 -39
- package/src/functions/notification/subscribe.ts +0 -38
- package/src/functions/paypalMe/edit.ts +0 -36
- package/src/functions/person/add.ts +0 -36
- package/src/functions/person/delete.ts +0 -37
- package/src/functions/person/update.ts +0 -37
- package/src/functions/team/new.ts +0 -54
- package/src/functions/user/login.ts +0 -25
- package/src/functions/user/roleEdit.ts +0 -44
- package/src/locales/de.json +0 -30
- package/src/locales/en.json +0 -30
- package/src/pushNotification.ts +0 -37
- package/src/types/Configuration.ts +0 -54
- package/src/types/Fine.ts +0 -59
- package/src/types/FineAmount.ts +0 -123
- package/src/types/FineTemplate.ts +0 -55
- package/src/types/FineTemplateRepetition.ts +0 -54
- package/src/types/Invitation.ts +0 -56
- package/src/types/MoneyAmount.ts +0 -41
- package/src/types/NotificationProperties.ts +0 -67
- package/src/types/PayedState.ts +0 -12
- package/src/types/Person.ts +0 -56
- package/src/types/PersonPrivateProperties.ts +0 -37
- package/src/types/PersonSignInProperties.ts +0 -42
- package/src/types/Team.ts +0 -49
- package/src/types/User.ts +0 -76
- package/src/types/UserRole.ts +0 -19
- package/tsconfig.json +0 -117
- /package/{index.ts → lib/index.d.ts} +0 -0
- /package/{src/firebase/index.ts → lib/src/firebase/index.d.ts} +0 -0
- /package/{src/types/index.ts → lib/src/types/index.d.ts} +0 -0
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { NotificationProperties, Person, Team } from '../../types';
|
|
3
|
-
import { ArrayTypeBuilder, Flattable, ObjectTypeBuilder, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
-
import { Firestore } from '../../Firestore';
|
|
5
|
-
|
|
6
|
-
export namespace NotificationSubscribeFunction {
|
|
7
|
-
|
|
8
|
-
export type Parameters = {
|
|
9
|
-
teamId: Team.Id,
|
|
10
|
-
personId: Person.Id,
|
|
11
|
-
subscriptions: NotificationProperties.Subscription[]
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class NotificationSubscribeFunction extends FirebaseFunction<NotificationSubscribeFunction.Parameters, void> {
|
|
16
|
-
|
|
17
|
-
public parametersBuilder = new ObjectTypeBuilder<Flattable.Flatten<NotificationSubscribeFunction.Parameters>, NotificationSubscribeFunction.Parameters>({
|
|
18
|
-
teamId: Team.Id.builder,
|
|
19
|
-
personId: Person.Id.builder,
|
|
20
|
-
subscriptions: new ArrayTypeBuilder(new ValueTypeBuilder())
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
public returnTypeBuilder = new ValueTypeBuilder<void>();
|
|
24
|
-
|
|
25
|
-
public async execute(parameters: NotificationSubscribeFunction.Parameters): Promise<void> {
|
|
26
|
-
|
|
27
|
-
const personSnapshot = await Firestore.shared.person(parameters.teamId, parameters.personId).snapshot();
|
|
28
|
-
if (!personSnapshot.exists)
|
|
29
|
-
throw new FunctionsError('not-found', 'Person not found');
|
|
30
|
-
const person = Person.builder.build(personSnapshot.data);
|
|
31
|
-
|
|
32
|
-
if (person.signInProperties === null)
|
|
33
|
-
throw new FunctionsError('unauthenticated', 'Person not signed in');
|
|
34
|
-
|
|
35
|
-
person.signInProperties.notificationProperties.subscriptions = parameters.subscriptions;
|
|
36
|
-
await Firestore.shared.person(parameters.teamId, parameters.personId).set(person);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Flattable, ObjectTypeBuilder, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
-
import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
|
|
3
|
-
import { Team } from '../../types';
|
|
4
|
-
import { checkAuthentication } from '../../checkAuthentication';
|
|
5
|
-
import { Firestore } from '../../Firestore';
|
|
6
|
-
|
|
7
|
-
export namespace PaypalMeEditFunction {
|
|
8
|
-
|
|
9
|
-
export type Parameters = {
|
|
10
|
-
teamId: Team.Id;
|
|
11
|
-
paypalMeLink: string | null;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class PaypalMeEditFunction extends FirebaseFunction<PaypalMeEditFunction.Parameters, void> {
|
|
16
|
-
|
|
17
|
-
public parametersBuilder = new ObjectTypeBuilder<Flattable.Flatten<PaypalMeEditFunction.Parameters>, PaypalMeEditFunction.Parameters>({
|
|
18
|
-
teamId: Team.Id.builder,
|
|
19
|
-
paypalMeLink: new ValueTypeBuilder()
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
public returnTypeBuilder = new ValueTypeBuilder<void>();
|
|
23
|
-
|
|
24
|
-
public async execute(parameters: PaypalMeEditFunction.Parameters): Promise<void> {
|
|
25
|
-
|
|
26
|
-
await checkAuthentication(this.userId, parameters.teamId, 'team-manager');
|
|
27
|
-
|
|
28
|
-
const teamSnapshot = await Firestore.shared.team(parameters.teamId).snapshot();
|
|
29
|
-
if (!teamSnapshot.exists)
|
|
30
|
-
throw new FunctionsError('not-found', 'Team not found');
|
|
31
|
-
const team = Team.builder.build(teamSnapshot.data);
|
|
32
|
-
|
|
33
|
-
team.paypalMeLink = parameters.paypalMeLink;
|
|
34
|
-
await Firestore.shared.team(parameters.teamId).set(team);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { Person, PersonPrivateProperties, Team } from '../../types';
|
|
3
|
-
import { Flattable, ObjectTypeBuilder, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
-
import { checkAuthentication } from '../../checkAuthentication';
|
|
5
|
-
import { Firestore } from '../../Firestore';
|
|
6
|
-
|
|
7
|
-
export namespace PersonAddFunction {
|
|
8
|
-
|
|
9
|
-
export type Parameters = {
|
|
10
|
-
teamId: Team.Id
|
|
11
|
-
id: Person.Id,
|
|
12
|
-
properties: PersonPrivateProperties
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class PersonAddFunction extends FirebaseFunction<PersonAddFunction.Parameters, void> {
|
|
17
|
-
|
|
18
|
-
public parametersBuilder = new ObjectTypeBuilder<Flattable.Flatten<PersonAddFunction.Parameters>, PersonAddFunction.Parameters>({
|
|
19
|
-
teamId: Team.Id.builder,
|
|
20
|
-
id: Person.Id.builder,
|
|
21
|
-
properties: PersonPrivateProperties.builder
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
public returnTypeBuilder = new ValueTypeBuilder<void>();
|
|
25
|
-
|
|
26
|
-
public async execute(parameters: PersonAddFunction.Parameters): Promise<void> {
|
|
27
|
-
|
|
28
|
-
await checkAuthentication(this.userId, parameters.teamId, 'person-manager');
|
|
29
|
-
|
|
30
|
-
const personSnapshot = await Firestore.shared.person(parameters.teamId, parameters.id).snapshot();
|
|
31
|
-
if (personSnapshot.exists)
|
|
32
|
-
throw new FunctionsError('already-exists', 'Person already exists');
|
|
33
|
-
|
|
34
|
-
await Firestore.shared.person(parameters.teamId, parameters.id).set(new Person(parameters.id, parameters.properties));
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { Person, Team } from '../../types';
|
|
3
|
-
import { Flattable, ObjectTypeBuilder, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
-
import { checkAuthentication } from '../../checkAuthentication';
|
|
5
|
-
import { Firestore } from '../../Firestore';
|
|
6
|
-
|
|
7
|
-
export namespace PersonDeleteFunction {
|
|
8
|
-
|
|
9
|
-
export type Parameters = {
|
|
10
|
-
teamId: Team.Id,
|
|
11
|
-
id: Person.Id
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class PersonDeleteFunction extends FirebaseFunction<PersonDeleteFunction.Parameters, void> {
|
|
16
|
-
|
|
17
|
-
public parametersBuilder = new ObjectTypeBuilder<Flattable.Flatten<PersonDeleteFunction.Parameters>, PersonDeleteFunction.Parameters>({
|
|
18
|
-
teamId: Team.Id.builder,
|
|
19
|
-
id: Person.Id.builder
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
public returnTypeBuilder = new ValueTypeBuilder<void>();
|
|
23
|
-
|
|
24
|
-
public async execute(parameters: PersonDeleteFunction.Parameters): Promise<void> {
|
|
25
|
-
|
|
26
|
-
await checkAuthentication(this.userId, parameters.teamId, 'person-manager');
|
|
27
|
-
|
|
28
|
-
const personSnapshot = await Firestore.shared.person(parameters.teamId, parameters.id).snapshot();
|
|
29
|
-
if (!personSnapshot.exists)
|
|
30
|
-
throw new FunctionsError('not-found', 'Person not found');
|
|
31
|
-
|
|
32
|
-
if (personSnapshot.data.signInProperties !== null)
|
|
33
|
-
throw new FunctionsError('failed-precondition', 'Person is signed in');
|
|
34
|
-
|
|
35
|
-
await Firestore.shared.person(parameters.teamId, parameters.id).remove();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { Person, PersonPrivateProperties, Team } from '../../types';
|
|
3
|
-
import { Flattable, ObjectTypeBuilder, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
-
import { checkAuthentication } from '../../checkAuthentication';
|
|
5
|
-
import { Firestore } from '../../Firestore';
|
|
6
|
-
|
|
7
|
-
export namespace PersonUpdateFunction {
|
|
8
|
-
|
|
9
|
-
export type Parameters = {
|
|
10
|
-
teamId: Team.Id,
|
|
11
|
-
id: Person.Id,
|
|
12
|
-
properties: PersonPrivateProperties
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class PersonUpdateFunction extends FirebaseFunction<PersonUpdateFunction.Parameters, void> {
|
|
17
|
-
|
|
18
|
-
public parametersBuilder = new ObjectTypeBuilder<Flattable.Flatten<PersonUpdateFunction.Parameters>, PersonUpdateFunction.Parameters>({
|
|
19
|
-
teamId: Team.Id.builder,
|
|
20
|
-
id: Person.Id.builder,
|
|
21
|
-
properties: PersonPrivateProperties.builder
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
public returnTypeBuilder = new ValueTypeBuilder<void>();
|
|
25
|
-
|
|
26
|
-
public async execute(parameters: PersonUpdateFunction.Parameters): Promise<void> {
|
|
27
|
-
|
|
28
|
-
await checkAuthentication(this.userId, parameters.teamId, 'person-manager');
|
|
29
|
-
|
|
30
|
-
const personSnapshot = await Firestore.shared.person(parameters.teamId, parameters.id).snapshot();
|
|
31
|
-
if (!personSnapshot.exists)
|
|
32
|
-
throw new FunctionsError('not-found', 'Person not found');
|
|
33
|
-
const person = Person.builder.build(personSnapshot.data);
|
|
34
|
-
|
|
35
|
-
await Firestore.shared.person(parameters.teamId, parameters.id).set(new Person(parameters.id, parameters.properties, person.fineIds, person.signInProperties));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Flattable, ObjectTypeBuilder, UtcDate, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
-
import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
|
|
3
|
-
import { Person, PersonPrivateProperties, PersonSignInProperties, User, UserRole, Team, NotificationProperties } from '../../types';
|
|
4
|
-
import { Firestore } from '../../Firestore';
|
|
5
|
-
|
|
6
|
-
export namespace TeamNewFunction {
|
|
7
|
-
|
|
8
|
-
export type Parameters = {
|
|
9
|
-
id: Team.Id
|
|
10
|
-
name: string
|
|
11
|
-
paypalMeLink: string | null
|
|
12
|
-
personId: Person.Id
|
|
13
|
-
personProperties: PersonPrivateProperties
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class TeamNewFunction extends FirebaseFunction<TeamNewFunction.Parameters, User> {
|
|
18
|
-
|
|
19
|
-
public parametersBuilder = new ObjectTypeBuilder<Flattable.Flatten<TeamNewFunction.Parameters>, TeamNewFunction.Parameters>({
|
|
20
|
-
id: Team.Id.builder,
|
|
21
|
-
name: new ValueTypeBuilder(),
|
|
22
|
-
paypalMeLink: new ValueTypeBuilder(),
|
|
23
|
-
personId: Person.Id.builder,
|
|
24
|
-
personProperties: PersonPrivateProperties.builder
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
public returnTypeBuilder = User.builder;
|
|
28
|
-
|
|
29
|
-
public async execute(parameters: TeamNewFunction.Parameters): Promise<User> {
|
|
30
|
-
|
|
31
|
-
if (this.userId === null)
|
|
32
|
-
throw new FunctionsError('permission-denied', 'User is not authenticated');
|
|
33
|
-
const userId = User.Id.builder.build(this.userId);
|
|
34
|
-
|
|
35
|
-
const teamSnapshot = await Firestore.shared.team(parameters.id).snapshot();
|
|
36
|
-
if (teamSnapshot.exists)
|
|
37
|
-
throw new FunctionsError('already-exists', 'Team already exists');
|
|
38
|
-
|
|
39
|
-
const userSnapshot = await Firestore.shared.user(userId).snapshot();
|
|
40
|
-
let user = new User(userId);
|
|
41
|
-
if (userSnapshot.exists)
|
|
42
|
-
user = User.builder.build(userSnapshot.data);
|
|
43
|
-
|
|
44
|
-
user.teams.set(parameters.id, new User.TeamProperties(parameters.name, parameters.personId));
|
|
45
|
-
await Firestore.shared.user(userId).set(user);
|
|
46
|
-
|
|
47
|
-
await Firestore.shared.team(parameters.id).set(new Team(parameters.id, parameters.name, parameters.paypalMeLink));
|
|
48
|
-
|
|
49
|
-
const signInProperties = new PersonSignInProperties(userId, UtcDate.now, new NotificationProperties(), UserRole.all);
|
|
50
|
-
await Firestore.shared.person(parameters.id, parameters.personId).set(new Person(parameters.personId, parameters.personProperties, [], signInProperties));
|
|
51
|
-
|
|
52
|
-
return user;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { User } from '../../types';
|
|
3
|
-
import { ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
-
import { Firestore } from '../../Firestore';
|
|
5
|
-
|
|
6
|
-
export class UserLoginFunction extends FirebaseFunction<null, User> {
|
|
7
|
-
|
|
8
|
-
public parametersBuilder = new ValueTypeBuilder<null>();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
public returnTypeBuilder = User.builder;
|
|
12
|
-
|
|
13
|
-
public async execute(): Promise<User> {
|
|
14
|
-
|
|
15
|
-
if (this.userId === null)
|
|
16
|
-
throw new FunctionsError('unauthenticated', 'User is not authenticated.');
|
|
17
|
-
const userId = User.Id.builder.build(this.userId);
|
|
18
|
-
|
|
19
|
-
const userSnapshot = await Firestore.shared.user(userId).snapshot();
|
|
20
|
-
if (!userSnapshot.exists)
|
|
21
|
-
throw new FunctionsError('not-found', 'User not found.');
|
|
22
|
-
|
|
23
|
-
return User.builder.build(userSnapshot.data);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { checkAuthentication } from '../../checkAuthentication';
|
|
3
|
-
import { Person, Team, UserRole } from '../../types';
|
|
4
|
-
import { ArrayTypeBuilder, Flattable, ObjectTypeBuilder, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
5
|
-
import { Firestore } from '../../Firestore';
|
|
6
|
-
|
|
7
|
-
export namespace UserRoleEditFunction {
|
|
8
|
-
|
|
9
|
-
export type Parameters = {
|
|
10
|
-
teamId: Team.Id
|
|
11
|
-
personId: Person.Id
|
|
12
|
-
roles: UserRole[]
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class UserRoleEditFunction extends FirebaseFunction<UserRoleEditFunction.Parameters, void> {
|
|
17
|
-
|
|
18
|
-
public parametersBuilder = new ObjectTypeBuilder<Flattable.Flatten<UserRoleEditFunction.Parameters>, UserRoleEditFunction.Parameters>({
|
|
19
|
-
teamId: Team.Id.builder,
|
|
20
|
-
personId: Person.Id.builder,
|
|
21
|
-
roles: new ArrayTypeBuilder(new ValueTypeBuilder())
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
public returnTypeBuilder = new ValueTypeBuilder<void>();
|
|
25
|
-
|
|
26
|
-
public async execute(parameters: UserRoleEditFunction.Parameters): Promise<void> {
|
|
27
|
-
|
|
28
|
-
const userId = await checkAuthentication(this.userId, parameters.teamId, 'team-manager');
|
|
29
|
-
|
|
30
|
-
const personSnapshot = await Firestore.shared.person(parameters.teamId, parameters.personId).snapshot();
|
|
31
|
-
if (!personSnapshot.exists)
|
|
32
|
-
throw new FunctionsError('not-found', 'User does not exist');
|
|
33
|
-
const person = Person.builder.build(personSnapshot.data);
|
|
34
|
-
|
|
35
|
-
if (person.signInProperties === null)
|
|
36
|
-
throw new FunctionsError('permission-denied', 'User is not signed in');
|
|
37
|
-
|
|
38
|
-
if (person.signInProperties.userId.value === userId.value && !parameters.roles.includes('team-manager'))
|
|
39
|
-
throw new FunctionsError('unavailable', 'User cannot remove their own team-manager role');
|
|
40
|
-
|
|
41
|
-
person.signInProperties.roles = parameters.roles;
|
|
42
|
-
await Firestore.shared.person(parameters.teamId, parameters.personId).set(person);
|
|
43
|
-
}
|
|
44
|
-
}
|
package/src/locales/de.json
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"notification": {
|
|
3
|
-
"fine": {
|
|
4
|
-
"new": {
|
|
5
|
-
"title": "%s",
|
|
6
|
-
"body": "Du hast eine neue Strafe von %s. Bitte so schnell wie möglich zahlen."
|
|
7
|
-
},
|
|
8
|
-
"reminder": {
|
|
9
|
-
"title": "Du hast noch offene Strafen",
|
|
10
|
-
"body": "Bei dir sind noch %s offen. Bitte so schnell wie möglich zahlen."
|
|
11
|
-
},
|
|
12
|
-
"state-change": {
|
|
13
|
-
"title": "Eine deiner Strafen hat sich geändert",
|
|
14
|
-
"body-payed": "Du hast eine Strafe von %1$s bezahlt (%2$s).",
|
|
15
|
-
"body-unpayed": "%1$s, %2$s ist noch offen.",
|
|
16
|
-
"body-deleted": "%1$s, %2$s wurde gelöscht."
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"FineAmount": {
|
|
21
|
-
"Item": {
|
|
22
|
-
"Type": {
|
|
23
|
-
"crateOfBeer": {
|
|
24
|
-
"singular": "Ein Kasten Bier",
|
|
25
|
-
"plural": "%s Kästen Bier"
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
package/src/locales/en.json
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"notification": {
|
|
3
|
-
"fine": {
|
|
4
|
-
"new": {
|
|
5
|
-
"title": "%s",
|
|
6
|
-
"body": "You have a new fine of %s. Please pay it as soon as possible."
|
|
7
|
-
},
|
|
8
|
-
"reminder": {
|
|
9
|
-
"title": "You still have outstanding penalties",
|
|
10
|
-
"body": "You still have %s outstanding. Please pay as soon as possible."
|
|
11
|
-
},
|
|
12
|
-
"state-change": {
|
|
13
|
-
"title": "One of your penalties has changed",
|
|
14
|
-
"body-paid": "You have paid a penalty of %1$s (%2$s).",
|
|
15
|
-
"body-unpayed": "%1$s, %2$s are still outstanding.",
|
|
16
|
-
"body-deleted": "%1$s, %2$s has been deleted."
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"FineAmount": {
|
|
21
|
-
"Item": {
|
|
22
|
-
"Type": {
|
|
23
|
-
"crateOfBeer": {
|
|
24
|
-
"singular": "One Crate of Beer",
|
|
25
|
-
"plural": "%s Crates of Beer"
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
package/src/pushNotification.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Dictionary } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
-
import { Firestore } from './Firestore';
|
|
3
|
-
import { NotificationProperties, Person, Team } from './types';
|
|
4
|
-
import { FirebaseConfiguration, BatchResponse, Notification } from './firebase';
|
|
5
|
-
|
|
6
|
-
function successfulTokens(response: BatchResponse, tokens: string[]): Dictionary<NotificationProperties.TokenId, string> {
|
|
7
|
-
const successfulTokens = response.responses
|
|
8
|
-
.map((response, index) => ({
|
|
9
|
-
failed: response.error?.code ==='messaging/invalid-registration-token' || response.error?.code === 'messaging/registration-token-not-registered',
|
|
10
|
-
token: tokens[index]
|
|
11
|
-
}))
|
|
12
|
-
.filter(response => !response.failed)
|
|
13
|
-
.map(response => response.token);
|
|
14
|
-
const tokenDict = new Dictionary<NotificationProperties.TokenId, string>(NotificationProperties.TokenId.builder);
|
|
15
|
-
for (const token of successfulTokens)
|
|
16
|
-
tokenDict.set(NotificationProperties.TokenId.create(token), token);
|
|
17
|
-
return tokenDict;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export async function pushNotification(teamId: Team.Id, personId: Person.Id, topic: NotificationProperties.Subscription, notification: Notification): Promise<void> {
|
|
21
|
-
|
|
22
|
-
const personSnapshot = await Firestore.shared.person(teamId, personId).snapshot();
|
|
23
|
-
if (!personSnapshot.exists)
|
|
24
|
-
return;
|
|
25
|
-
const person = Person.builder.build(personSnapshot.data);
|
|
26
|
-
|
|
27
|
-
if (person.signInProperties === null || !person.signInProperties.notificationProperties.subscriptions.includes(topic))
|
|
28
|
-
return;
|
|
29
|
-
|
|
30
|
-
const tokens = person.signInProperties.notificationProperties.tokens.values;
|
|
31
|
-
const response = await FirebaseConfiguration.shared.messaging.sendEachForMulticast({
|
|
32
|
-
tokens: tokens,
|
|
33
|
-
notification: notification
|
|
34
|
-
});
|
|
35
|
-
person.signInProperties.notificationProperties.tokens = successfulTokens(response, tokens);
|
|
36
|
-
await Firestore.shared.person(teamId, personId).set(person);
|
|
37
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Flattable, ITypeBuilder, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
-
|
|
3
|
-
export class Configuration implements Flattable<Configuration.Flatten> {
|
|
4
|
-
|
|
5
|
-
public constructor(
|
|
6
|
-
public currency: Configuration.Currency,
|
|
7
|
-
public locale: Configuration.Locale
|
|
8
|
-
) {}
|
|
9
|
-
|
|
10
|
-
public get flatten(): Configuration.Flatten {
|
|
11
|
-
return {
|
|
12
|
-
currency: this.currency,
|
|
13
|
-
locale: this.locale
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export namespace Configuration {
|
|
19
|
-
|
|
20
|
-
export type Currency = 'EUR' | 'USD';
|
|
21
|
-
|
|
22
|
-
export namespace Currency {
|
|
23
|
-
|
|
24
|
-
export const all: Currency[] = ['EUR', 'USD'];
|
|
25
|
-
|
|
26
|
-
export const builder = new ValueTypeBuilder<Currency>();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export type Locale = 'de' | 'en';
|
|
30
|
-
|
|
31
|
-
export namespace Locale {
|
|
32
|
-
|
|
33
|
-
export const all: Locale[] = ['de', 'en'];
|
|
34
|
-
|
|
35
|
-
export const builder = new ValueTypeBuilder<Locale>();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export type Flatten = {
|
|
39
|
-
currency: Currency,
|
|
40
|
-
locale: Locale
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export class TypeBuilder implements ITypeBuilder<Flatten, Configuration> {
|
|
44
|
-
|
|
45
|
-
public build(flatten: Flatten): Configuration {
|
|
46
|
-
return new Configuration(
|
|
47
|
-
flatten.currency,
|
|
48
|
-
flatten.locale
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export const builder = new TypeBuilder();
|
|
54
|
-
}
|
package/src/types/Fine.ts
DELETED
|
@@ -1,59 +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
|
-
export class Fine implements Flattable<Fine.Flatten> {
|
|
6
|
-
|
|
7
|
-
public constructor(
|
|
8
|
-
public id: Fine.Id,
|
|
9
|
-
public payedState: PayedState,
|
|
10
|
-
public date: UtcDate,
|
|
11
|
-
public reason: string,
|
|
12
|
-
public amount: FineAmount
|
|
13
|
-
) {}
|
|
14
|
-
|
|
15
|
-
public get flatten(): Fine.Flatten {
|
|
16
|
-
return {
|
|
17
|
-
id: this.id.flatten,
|
|
18
|
-
payedState: this.payedState,
|
|
19
|
-
date: this.date.flatten,
|
|
20
|
-
reason: this.reason,
|
|
21
|
-
amount: this.amount.flatten
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export namespace Fine {
|
|
27
|
-
|
|
28
|
-
export type Id = Tagged<Guid, 'fine'>;
|
|
29
|
-
|
|
30
|
-
export namespace Id {
|
|
31
|
-
|
|
32
|
-
export type Flatten = string;
|
|
33
|
-
|
|
34
|
-
export const builder = Tagged.builder('fine' as const, Guid.builder);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export type Flatten = {
|
|
38
|
-
id: Id.Flatten,
|
|
39
|
-
payedState: PayedState,
|
|
40
|
-
date: UtcDate.Flatten,
|
|
41
|
-
reason: string,
|
|
42
|
-
amount: FineAmount.Flatten
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export class TypeBuilder implements ITypeBuilder<Flatten, Fine> {
|
|
46
|
-
|
|
47
|
-
public build(value: Flatten): Fine {
|
|
48
|
-
return new Fine(
|
|
49
|
-
Id.builder.build(value.id),
|
|
50
|
-
value.payedState,
|
|
51
|
-
UtcDate.builder.build(value.date),
|
|
52
|
-
value.reason,
|
|
53
|
-
FineAmount.builder.build(value.amount)
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const builder = new TypeBuilder();
|
|
59
|
-
}
|
package/src/types/FineAmount.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
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
|
-
}
|