@stevenkellner/team-conduct-api 1.0.3 → 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/lib/src/firebase/FirebaseConfiguration.js +28 -0
- 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/firebase/FirebaseConfiguration.ts +0 -39
- 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
package/eslint.config.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
defineConfig,
|
|
3
|
-
globalIgnores,
|
|
4
|
-
} = require("eslint/config");
|
|
5
|
-
|
|
6
|
-
const globals = require("globals");
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
fixupConfigRules,
|
|
10
|
-
fixupPluginRules,
|
|
11
|
-
} = require("@eslint/compat");
|
|
12
|
-
|
|
13
|
-
const tsParser = require("@typescript-eslint/parser");
|
|
14
|
-
const typescriptEslint = require("@typescript-eslint/eslint-plugin");
|
|
15
|
-
const _import = require("eslint-plugin-import");
|
|
16
|
-
const js = require("@eslint/js");
|
|
17
|
-
|
|
18
|
-
const {
|
|
19
|
-
FlatCompat,
|
|
20
|
-
} = require("@eslint/eslintrc");
|
|
21
|
-
|
|
22
|
-
const compat = new FlatCompat({
|
|
23
|
-
baseDirectory: __dirname,
|
|
24
|
-
recommendedConfig: js.configs.recommended,
|
|
25
|
-
allConfig: js.configs.all
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
module.exports = defineConfig([{
|
|
29
|
-
languageOptions: {
|
|
30
|
-
globals: {
|
|
31
|
-
...globals.node,
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
parser: tsParser,
|
|
35
|
-
sourceType: "module",
|
|
36
|
-
|
|
37
|
-
parserOptions: {
|
|
38
|
-
project: ["tsconfig.json", "tsconfig.dev.json"],
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
extends: fixupConfigRules(compat.extends(
|
|
43
|
-
"eslint:recommended",
|
|
44
|
-
"plugin:import/errors",
|
|
45
|
-
"plugin:import/warnings",
|
|
46
|
-
"plugin:import/typescript",
|
|
47
|
-
// "google",
|
|
48
|
-
"plugin:@typescript-eslint/recommended",
|
|
49
|
-
)),
|
|
50
|
-
|
|
51
|
-
plugins: {
|
|
52
|
-
"@typescript-eslint": fixupPluginRules(typescriptEslint),
|
|
53
|
-
import: fixupPluginRules(_import),
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
rules: {
|
|
57
|
-
"quotes": ["error", "single"],
|
|
58
|
-
"import/no-unresolved": 0,
|
|
59
|
-
"indent": ["error", 4],
|
|
60
|
-
"object-curly-spacing": ["error", "always"],
|
|
61
|
-
"@typescript-eslint/no-namespace": "off",
|
|
62
|
-
"comma-dangle": ["error", "never"],
|
|
63
|
-
"max-len": "off",
|
|
64
|
-
"require-jsdoc": "off",
|
|
65
|
-
"padded-blocks": "off",
|
|
66
|
-
"curly": ["error", "multi-or-nest"],
|
|
67
|
-
"arrow-parens": ["error", "as-needed"],
|
|
68
|
-
"@typescript-eslint/no-floating-promises": "error",
|
|
69
|
-
"new-cap": "off",
|
|
70
|
-
"@typescript-eslint/no-inferrable-types": "off",
|
|
71
|
-
},
|
|
72
|
-
}, globalIgnores(["lib/**/*", "generated/**/*", "coverage/**/*", ".nyc_output/**/*", "eslint.config.js", ".mocharc.js"])]);
|
package/src/Firestore.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { FirestoreDocument } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { FirestoreScheme } from './FirestoreScheme';
|
|
3
|
-
import { Fine, FineTemplate, Invitation, Person, User, Team } from './types';
|
|
4
|
-
import { FirebaseConfiguration } from './firebase';
|
|
5
|
-
|
|
6
|
-
export class Firestore {
|
|
7
|
-
|
|
8
|
-
protected base: FirestoreScheme;
|
|
9
|
-
|
|
10
|
-
protected constructor() {
|
|
11
|
-
this.base = FirebaseConfiguration.shared.baseFirestoreDocument;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
private static sharedInstance: Firestore | null = null;
|
|
15
|
-
|
|
16
|
-
public static get shared(): Firestore {
|
|
17
|
-
if (!Firestore.sharedInstance)
|
|
18
|
-
Firestore.sharedInstance = new Firestore();
|
|
19
|
-
return Firestore.sharedInstance;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public team(id: Team.Id): FirestoreDocument<Team> {
|
|
23
|
-
return this.base
|
|
24
|
-
.collection('teams')
|
|
25
|
-
.document(id.guidString) as FirestoreDocument<Team>;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public user(id: User.Id): FirestoreDocument<User> {
|
|
29
|
-
return this.base
|
|
30
|
-
.collection('users')
|
|
31
|
-
.document(id.value);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public invitation(id: Invitation.Id): FirestoreDocument<Invitation> {
|
|
35
|
-
return this.base
|
|
36
|
-
.collection('invitations')
|
|
37
|
-
.document(id.value);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public person(teamId: Team.Id, id: Person.Id): FirestoreDocument<Person> {
|
|
41
|
-
return this.base
|
|
42
|
-
.collection('teams')
|
|
43
|
-
.document(teamId.guidString)
|
|
44
|
-
.collection('persons')
|
|
45
|
-
.document(id.guidString);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public fineTemplate(teamId: Team.Id, id: FineTemplate.Id): FirestoreDocument<FineTemplate> {
|
|
49
|
-
return this.base
|
|
50
|
-
.collection('teams')
|
|
51
|
-
.document(teamId.guidString)
|
|
52
|
-
.collection('fineTemplates')
|
|
53
|
-
.document(id.guidString);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public fine(teamId: Team.Id, id: Fine.Id): FirestoreDocument<Fine> {
|
|
57
|
-
return this.base
|
|
58
|
-
.collection('teams')
|
|
59
|
-
.document(teamId.guidString)
|
|
60
|
-
.collection('fines')
|
|
61
|
-
.document(id.guidString);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { FunctionsError } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { Person, Team, User, UserRole } from './types';
|
|
3
|
-
import { Firestore } from './Firestore';
|
|
4
|
-
|
|
5
|
-
function includesAll<T>(array: T[], ...values: T[]): boolean {
|
|
6
|
-
return values.every(value => array.includes(value));
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export async function checkAuthentication(rawUserId: string | null, teamId: Team.Id, ...roles: UserRole[]): Promise<User.Id> {
|
|
10
|
-
if (rawUserId === null)
|
|
11
|
-
throw new FunctionsError('unauthenticated', 'User is not authenticated');
|
|
12
|
-
const userId = User.Id.builder.build(rawUserId);
|
|
13
|
-
|
|
14
|
-
const userSnapshot = await Firestore.shared.user(userId).snapshot();
|
|
15
|
-
if (!userSnapshot.exists)
|
|
16
|
-
throw new FunctionsError('permission-denied', 'User does not exist');
|
|
17
|
-
const user = User.builder.build(userSnapshot.data);
|
|
18
|
-
|
|
19
|
-
if (!user.teams.has(teamId))
|
|
20
|
-
throw new FunctionsError('permission-denied', 'User is not a member of the team');
|
|
21
|
-
const team = user.teams.get(teamId);
|
|
22
|
-
|
|
23
|
-
const personSnapshot = await Firestore.shared.person(teamId, team.personId).snapshot();
|
|
24
|
-
if (!personSnapshot.exists)
|
|
25
|
-
throw new FunctionsError('permission-denied', 'Person does not exist');
|
|
26
|
-
const person = Person.builder.build(personSnapshot.data);
|
|
27
|
-
|
|
28
|
-
if (person.signInProperties === null)
|
|
29
|
-
throw new FunctionsError('permission-denied', 'Person is not signed in');
|
|
30
|
-
|
|
31
|
-
const userHasRoles = includesAll(person.signInProperties.roles, ...roles);
|
|
32
|
-
if (!userHasRoles)
|
|
33
|
-
throw new FunctionsError('permission-denied', 'User does not have the required roles');
|
|
34
|
-
|
|
35
|
-
return userId;
|
|
36
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { FirestoreScheme } from '../FirestoreScheme';
|
|
2
|
-
import { Messaging } from './Messaging';
|
|
3
|
-
|
|
4
|
-
export class FirebaseConfiguration {
|
|
5
|
-
|
|
6
|
-
public static readonly shared = new FirebaseConfiguration();
|
|
7
|
-
|
|
8
|
-
private configured: boolean = false;
|
|
9
|
-
|
|
10
|
-
private _baseFirestoreDocument: FirestoreScheme | null = null;
|
|
11
|
-
|
|
12
|
-
private _messaging: Messaging | null = null;
|
|
13
|
-
|
|
14
|
-
private constructor() {}
|
|
15
|
-
|
|
16
|
-
public configure(
|
|
17
|
-
baseFirestoreDocument: FirestoreScheme,
|
|
18
|
-
messaging: Messaging
|
|
19
|
-
) {
|
|
20
|
-
if (this.configured)
|
|
21
|
-
throw new Error('Configuration is already configured');
|
|
22
|
-
this._baseFirestoreDocument = baseFirestoreDocument;
|
|
23
|
-
this._messaging = messaging;
|
|
24
|
-
this.configured = true;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public get baseFirestoreDocument(): FirestoreScheme {
|
|
28
|
-
if (!this.configured || !this._baseFirestoreDocument)
|
|
29
|
-
throw new Error('Configuration.baseFirestoreDocument is not configured');
|
|
30
|
-
return this._baseFirestoreDocument;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public get messaging(): Messaging {
|
|
34
|
-
if (!this.configured || !this._messaging)
|
|
35
|
-
throw new Error('Configuration.messaging is not configured');
|
|
36
|
-
return this._messaging;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { createFirebaseFunctionCreators } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { TeamNewFunction } from './functions/team/new';
|
|
3
|
-
import { UserLoginFunction } from './functions/user/login';
|
|
4
|
-
import { UserRoleEditFunction } from './functions/user/roleEdit';
|
|
5
|
-
import { PaypalMeEditFunction } from './functions/paypalMe/edit';
|
|
6
|
-
import { NotificationRegisterFunction } from './functions/notification/register';
|
|
7
|
-
import { NotificationSubscribeFunction } from './functions/notification/subscribe';
|
|
8
|
-
import { InvitationInviteFunction } from './functions/invitation/invite';
|
|
9
|
-
import { InvitationWithdrawFunction } from './functions/invitation/withdraw';
|
|
10
|
-
import { InvitationRegisterFunction } from './functions/invitation/register';
|
|
11
|
-
import { PersonAddFunction } from './functions/person/add';
|
|
12
|
-
import { PersonUpdateFunction } from './functions/person/update';
|
|
13
|
-
import { PersonDeleteFunction } from './functions/person/delete';
|
|
14
|
-
import { FineAddFunction } from './functions/fine/add';
|
|
15
|
-
import { FineUpdateFunction } from './functions/fine/update';
|
|
16
|
-
import { FineDeleteFunction } from './functions/fine/delete';
|
|
17
|
-
import { FineTemplateAddFunction } from './functions/fineTemplate/add';
|
|
18
|
-
import { FineTemplateUpdateFunction } from './functions/fineTemplate/update';
|
|
19
|
-
import { FineTemplateDeleteFunction } from './functions/fineTemplate/delete';
|
|
20
|
-
|
|
21
|
-
export const firebaseFunctionCreators = createFirebaseFunctionCreators(builder => ({
|
|
22
|
-
team: {
|
|
23
|
-
new: builder.function(TeamNewFunction)
|
|
24
|
-
},
|
|
25
|
-
user: {
|
|
26
|
-
login: builder.function(UserLoginFunction),
|
|
27
|
-
roleEdit: builder.function(UserRoleEditFunction)
|
|
28
|
-
},
|
|
29
|
-
paypalMe: {
|
|
30
|
-
edit: builder.function(PaypalMeEditFunction)
|
|
31
|
-
},
|
|
32
|
-
notification: {
|
|
33
|
-
register: builder.function(NotificationRegisterFunction),
|
|
34
|
-
subscribe: builder.function(NotificationSubscribeFunction)
|
|
35
|
-
},
|
|
36
|
-
invitation: {
|
|
37
|
-
invite: builder.function(InvitationInviteFunction),
|
|
38
|
-
withdraw: builder.function(InvitationWithdrawFunction),
|
|
39
|
-
register: builder.function(InvitationRegisterFunction)
|
|
40
|
-
},
|
|
41
|
-
person: {
|
|
42
|
-
add: builder.function(PersonAddFunction),
|
|
43
|
-
update: builder.function(PersonUpdateFunction),
|
|
44
|
-
delete: builder.function(PersonDeleteFunction)
|
|
45
|
-
},
|
|
46
|
-
fineTemplate: {
|
|
47
|
-
add: builder.function(FineTemplateAddFunction),
|
|
48
|
-
update: builder.function(FineTemplateUpdateFunction),
|
|
49
|
-
delete: builder.function(FineTemplateDeleteFunction)
|
|
50
|
-
},
|
|
51
|
-
fine: {
|
|
52
|
-
add: builder.function(FineAddFunction),
|
|
53
|
-
update: builder.function(FineUpdateFunction),
|
|
54
|
-
delete: builder.function(FineDeleteFunction)
|
|
55
|
-
}
|
|
56
|
-
}));
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { Flattable, ObjectTypeBuilder, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
3
|
-
import { Configuration, Fine, Person, Team } from '../../types';
|
|
4
|
-
import { checkAuthentication } from '../../checkAuthentication';
|
|
5
|
-
import { Firestore } from '../../Firestore';
|
|
6
|
-
import { pushNotification } from '../../pushNotification';
|
|
7
|
-
import * as i18n from 'i18n';
|
|
8
|
-
|
|
9
|
-
export namespace FineAddFunction {
|
|
10
|
-
|
|
11
|
-
export type Parameters = {
|
|
12
|
-
teamId: Team.Id,
|
|
13
|
-
personId: Person.Id,
|
|
14
|
-
fine: Fine,
|
|
15
|
-
configuration: Configuration
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class FineAddFunction extends FirebaseFunction<FineAddFunction.Parameters, void> {
|
|
20
|
-
|
|
21
|
-
public parametersBuilder = new ObjectTypeBuilder<Flattable.Flatten<FineAddFunction.Parameters>, FineAddFunction.Parameters>({
|
|
22
|
-
teamId: Team.Id.builder,
|
|
23
|
-
personId: Person.Id.builder,
|
|
24
|
-
fine: Fine.builder,
|
|
25
|
-
configuration: Configuration.builder
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
public returnTypeBuilder = new ValueTypeBuilder<void>();
|
|
29
|
-
|
|
30
|
-
public async execute(parameters: FineAddFunction.Parameters): Promise<void> {
|
|
31
|
-
|
|
32
|
-
await checkAuthentication(this.userId, parameters.teamId, 'fine-manager');
|
|
33
|
-
|
|
34
|
-
const fineSnapshot = await Firestore.shared.fine(parameters.teamId, parameters.fine.id).snapshot();
|
|
35
|
-
if (fineSnapshot.exists)
|
|
36
|
-
throw new FunctionsError('already-exists', 'Fine already exists');
|
|
37
|
-
|
|
38
|
-
const personSnapshot = await Firestore.shared.person(parameters.teamId, parameters.personId).snapshot();
|
|
39
|
-
if (!personSnapshot.exists)
|
|
40
|
-
throw new FunctionsError('not-found', 'Person not found');
|
|
41
|
-
const person = Person.builder.build(personSnapshot.data);
|
|
42
|
-
|
|
43
|
-
await Firestore.shared.fine(parameters.teamId, parameters.fine.id).set(parameters.fine);
|
|
44
|
-
|
|
45
|
-
person.fineIds.push(parameters.fine.id);
|
|
46
|
-
await Firestore.shared.person(parameters.teamId, parameters.personId).set(person);
|
|
47
|
-
|
|
48
|
-
i18n.setLocale(parameters.configuration.locale);
|
|
49
|
-
await pushNotification(parameters.teamId, parameters.personId, 'new-fine', {
|
|
50
|
-
title: i18n.__('notification.fine.new.title', parameters.fine.reason),
|
|
51
|
-
body: i18n.__('notification.fine.new.body', parameters.fine.amount.formatted(parameters.configuration))
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { Configuration, Fine, FineAmount, 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
|
-
import { pushNotification } from '../../pushNotification';
|
|
7
|
-
import * as i18n from 'i18n';
|
|
8
|
-
|
|
9
|
-
export namespace FineDeleteFunction {
|
|
10
|
-
|
|
11
|
-
export type Parameters = {
|
|
12
|
-
teamId: Team.Id,
|
|
13
|
-
personId: Person.Id,
|
|
14
|
-
id: Fine.Id,
|
|
15
|
-
configuration: Configuration
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class FineDeleteFunction extends FirebaseFunction<FineDeleteFunction.Parameters, void> {
|
|
20
|
-
|
|
21
|
-
public parametersBuilder = new ObjectTypeBuilder<Flattable.Flatten<FineDeleteFunction.Parameters>, FineDeleteFunction.Parameters>({
|
|
22
|
-
teamId: Team.Id.builder,
|
|
23
|
-
personId: Person.Id.builder,
|
|
24
|
-
id: Fine.Id.builder,
|
|
25
|
-
configuration: Configuration.builder
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
public returnTypeBuilder = new ValueTypeBuilder<void>();
|
|
29
|
-
|
|
30
|
-
public async execute(parameters: FineDeleteFunction.Parameters): Promise<void> {
|
|
31
|
-
|
|
32
|
-
await checkAuthentication(this.userId, parameters.teamId, 'fine-manager');
|
|
33
|
-
|
|
34
|
-
const fineSnapshot = await Firestore.shared.fine(parameters.teamId, parameters.id).snapshot();
|
|
35
|
-
if (!fineSnapshot.exists)
|
|
36
|
-
throw new FunctionsError('not-found', 'Fine not found');
|
|
37
|
-
|
|
38
|
-
const personSnapshot = await Firestore.shared.person(parameters.teamId, parameters.personId).snapshot();
|
|
39
|
-
if (!personSnapshot.exists)
|
|
40
|
-
throw new FunctionsError('not-found', 'Person not found');
|
|
41
|
-
const person = Person.builder.build(personSnapshot.data);
|
|
42
|
-
|
|
43
|
-
await Firestore.shared.fine(parameters.teamId, parameters.id).remove();
|
|
44
|
-
|
|
45
|
-
person.fineIds = person.fineIds.filter(id => id.guidString !== parameters.id.guidString);
|
|
46
|
-
await Firestore.shared.person(parameters.teamId, parameters.personId).set(person);
|
|
47
|
-
|
|
48
|
-
i18n.setLocale(parameters.configuration.locale);
|
|
49
|
-
await pushNotification(parameters.teamId, parameters.personId, 'fine-state-change', {
|
|
50
|
-
title: i18n.__('notification.fine.state-change.title'),
|
|
51
|
-
body: i18n.__('notification.fine.state-change.body-deleted', fineSnapshot.data.reason, FineAmount.builder.build(fineSnapshot.data.amount).formatted(parameters.configuration))
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { Configuration } from '../../types/Configuration';
|
|
2
|
-
import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
|
|
3
|
-
import { pushNotification } from '../../pushNotification';
|
|
4
|
-
import { Fine, Person, Team } from '../../types';
|
|
5
|
-
import { Flattable, ObjectTypeBuilder, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
6
|
-
import { checkAuthentication } from '../../checkAuthentication';
|
|
7
|
-
import { Firestore } from '../../Firestore';
|
|
8
|
-
import * as i18n from 'i18n';
|
|
9
|
-
|
|
10
|
-
export namespace FineUpdateFunction {
|
|
11
|
-
|
|
12
|
-
export type Parameters = {
|
|
13
|
-
teamId: Team.Id,
|
|
14
|
-
personId: Person.Id,
|
|
15
|
-
fine: Fine,
|
|
16
|
-
configuration: Configuration
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class FineUpdateFunction extends FirebaseFunction<FineUpdateFunction.Parameters, void> {
|
|
21
|
-
|
|
22
|
-
public parametersBuilder = new ObjectTypeBuilder<Flattable.Flatten<FineUpdateFunction.Parameters>, FineUpdateFunction.Parameters>({
|
|
23
|
-
teamId: Team.Id.builder,
|
|
24
|
-
personId: Person.Id.builder,
|
|
25
|
-
fine: Fine.builder,
|
|
26
|
-
configuration: Configuration.builder
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
public returnTypeBuilder = new ValueTypeBuilder<void>();
|
|
30
|
-
|
|
31
|
-
public async execute(parameters: FineUpdateFunction.Parameters): Promise<void> {
|
|
32
|
-
|
|
33
|
-
await checkAuthentication(this.userId, parameters.teamId, 'fine-manager');
|
|
34
|
-
|
|
35
|
-
const fineSnapshot = await Firestore.shared.fine(parameters.teamId, parameters.fine.id).snapshot();
|
|
36
|
-
if (!fineSnapshot.exists)
|
|
37
|
-
throw new FunctionsError('not-found', 'Fine not found');
|
|
38
|
-
|
|
39
|
-
await Firestore.shared.fine(parameters.teamId, parameters.fine.id).set(parameters.fine);
|
|
40
|
-
|
|
41
|
-
i18n.setLocale(parameters.configuration.locale);
|
|
42
|
-
if (parameters.fine.payedState !== fineSnapshot.data.payedState) {
|
|
43
|
-
let body: string;
|
|
44
|
-
if (parameters.fine.payedState === 'payed')
|
|
45
|
-
body = i18n.__('notification.fine.state-change.body-payed', parameters.fine.amount.formatted(parameters.configuration), parameters.fine.reason);
|
|
46
|
-
else
|
|
47
|
-
body = i18n.__('notification.fine.state-change.body-unpayed', parameters.fine.reason, parameters.fine.amount.formatted(parameters.configuration));
|
|
48
|
-
await pushNotification(parameters.teamId, parameters.personId, 'fine-state-change', {
|
|
49
|
-
title: i18n.__('notification.fine.state-change.title'),
|
|
50
|
-
body: body
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { FineTemplate, 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 FineTemplateAddFunction {
|
|
8
|
-
|
|
9
|
-
export type Parameters = {
|
|
10
|
-
teamId: Team.Id,
|
|
11
|
-
fineTemplate: FineTemplate
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class FineTemplateAddFunction extends FirebaseFunction<FineTemplateAddFunction.Parameters, void> {
|
|
16
|
-
|
|
17
|
-
public parametersBuilder = new ObjectTypeBuilder<Flattable.Flatten<FineTemplateAddFunction.Parameters>, FineTemplateAddFunction.Parameters>({
|
|
18
|
-
teamId: Team.Id.builder,
|
|
19
|
-
fineTemplate: FineTemplate.builder
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
public returnTypeBuilder = new ValueTypeBuilder<void>();
|
|
23
|
-
|
|
24
|
-
public async execute(parameters: FineTemplateAddFunction.Parameters): Promise<void> {
|
|
25
|
-
|
|
26
|
-
await checkAuthentication(this.userId, parameters.teamId, 'fineTemplate-manager');
|
|
27
|
-
|
|
28
|
-
const fineTemplateSnapshot = await Firestore.shared.fineTemplate(parameters.teamId, parameters.fineTemplate.id).snapshot();
|
|
29
|
-
if (fineTemplateSnapshot.exists)
|
|
30
|
-
throw new FunctionsError('already-exists', 'FineTemplate already exists');
|
|
31
|
-
|
|
32
|
-
await Firestore.shared.fineTemplate(parameters.teamId, parameters.fineTemplate.id).set(parameters.fineTemplate);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { FineTemplate, 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 FineTemplateDeleteFunction {
|
|
8
|
-
|
|
9
|
-
export type Parameters = {
|
|
10
|
-
teamId: Team.Id,
|
|
11
|
-
id: FineTemplate.Id
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class FineTemplateDeleteFunction extends FirebaseFunction<FineTemplateDeleteFunction.Parameters, void> {
|
|
16
|
-
|
|
17
|
-
public parametersBuilder = new ObjectTypeBuilder<Flattable.Flatten<FineTemplateDeleteFunction.Parameters>, FineTemplateDeleteFunction.Parameters>({
|
|
18
|
-
teamId: Team.Id.builder,
|
|
19
|
-
id: FineTemplate.Id.builder
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
public returnTypeBuilder = new ValueTypeBuilder<void>();
|
|
23
|
-
|
|
24
|
-
public async execute(parameters: FineTemplateDeleteFunction.Parameters): Promise<void> {
|
|
25
|
-
|
|
26
|
-
await checkAuthentication(this.userId, parameters.teamId, 'fineTemplate-manager');
|
|
27
|
-
|
|
28
|
-
const fineTemplateSnapshot = await Firestore.shared.fineTemplate(parameters.teamId, parameters.id).snapshot();
|
|
29
|
-
if (!fineTemplateSnapshot.exists)
|
|
30
|
-
throw new FunctionsError('not-found', 'FineTemplate not found');
|
|
31
|
-
|
|
32
|
-
await Firestore.shared.fineTemplate(parameters.teamId, parameters.id).remove();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { FineTemplate, 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 FineTemplateUpdateFunction {
|
|
8
|
-
|
|
9
|
-
export type Parameters = {
|
|
10
|
-
teamId: Team.Id,
|
|
11
|
-
fineTemplate: FineTemplate
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class FineTemplateUpdateFunction extends FirebaseFunction<FineTemplateUpdateFunction.Parameters, void> {
|
|
16
|
-
|
|
17
|
-
public parametersBuilder = new ObjectTypeBuilder<Flattable.Flatten<FineTemplateUpdateFunction.Parameters>, FineTemplateUpdateFunction.Parameters>({
|
|
18
|
-
teamId: Team.Id.builder,
|
|
19
|
-
fineTemplate: FineTemplate.builder
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
public returnTypeBuilder = new ValueTypeBuilder<void>();
|
|
23
|
-
|
|
24
|
-
public async execute(parameters: FineTemplateUpdateFunction.Parameters): Promise<void> {
|
|
25
|
-
|
|
26
|
-
await checkAuthentication(this.userId, parameters.teamId, 'fineTemplate-manager');
|
|
27
|
-
|
|
28
|
-
const fineTemplateSnapshot = await Firestore.shared.fineTemplate(parameters.teamId, parameters.fineTemplate.id).snapshot();
|
|
29
|
-
if (!fineTemplateSnapshot.exists)
|
|
30
|
-
throw new FunctionsError('not-found', 'FineTemplate not found');
|
|
31
|
-
|
|
32
|
-
await Firestore.shared.fineTemplate(parameters.teamId, parameters.fineTemplate.id).set(parameters.fineTemplate);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { Invitation } from '../../types';
|
|
3
|
-
import { checkAuthentication } from '../../checkAuthentication';
|
|
4
|
-
import { Firestore } from '../../Firestore';
|
|
5
|
-
|
|
6
|
-
export class InvitationInviteFunction extends FirebaseFunction<Invitation, Invitation.Id> {
|
|
7
|
-
|
|
8
|
-
public parametersBuilder = Invitation.builder;
|
|
9
|
-
|
|
10
|
-
public returnTypeBuilder = Invitation.Id.builder;
|
|
11
|
-
|
|
12
|
-
public async execute(invitation: Invitation): Promise<Invitation.Id> {
|
|
13
|
-
|
|
14
|
-
await checkAuthentication(this.userId, invitation.teamId, 'team-manager');
|
|
15
|
-
|
|
16
|
-
const personSnapshot = await Firestore.shared.person(invitation.teamId, invitation.personId).snapshot();
|
|
17
|
-
if (!personSnapshot.exists)
|
|
18
|
-
throw new FunctionsError('not-found', 'Person not found');
|
|
19
|
-
|
|
20
|
-
if (personSnapshot.data.signInProperties !== null)
|
|
21
|
-
throw new FunctionsError('already-exists', 'Person already has an account');
|
|
22
|
-
|
|
23
|
-
const invitationId = invitation.createId();
|
|
24
|
-
await Firestore.shared.invitation(invitationId).set(invitation);
|
|
25
|
-
|
|
26
|
-
return invitationId;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { Invitation, Person, PersonSignInProperties, Team, User } from '../../types';
|
|
3
|
-
import { Firestore } from '../../Firestore';
|
|
4
|
-
import { UtcDate } from '@stevenkellner/typescript-common-functionality';
|
|
5
|
-
|
|
6
|
-
export class InvitationRegisterFunction extends FirebaseFunction<Invitation.Id, User> {
|
|
7
|
-
|
|
8
|
-
public parametersBuilder = Invitation.Id.builder;
|
|
9
|
-
|
|
10
|
-
public returnTypeBuilder = User.builder;
|
|
11
|
-
|
|
12
|
-
public async execute(invitationId: Invitation.Id): Promise<User> {
|
|
13
|
-
|
|
14
|
-
if (this.userId === null)
|
|
15
|
-
throw new FunctionsError('unauthenticated', 'User not authenticated');
|
|
16
|
-
const userId = User.Id.builder.build(this.userId);
|
|
17
|
-
|
|
18
|
-
const invitationSnapshot = await Firestore.shared.invitation(invitationId).snapshot();
|
|
19
|
-
if (!invitationSnapshot.exists)
|
|
20
|
-
throw new FunctionsError('not-found', 'Invitation not found');
|
|
21
|
-
const invitation = Invitation.builder.build(invitationSnapshot.data);
|
|
22
|
-
|
|
23
|
-
const userSnapshot = await Firestore.shared.user(userId).snapshot();
|
|
24
|
-
let user = new User(userId);
|
|
25
|
-
if (userSnapshot.exists)
|
|
26
|
-
user = User.builder.build(userSnapshot.data);
|
|
27
|
-
|
|
28
|
-
if (user.teams.has(invitation.teamId))
|
|
29
|
-
throw new FunctionsError('already-exists', 'User already in team');
|
|
30
|
-
|
|
31
|
-
const teamSnapshot = await Firestore.shared.team(invitation.teamId).snapshot();
|
|
32
|
-
if (!teamSnapshot.exists)
|
|
33
|
-
throw new FunctionsError('not-found', 'Team not found');
|
|
34
|
-
const team = Team.builder.build(teamSnapshot.data);
|
|
35
|
-
|
|
36
|
-
const personSnapshot = await Firestore.shared.person(invitation.teamId, invitation.personId).snapshot();
|
|
37
|
-
if (!personSnapshot.exists)
|
|
38
|
-
throw new FunctionsError('not-found', 'Person not found');
|
|
39
|
-
const person = Person.builder.build(personSnapshot.data);
|
|
40
|
-
|
|
41
|
-
if (person.signInProperties !== null)
|
|
42
|
-
throw new FunctionsError('already-exists', 'Person already registered');
|
|
43
|
-
|
|
44
|
-
await Firestore.shared.invitation(invitationId).remove();
|
|
45
|
-
|
|
46
|
-
user.teams.set(invitation.teamId, new User.TeamProperties(team.name, invitation.personId));
|
|
47
|
-
await Firestore.shared.user(userId).set(user);
|
|
48
|
-
|
|
49
|
-
person.signInProperties = new PersonSignInProperties(userId, UtcDate.now);
|
|
50
|
-
await Firestore.shared.person(invitation.teamId, invitation.personId).set(person);
|
|
51
|
-
|
|
52
|
-
return user;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { Invitation } from '../../types';
|
|
3
|
-
import { checkAuthentication } from '../../checkAuthentication';
|
|
4
|
-
import { Firestore } from '../../Firestore';
|
|
5
|
-
import { ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
6
|
-
|
|
7
|
-
export class InvitationWithdrawFunction extends FirebaseFunction<Invitation, void> {
|
|
8
|
-
|
|
9
|
-
public parametersBuilder = Invitation.builder;
|
|
10
|
-
|
|
11
|
-
public returnTypeBuilder = new ValueTypeBuilder<void>();
|
|
12
|
-
|
|
13
|
-
public async execute(invitation: Invitation): Promise<void> {
|
|
14
|
-
|
|
15
|
-
await checkAuthentication(this.userId, invitation.teamId, 'team-manager');
|
|
16
|
-
|
|
17
|
-
const invitationId = invitation.createId();
|
|
18
|
-
const invitationSnapshot = await Firestore.shared.invitation(invitationId).snapshot();
|
|
19
|
-
if (!invitationSnapshot.exists)
|
|
20
|
-
throw new FunctionsError('not-found', 'Invitation not found');
|
|
21
|
-
|
|
22
|
-
await Firestore.shared.invitation(invitationId).remove();
|
|
23
|
-
}
|
|
24
|
-
}
|