@stevenkellner/team-conduct-api 1.0.32 → 1.0.34
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 +12 -3
- package/lib/src/Firestore.js +17 -8
- package/lib/src/FirestoreScheme.d.ts +3 -3
- package/lib/src/firebaseFunctionsContext.d.ts +6 -5
- package/lib/src/firebaseFunctionsContext.js +5 -4
- package/lib/src/functions/index.d.ts +4 -3
- package/lib/src/functions/index.js +4 -3
- package/lib/src/functions/invitation/getInvitation.d.ts +50 -0
- package/lib/src/functions/invitation/getInvitation.js +96 -0
- package/lib/src/functions/invitation/invite.d.ts +7 -0
- package/lib/src/functions/invitation/invite.js +25 -0
- package/lib/src/functions/invitation/register.d.ts +19 -0
- package/lib/src/functions/{userInvitation → invitation}/register.js +26 -19
- package/lib/src/functions/invitation/withdraw.d.ts +8 -0
- package/lib/src/functions/{userInvitation → invitation}/withdraw.js +6 -6
- package/lib/src/types/Invitation.d.ts +25 -0
- package/lib/src/types/Invitation.js +46 -0
- package/lib/src/types/index.d.ts +1 -1
- package/lib/src/types/index.js +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/Firestore.ts +22 -10
- package/src/FirestoreScheme.ts +3 -3
- package/src/firebaseFunctionsContext.ts +6 -5
- package/src/functions/index.ts +4 -3
- package/src/functions/invitation/getInvitation.ts +140 -0
- package/src/functions/invitation/invite.ts +32 -0
- package/src/functions/invitation/register.ts +69 -0
- package/src/functions/{userInvitation → invitation}/withdraw.ts +6 -6
- package/src/types/Invitation.ts +60 -0
- package/src/types/index.ts +1 -1
- package/lib/src/functions/userInvitation/invite.d.ts +0 -7
- package/lib/src/functions/userInvitation/invite.js +0 -23
- package/lib/src/functions/userInvitation/register.d.ts +0 -7
- package/lib/src/functions/userInvitation/withdraw.d.ts +0 -8
- package/lib/src/types/UserInvitation.d.ts +0 -25
- package/lib/src/types/UserInvitation.js +0 -42
- package/src/functions/userInvitation/invite.ts +0 -28
- package/src/functions/userInvitation/register.ts +0 -54
- package/src/types/UserInvitation.ts +0 -56
package/lib/src/Firestore.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FirestoreDocument } from '@stevenkellner/firebase-function';
|
|
1
|
+
import { FirestoreCollection, FirestoreDocument } from '@stevenkellner/firebase-function';
|
|
2
2
|
import { FirestoreScheme } from './FirestoreScheme';
|
|
3
|
-
import { Fine, FineTemplate,
|
|
3
|
+
import { Fine, FineTemplate, Invitation, Person, User, Team } from './types';
|
|
4
4
|
export declare class Firestore {
|
|
5
5
|
protected base: FirestoreScheme;
|
|
6
6
|
protected constructor();
|
|
@@ -8,8 +8,17 @@ export declare class Firestore {
|
|
|
8
8
|
static get shared(): Firestore;
|
|
9
9
|
team(id: Team.Id): FirestoreDocument<Team>;
|
|
10
10
|
user(id: User.Id): FirestoreDocument<User>;
|
|
11
|
-
|
|
11
|
+
invitation(id: Invitation.Id): FirestoreDocument<Invitation>;
|
|
12
|
+
persons(teamId: Team.Id): FirestoreCollection<{
|
|
13
|
+
[x: string]: FirestoreDocument<Person, never>;
|
|
14
|
+
}>;
|
|
12
15
|
person(teamId: Team.Id, id: Person.Id): FirestoreDocument<Person>;
|
|
16
|
+
fineTemplates(teamId: Team.Id): FirestoreCollection<{
|
|
17
|
+
[x: string]: FirestoreDocument<FineTemplate, never>;
|
|
18
|
+
}>;
|
|
13
19
|
fineTemplate(teamId: Team.Id, id: FineTemplate.Id): FirestoreDocument<FineTemplate>;
|
|
20
|
+
fines(teamId: Team.Id): FirestoreCollection<{
|
|
21
|
+
[x: string]: FirestoreDocument<Fine, never>;
|
|
22
|
+
}>;
|
|
14
23
|
fine(teamId: Team.Id, id: Fine.Id): FirestoreDocument<Fine>;
|
|
15
24
|
}
|
package/lib/src/Firestore.js
CHANGED
|
@@ -23,30 +23,39 @@ class Firestore {
|
|
|
23
23
|
.collection('users')
|
|
24
24
|
.document(id.value);
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
invitation(id) {
|
|
27
27
|
return this.base
|
|
28
|
-
.collection('
|
|
28
|
+
.collection('invitations')
|
|
29
29
|
.document(id.value);
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
persons(teamId) {
|
|
32
32
|
return this.base
|
|
33
33
|
.collection('teams')
|
|
34
34
|
.document(teamId.guidString)
|
|
35
|
-
.collection('persons')
|
|
35
|
+
.collection('persons');
|
|
36
|
+
}
|
|
37
|
+
person(teamId, id) {
|
|
38
|
+
return this.persons(teamId)
|
|
36
39
|
.document(id.guidString);
|
|
37
40
|
}
|
|
38
|
-
|
|
41
|
+
fineTemplates(teamId) {
|
|
39
42
|
return this.base
|
|
40
43
|
.collection('teams')
|
|
41
44
|
.document(teamId.guidString)
|
|
42
|
-
.collection('fineTemplates')
|
|
45
|
+
.collection('fineTemplates');
|
|
46
|
+
}
|
|
47
|
+
fineTemplate(teamId, id) {
|
|
48
|
+
return this.fineTemplates(teamId)
|
|
43
49
|
.document(id.guidString);
|
|
44
50
|
}
|
|
45
|
-
|
|
51
|
+
fines(teamId) {
|
|
46
52
|
return this.base
|
|
47
53
|
.collection('teams')
|
|
48
54
|
.document(teamId.guidString)
|
|
49
|
-
.collection('fines')
|
|
55
|
+
.collection('fines');
|
|
56
|
+
}
|
|
57
|
+
fine(teamId, id) {
|
|
58
|
+
return this.fines(teamId)
|
|
50
59
|
.document(id.guidString);
|
|
51
60
|
}
|
|
52
61
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { FirestoreCollection, FirestoreDocument } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { Fine, FineTemplate,
|
|
2
|
+
import { Fine, FineTemplate, Invitation, Person, Team, User } from './types';
|
|
3
3
|
export type FirestoreScheme = FirestoreDocument<never, {
|
|
4
4
|
users: FirestoreCollection<{
|
|
5
5
|
[UserId in string]: FirestoreDocument<User>;
|
|
6
6
|
}>;
|
|
7
|
-
|
|
8
|
-
[
|
|
7
|
+
invitations: FirestoreCollection<{
|
|
8
|
+
[InvitationId in string]: FirestoreDocument<Invitation>;
|
|
9
9
|
}>;
|
|
10
10
|
teams: FirestoreCollection<{
|
|
11
11
|
[TeamId in string]: FirestoreDocument<Team, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TeamNewFunction, UserKickoutFunction, UserRoleEditFunction, PaypalMeEditFunction, NotificationRegisterFunction, NotificationSubscribeFunction, PersonAddFunction, PersonDeleteFunction, PersonUpdateFunction, FineTemplateAddFunction, FineTemplateDeleteFunction, FineTemplateUpdateFunction, FineAddFunction, FineDeleteFunction, FineUpdateFunction } from './functions';
|
|
1
|
+
import { TeamNewFunction, UserKickoutFunction, UserRoleEditFunction, PaypalMeEditFunction, NotificationRegisterFunction, NotificationSubscribeFunction, InvitationGetInvitationFunction, InvitationRegisterFunction, PersonAddFunction, PersonDeleteFunction, PersonUpdateFunction, FineTemplateAddFunction, FineTemplateDeleteFunction, FineTemplateUpdateFunction, FineAddFunction, FineDeleteFunction, FineUpdateFunction } from './functions';
|
|
2
2
|
export declare const firebaseFunctionsContext: {
|
|
3
3
|
team: {
|
|
4
4
|
new: import("@stevenkellner/firebase-function").FirebaseFunctionContext<TeamNewFunction.Parameters, import("./types").User>;
|
|
@@ -15,10 +15,11 @@ export declare const firebaseFunctionsContext: {
|
|
|
15
15
|
register: import("@stevenkellner/firebase-function").FirebaseFunctionContext<NotificationRegisterFunction.Parameters, void>;
|
|
16
16
|
subscribe: import("@stevenkellner/firebase-function").FirebaseFunctionContext<NotificationSubscribeFunction.Parameters, void>;
|
|
17
17
|
};
|
|
18
|
-
|
|
19
|
-
invite: import("@stevenkellner/firebase-function").FirebaseFunctionContext<import("./types").
|
|
20
|
-
withdraw: import("@stevenkellner/firebase-function").FirebaseFunctionContext<import("./types").
|
|
21
|
-
|
|
18
|
+
invitation: {
|
|
19
|
+
invite: import("@stevenkellner/firebase-function").FirebaseFunctionContext<import("./types").Invitation, import("./types").Invitation.Id>;
|
|
20
|
+
withdraw: import("@stevenkellner/firebase-function").FirebaseFunctionContext<import("./types").Invitation, void>;
|
|
21
|
+
getInvitation: import("@stevenkellner/firebase-function").FirebaseFunctionContext<import("./types").Invitation.Id, InvitationGetInvitationFunction.ReturnType>;
|
|
22
|
+
register: import("@stevenkellner/firebase-function").FirebaseFunctionContext<InvitationRegisterFunction.Parameters, import("./types").User>;
|
|
22
23
|
};
|
|
23
24
|
person: {
|
|
24
25
|
add: import("@stevenkellner/firebase-function").FirebaseFunctionContext<PersonAddFunction.Parameters, void>;
|
|
@@ -19,10 +19,11 @@ exports.firebaseFunctionsContext = firebase_function_1.FirebaseFunctionsContext.
|
|
|
19
19
|
register: builder.function(functions_1.NotificationRegisterFunction),
|
|
20
20
|
subscribe: builder.function(functions_1.NotificationSubscribeFunction)
|
|
21
21
|
},
|
|
22
|
-
|
|
23
|
-
invite: builder.function(functions_1.
|
|
24
|
-
withdraw: builder.function(functions_1.
|
|
25
|
-
|
|
22
|
+
invitation: {
|
|
23
|
+
invite: builder.function(functions_1.InvitationInviteFunction),
|
|
24
|
+
withdraw: builder.function(functions_1.InvitationWithdrawFunction),
|
|
25
|
+
getInvitation: builder.function(functions_1.InvitationGetInvitationFunction),
|
|
26
|
+
register: builder.function(functions_1.InvitationRegisterFunction)
|
|
26
27
|
},
|
|
27
28
|
person: {
|
|
28
29
|
add: builder.function(functions_1.PersonAddFunction),
|
|
@@ -5,9 +5,10 @@ export * from './user/kickout';
|
|
|
5
5
|
export * from './paypalMe/edit';
|
|
6
6
|
export * from './notification/register';
|
|
7
7
|
export * from './notification/subscribe';
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
8
|
+
export * from './invitation/invite';
|
|
9
|
+
export * from './invitation/withdraw';
|
|
10
|
+
export * from './invitation/getInvitation';
|
|
11
|
+
export * from './invitation/register';
|
|
11
12
|
export * from './person/add';
|
|
12
13
|
export * from './person/update';
|
|
13
14
|
export * from './person/delete';
|
|
@@ -21,9 +21,10 @@ __exportStar(require("./user/kickout"), exports);
|
|
|
21
21
|
__exportStar(require("./paypalMe/edit"), exports);
|
|
22
22
|
__exportStar(require("./notification/register"), exports);
|
|
23
23
|
__exportStar(require("./notification/subscribe"), exports);
|
|
24
|
-
__exportStar(require("./
|
|
25
|
-
__exportStar(require("./
|
|
26
|
-
__exportStar(require("./
|
|
24
|
+
__exportStar(require("./invitation/invite"), exports);
|
|
25
|
+
__exportStar(require("./invitation/withdraw"), exports);
|
|
26
|
+
__exportStar(require("./invitation/getInvitation"), exports);
|
|
27
|
+
__exportStar(require("./invitation/register"), exports);
|
|
27
28
|
__exportStar(require("./person/add"), exports);
|
|
28
29
|
__exportStar(require("./person/update"), exports);
|
|
29
30
|
__exportStar(require("./person/delete"), exports);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { FirebaseFunction } from '@stevenkellner/firebase-function';
|
|
2
|
+
import { Invitation, Person, PersonPrivateProperties, Team } from '../../types';
|
|
3
|
+
import { Flattable, ITypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
+
export declare class InvitationGetInvitationFunction extends FirebaseFunction<Invitation.Id, InvitationGetInvitationFunction.ReturnType> {
|
|
5
|
+
parametersBuilder: import("@stevenkellner/typescript-common-functionality").Tagged.TypeBuilder<string, "invitation">;
|
|
6
|
+
returnTypeBuilder: InvitationGetInvitationFunction.ReturnType.TypeBuilder;
|
|
7
|
+
execute(invitationId: Invitation.Id): Promise<InvitationGetInvitationFunction.ReturnType>;
|
|
8
|
+
}
|
|
9
|
+
export declare namespace InvitationGetInvitationFunction {
|
|
10
|
+
type PersonIdOrPersons = {
|
|
11
|
+
personId: Person.Id;
|
|
12
|
+
} | {
|
|
13
|
+
persons: {
|
|
14
|
+
id: Person.Id;
|
|
15
|
+
properties: PersonPrivateProperties;
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
namespace PersonIdOrPersons {
|
|
19
|
+
type Flatten = {
|
|
20
|
+
personId: Person.Id.Flatten;
|
|
21
|
+
} | {
|
|
22
|
+
persons: {
|
|
23
|
+
id: Person.Id.Flatten;
|
|
24
|
+
properties: PersonPrivateProperties.Flatten;
|
|
25
|
+
}[];
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
class ReturnType implements Flattable<ReturnType.Flatten> {
|
|
29
|
+
teamId: Team.Id;
|
|
30
|
+
private personIdOrPersons;
|
|
31
|
+
private constructor();
|
|
32
|
+
static from(teamId: Team.Id, personId: Person.Id): ReturnType;
|
|
33
|
+
static from(teamId: Team.Id, persons: {
|
|
34
|
+
id: Person.Id;
|
|
35
|
+
properties: PersonPrivateProperties;
|
|
36
|
+
}[]): ReturnType;
|
|
37
|
+
get personId(): Person.Id | null;
|
|
38
|
+
get persons(): Person.Id[] | null;
|
|
39
|
+
get flatten(): ReturnType.Flatten;
|
|
40
|
+
}
|
|
41
|
+
namespace ReturnType {
|
|
42
|
+
type Flatten = {
|
|
43
|
+
teamId: Team.Id.Flatten;
|
|
44
|
+
} & InvitationGetInvitationFunction.PersonIdOrPersons.Flatten;
|
|
45
|
+
class TypeBuilder implements ITypeBuilder<Flatten, ReturnType> {
|
|
46
|
+
build(value: Flatten): ReturnType;
|
|
47
|
+
}
|
|
48
|
+
const builder: TypeBuilder;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvitationGetInvitationFunction = void 0;
|
|
4
|
+
const firebase_function_1 = require("@stevenkellner/firebase-function");
|
|
5
|
+
const types_1 = require("../../types");
|
|
6
|
+
const Firestore_1 = require("../../Firestore");
|
|
7
|
+
const typescript_common_functionality_1 = require("@stevenkellner/typescript-common-functionality");
|
|
8
|
+
class InvitationGetInvitationFunction extends firebase_function_1.FirebaseFunction {
|
|
9
|
+
parametersBuilder = types_1.Invitation.Id.builder;
|
|
10
|
+
returnTypeBuilder = InvitationGetInvitationFunction.ReturnType.builder;
|
|
11
|
+
async execute(invitationId) {
|
|
12
|
+
if (this.userId === null)
|
|
13
|
+
throw new firebase_function_1.FunctionsError('unauthenticated', 'User not authenticated');
|
|
14
|
+
const invitationSnapshot = await Firestore_1.Firestore.shared.invitation(invitationId).snapshot();
|
|
15
|
+
if (!invitationSnapshot.exists)
|
|
16
|
+
throw new firebase_function_1.FunctionsError('not-found', 'Invitation not found');
|
|
17
|
+
const invitation = types_1.Invitation.builder.build(invitationSnapshot.data);
|
|
18
|
+
if (invitation.personId !== null)
|
|
19
|
+
return InvitationGetInvitationFunction.ReturnType.from(invitation.teamId, invitation.personId);
|
|
20
|
+
const personSnapshots = await Firestore_1.Firestore.shared.persons(invitation.teamId).documentSnapshots();
|
|
21
|
+
const persons = (0, typescript_common_functionality_1.compactMap)(personSnapshots, personSnapshot => {
|
|
22
|
+
if (!personSnapshot.exists)
|
|
23
|
+
return null;
|
|
24
|
+
const person = types_1.Person.builder.build(personSnapshot.data);
|
|
25
|
+
if (person.signInProperties !== null)
|
|
26
|
+
return null;
|
|
27
|
+
return {
|
|
28
|
+
id: person.id,
|
|
29
|
+
properties: person.properties
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
return InvitationGetInvitationFunction.ReturnType.from(invitation.teamId, persons);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.InvitationGetInvitationFunction = InvitationGetInvitationFunction;
|
|
36
|
+
(function (InvitationGetInvitationFunction) {
|
|
37
|
+
class ReturnType {
|
|
38
|
+
teamId;
|
|
39
|
+
personIdOrPersons;
|
|
40
|
+
constructor(teamId, personIdOrPersons) {
|
|
41
|
+
this.teamId = teamId;
|
|
42
|
+
this.personIdOrPersons = personIdOrPersons;
|
|
43
|
+
}
|
|
44
|
+
static from(teamId, personIdOrPersons) {
|
|
45
|
+
if (Array.isArray(personIdOrPersons)) {
|
|
46
|
+
return new ReturnType(teamId, {
|
|
47
|
+
persons: personIdOrPersons
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return new ReturnType(teamId, {
|
|
51
|
+
personId: personIdOrPersons
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
get personId() {
|
|
55
|
+
if (!('personId' in this.personIdOrPersons))
|
|
56
|
+
return null;
|
|
57
|
+
return this.personIdOrPersons.personId;
|
|
58
|
+
}
|
|
59
|
+
get persons() {
|
|
60
|
+
if (!('persons' in this.personIdOrPersons))
|
|
61
|
+
return null;
|
|
62
|
+
return this.personIdOrPersons.persons.map(person => person.id);
|
|
63
|
+
}
|
|
64
|
+
get flatten() {
|
|
65
|
+
if ('personId' in this.personIdOrPersons) {
|
|
66
|
+
return {
|
|
67
|
+
teamId: this.teamId.flatten,
|
|
68
|
+
personId: this.personIdOrPersons.personId.flatten
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
teamId: this.teamId.flatten,
|
|
73
|
+
persons: this.personIdOrPersons.persons.map(person => ({
|
|
74
|
+
id: person.id.flatten,
|
|
75
|
+
properties: person.properties.flatten
|
|
76
|
+
}))
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
InvitationGetInvitationFunction.ReturnType = ReturnType;
|
|
81
|
+
(function (ReturnType) {
|
|
82
|
+
class TypeBuilder {
|
|
83
|
+
build(value) {
|
|
84
|
+
if ('personId' in value) {
|
|
85
|
+
return ReturnType.from(types_1.Team.Id.builder.build(value.teamId), types_1.Person.Id.builder.build(value.personId));
|
|
86
|
+
}
|
|
87
|
+
return ReturnType.from(types_1.Team.Id.builder.build(value.teamId), value.persons.map(person => ({
|
|
88
|
+
id: types_1.Person.Id.builder.build(person.id),
|
|
89
|
+
properties: types_1.PersonPrivateProperties.builder.build(person.properties)
|
|
90
|
+
})));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
ReturnType.TypeBuilder = TypeBuilder;
|
|
94
|
+
ReturnType.builder = new TypeBuilder();
|
|
95
|
+
})(ReturnType = InvitationGetInvitationFunction.ReturnType || (InvitationGetInvitationFunction.ReturnType = {}));
|
|
96
|
+
})(InvitationGetInvitationFunction || (exports.InvitationGetInvitationFunction = InvitationGetInvitationFunction = {}));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FirebaseFunction } from '@stevenkellner/firebase-function';
|
|
2
|
+
import { Invitation } from '../../types';
|
|
3
|
+
export declare class InvitationInviteFunction extends FirebaseFunction<Invitation, Invitation.Id> {
|
|
4
|
+
parametersBuilder: Invitation.TypeBuilder;
|
|
5
|
+
returnTypeBuilder: import("@stevenkellner/typescript-common-functionality").Tagged.TypeBuilder<string, "invitation">;
|
|
6
|
+
execute(invitation: Invitation): Promise<Invitation.Id>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvitationInviteFunction = void 0;
|
|
4
|
+
const firebase_function_1 = require("@stevenkellner/firebase-function");
|
|
5
|
+
const types_1 = require("../../types");
|
|
6
|
+
const checkAuthentication_1 = require("../../checkAuthentication");
|
|
7
|
+
const Firestore_1 = require("../../Firestore");
|
|
8
|
+
class InvitationInviteFunction extends firebase_function_1.FirebaseFunction {
|
|
9
|
+
parametersBuilder = types_1.Invitation.builder;
|
|
10
|
+
returnTypeBuilder = types_1.Invitation.Id.builder;
|
|
11
|
+
async execute(invitation) {
|
|
12
|
+
await (0, checkAuthentication_1.checkAuthentication)(this.userId, invitation.teamId, 'team-manager');
|
|
13
|
+
if (invitation.personId !== null) {
|
|
14
|
+
const personSnapshot = await Firestore_1.Firestore.shared.person(invitation.teamId, invitation.personId).snapshot();
|
|
15
|
+
if (!personSnapshot.exists)
|
|
16
|
+
throw new firebase_function_1.FunctionsError('not-found', 'Person not found');
|
|
17
|
+
if (personSnapshot.data.signInProperties !== null)
|
|
18
|
+
throw new firebase_function_1.FunctionsError('already-exists', 'Person already has an account');
|
|
19
|
+
}
|
|
20
|
+
const invitationId = invitation.createId();
|
|
21
|
+
await Firestore_1.Firestore.shared.invitation(invitationId).set(invitation);
|
|
22
|
+
return invitationId;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.InvitationInviteFunction = InvitationInviteFunction;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FirebaseFunction } from '@stevenkellner/firebase-function';
|
|
2
|
+
import { Person, Team, User } from '../../types';
|
|
3
|
+
import { ObjectTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
+
export declare namespace InvitationRegisterFunction {
|
|
5
|
+
type Parameters = {
|
|
6
|
+
teamId: Team.Id;
|
|
7
|
+
personId: Person.Id;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export declare class InvitationRegisterFunction extends FirebaseFunction<InvitationRegisterFunction.Parameters, User> {
|
|
11
|
+
parametersBuilder: ObjectTypeBuilder<{
|
|
12
|
+
teamId: string;
|
|
13
|
+
personId: string;
|
|
14
|
+
}, InvitationRegisterFunction.Parameters>;
|
|
15
|
+
returnTypeBuilder: User.TypeBuilder;
|
|
16
|
+
execute(parameters: InvitationRegisterFunction.Parameters): Promise<User>;
|
|
17
|
+
private getUser;
|
|
18
|
+
private removeUserInvitation;
|
|
19
|
+
}
|
|
@@ -1,43 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.InvitationRegisterFunction = void 0;
|
|
4
4
|
const firebase_function_1 = require("@stevenkellner/firebase-function");
|
|
5
5
|
const types_1 = require("../../types");
|
|
6
6
|
const Firestore_1 = require("../../Firestore");
|
|
7
7
|
const typescript_common_functionality_1 = require("@stevenkellner/typescript-common-functionality");
|
|
8
|
-
class
|
|
9
|
-
parametersBuilder =
|
|
8
|
+
class InvitationRegisterFunction extends firebase_function_1.FirebaseFunction {
|
|
9
|
+
parametersBuilder = new typescript_common_functionality_1.ObjectTypeBuilder({
|
|
10
|
+
teamId: types_1.Team.Id.builder,
|
|
11
|
+
personId: types_1.Person.Id.builder
|
|
12
|
+
});
|
|
10
13
|
returnTypeBuilder = types_1.User.builder;
|
|
11
|
-
async execute(
|
|
14
|
+
async execute(parameters) {
|
|
12
15
|
if (this.userId === null)
|
|
13
16
|
throw new firebase_function_1.FunctionsError('unauthenticated', 'User not authenticated');
|
|
14
17
|
const userId = types_1.User.Id.builder.build(this.userId);
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
17
|
-
throw new firebase_function_1.FunctionsError('not-found', 'Invitation not found');
|
|
18
|
-
const invitation = types_1.UserInvitation.builder.build(invitationSnapshot.data);
|
|
19
|
-
const userSnapshot = await Firestore_1.Firestore.shared.user(userId).snapshot();
|
|
20
|
-
let user = new types_1.User(userId);
|
|
21
|
-
if (userSnapshot.exists)
|
|
22
|
-
user = types_1.User.builder.build(userSnapshot.data);
|
|
23
|
-
if (user.teams.has(invitation.teamId))
|
|
18
|
+
const user = await this.getUser(userId);
|
|
19
|
+
if (user.teams.has(parameters.teamId))
|
|
24
20
|
throw new firebase_function_1.FunctionsError('already-exists', 'User already in team');
|
|
25
|
-
const teamSnapshot = await Firestore_1.Firestore.shared.team(
|
|
21
|
+
const teamSnapshot = await Firestore_1.Firestore.shared.team(parameters.teamId).snapshot();
|
|
26
22
|
if (!teamSnapshot.exists)
|
|
27
23
|
throw new firebase_function_1.FunctionsError('not-found', 'Team not found');
|
|
28
24
|
const team = types_1.Team.builder.build(teamSnapshot.data);
|
|
29
|
-
const personSnapshot = await Firestore_1.Firestore.shared.person(
|
|
25
|
+
const personSnapshot = await Firestore_1.Firestore.shared.person(parameters.teamId, parameters.personId).snapshot();
|
|
30
26
|
if (!personSnapshot.exists)
|
|
31
27
|
throw new firebase_function_1.FunctionsError('not-found', 'Person not found');
|
|
32
28
|
const person = types_1.Person.builder.build(personSnapshot.data);
|
|
33
29
|
if (person.signInProperties !== null)
|
|
34
30
|
throw new firebase_function_1.FunctionsError('already-exists', 'Person already registered');
|
|
35
|
-
await
|
|
36
|
-
user.teams.set(
|
|
31
|
+
await this.removeUserInvitation(parameters.teamId, parameters.personId);
|
|
32
|
+
user.teams.set(parameters.teamId, new types_1.User.TeamProperties(team.name, parameters.personId));
|
|
37
33
|
await Firestore_1.Firestore.shared.user(userId).set(user);
|
|
38
34
|
person.signInProperties = new types_1.PersonSignInProperties(userId, typescript_common_functionality_1.UtcDate.now);
|
|
39
|
-
await Firestore_1.Firestore.shared.person(
|
|
35
|
+
await Firestore_1.Firestore.shared.person(parameters.teamId, parameters.personId).set(person);
|
|
40
36
|
return user;
|
|
41
37
|
}
|
|
38
|
+
async getUser(userId) {
|
|
39
|
+
const userSnapshot = await Firestore_1.Firestore.shared.user(userId).snapshot();
|
|
40
|
+
if (userSnapshot.exists)
|
|
41
|
+
return types_1.User.builder.build(userSnapshot.data);
|
|
42
|
+
return new types_1.User(userId);
|
|
43
|
+
}
|
|
44
|
+
async removeUserInvitation(teamId, personId) {
|
|
45
|
+
const invitation = new types_1.Invitation(teamId, personId);
|
|
46
|
+
const invitationId = invitation.createId();
|
|
47
|
+
await Firestore_1.Firestore.shared.invitation(invitationId).remove();
|
|
48
|
+
}
|
|
42
49
|
}
|
|
43
|
-
exports.
|
|
50
|
+
exports.InvitationRegisterFunction = InvitationRegisterFunction;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FirebaseFunction } from '@stevenkellner/firebase-function';
|
|
2
|
+
import { Invitation } from '../../types';
|
|
3
|
+
import { ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
+
export declare class InvitationWithdrawFunction extends FirebaseFunction<Invitation, void> {
|
|
5
|
+
parametersBuilder: Invitation.TypeBuilder;
|
|
6
|
+
returnTypeBuilder: ValueTypeBuilder<void>;
|
|
7
|
+
execute(invitation: Invitation): Promise<void>;
|
|
8
|
+
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.InvitationWithdrawFunction = void 0;
|
|
4
4
|
const firebase_function_1 = require("@stevenkellner/firebase-function");
|
|
5
5
|
const types_1 = require("../../types");
|
|
6
6
|
const checkAuthentication_1 = require("../../checkAuthentication");
|
|
7
7
|
const Firestore_1 = require("../../Firestore");
|
|
8
8
|
const typescript_common_functionality_1 = require("@stevenkellner/typescript-common-functionality");
|
|
9
|
-
class
|
|
10
|
-
parametersBuilder = types_1.
|
|
9
|
+
class InvitationWithdrawFunction extends firebase_function_1.FirebaseFunction {
|
|
10
|
+
parametersBuilder = types_1.Invitation.builder;
|
|
11
11
|
returnTypeBuilder = new typescript_common_functionality_1.ValueTypeBuilder();
|
|
12
12
|
async execute(invitation) {
|
|
13
13
|
await (0, checkAuthentication_1.checkAuthentication)(this.userId, invitation.teamId, 'team-manager');
|
|
14
14
|
const invitationId = invitation.createId();
|
|
15
|
-
const invitationSnapshot = await Firestore_1.Firestore.shared.
|
|
15
|
+
const invitationSnapshot = await Firestore_1.Firestore.shared.invitation(invitationId).snapshot();
|
|
16
16
|
if (!invitationSnapshot.exists)
|
|
17
17
|
throw new firebase_function_1.FunctionsError('not-found', 'Invitation not found');
|
|
18
|
-
await Firestore_1.Firestore.shared.
|
|
18
|
+
await Firestore_1.Firestore.shared.invitation(invitationId).remove();
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
exports.
|
|
21
|
+
exports.InvitationWithdrawFunction = InvitationWithdrawFunction;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Flattable, ITypeBuilder, Tagged } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
+
import { Team } from './Team';
|
|
3
|
+
import { Person } from './Person';
|
|
4
|
+
export declare class Invitation implements Flattable<Invitation.Flatten> {
|
|
5
|
+
teamId: Team.Id;
|
|
6
|
+
personId: Person.Id | null;
|
|
7
|
+
constructor(teamId: Team.Id, personId: Person.Id | null);
|
|
8
|
+
createId(): Invitation.Id;
|
|
9
|
+
get flatten(): Invitation.Flatten;
|
|
10
|
+
}
|
|
11
|
+
export declare namespace Invitation {
|
|
12
|
+
type Id = Tagged<string, 'invitation'>;
|
|
13
|
+
namespace Id {
|
|
14
|
+
type Flatten = string;
|
|
15
|
+
const builder: Tagged.TypeBuilder<string, "invitation">;
|
|
16
|
+
}
|
|
17
|
+
type Flatten = {
|
|
18
|
+
teamId: Team.Id.Flatten;
|
|
19
|
+
personId: Person.Id.Flatten | null;
|
|
20
|
+
};
|
|
21
|
+
class TypeBuilder implements ITypeBuilder<Flatten, Invitation> {
|
|
22
|
+
build(value: Flatten): Invitation;
|
|
23
|
+
}
|
|
24
|
+
const builder: TypeBuilder;
|
|
25
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Invitation = void 0;
|
|
4
|
+
const typescript_common_functionality_1 = require("@stevenkellner/typescript-common-functionality");
|
|
5
|
+
const Team_1 = require("./Team");
|
|
6
|
+
const Person_1 = require("./Person");
|
|
7
|
+
class Invitation {
|
|
8
|
+
teamId;
|
|
9
|
+
personId;
|
|
10
|
+
constructor(teamId, personId) {
|
|
11
|
+
this.teamId = teamId;
|
|
12
|
+
this.personId = personId;
|
|
13
|
+
}
|
|
14
|
+
createId() {
|
|
15
|
+
const hasher = new typescript_common_functionality_1.Sha512();
|
|
16
|
+
const teamIdBytes = typescript_common_functionality_1.BytesCoder.fromUtf8(this.teamId.guidString);
|
|
17
|
+
let invitationBytes = teamIdBytes;
|
|
18
|
+
if (this.personId !== null) {
|
|
19
|
+
const personIdBytes = typescript_common_functionality_1.BytesCoder.fromUtf8(this.personId.guidString);
|
|
20
|
+
invitationBytes = new Uint8Array([...teamIdBytes, ...personIdBytes]);
|
|
21
|
+
}
|
|
22
|
+
const hashedInvitationBytes = hasher.hash(invitationBytes);
|
|
23
|
+
const rawId = typescript_common_functionality_1.BytesCoder.toHex(hashedInvitationBytes).slice(0, 12);
|
|
24
|
+
return new typescript_common_functionality_1.Tagged(rawId, 'invitation');
|
|
25
|
+
}
|
|
26
|
+
get flatten() {
|
|
27
|
+
return {
|
|
28
|
+
teamId: this.teamId.flatten,
|
|
29
|
+
personId: this.personId !== null ? this.personId.flatten : null
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.Invitation = Invitation;
|
|
34
|
+
(function (Invitation) {
|
|
35
|
+
let Id;
|
|
36
|
+
(function (Id) {
|
|
37
|
+
Id.builder = typescript_common_functionality_1.Tagged.builder('invitation', new typescript_common_functionality_1.ValueTypeBuilder());
|
|
38
|
+
})(Id = Invitation.Id || (Invitation.Id = {}));
|
|
39
|
+
class TypeBuilder {
|
|
40
|
+
build(value) {
|
|
41
|
+
return new Invitation(Team_1.Team.Id.builder.build(value.teamId), new typescript_common_functionality_1.OptionalTypeBuilder(Person_1.Person.Id.builder).build(value.personId));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
Invitation.TypeBuilder = TypeBuilder;
|
|
45
|
+
Invitation.builder = new TypeBuilder();
|
|
46
|
+
})(Invitation || (exports.Invitation = Invitation = {}));
|
package/lib/src/types/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export * from './Fine';
|
|
|
3
3
|
export * from './FineAmount';
|
|
4
4
|
export * from './FineTemplate';
|
|
5
5
|
export * from './FineTemplateRepetition';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './Invitation';
|
|
7
7
|
export * from './Localization';
|
|
8
8
|
export * from './MoneyAmount';
|
|
9
9
|
export * from './NotificationProperties';
|
package/lib/src/types/index.js
CHANGED
|
@@ -19,7 +19,7 @@ __exportStar(require("./Fine"), exports);
|
|
|
19
19
|
__exportStar(require("./FineAmount"), exports);
|
|
20
20
|
__exportStar(require("./FineTemplate"), exports);
|
|
21
21
|
__exportStar(require("./FineTemplateRepetition"), exports);
|
|
22
|
-
__exportStar(require("./
|
|
22
|
+
__exportStar(require("./Invitation"), exports);
|
|
23
23
|
__exportStar(require("./Localization"), exports);
|
|
24
24
|
__exportStar(require("./MoneyAmount"), exports);
|
|
25
25
|
__exportStar(require("./NotificationProperties"), exports);
|
package/lib/tsconfig.tsbuildinfo
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../index.ts","../src/Firestore.ts","../src/FirestoreScheme.ts","../src/checkAuthentication.ts","../src/firebaseFunctionsContext.ts","../src/index.ts","../src/pushNotification.ts","../src/firebase/FirebaseConfiguration.ts","../src/firebase/Messaging.ts","../src/firebase/index.ts","../src/functions/index.ts","../src/functions/fine/add.ts","../src/functions/fine/delete.ts","../src/functions/fine/update.ts","../src/functions/fineTemplate/add.ts","../src/functions/fineTemplate/delete.ts","../src/functions/fineTemplate/update.ts","../src/functions/
|
|
1
|
+
{"root":["../index.ts","../src/Firestore.ts","../src/FirestoreScheme.ts","../src/checkAuthentication.ts","../src/firebaseFunctionsContext.ts","../src/index.ts","../src/pushNotification.ts","../src/firebase/FirebaseConfiguration.ts","../src/firebase/Messaging.ts","../src/firebase/index.ts","../src/functions/index.ts","../src/functions/fine/add.ts","../src/functions/fine/delete.ts","../src/functions/fine/update.ts","../src/functions/fineTemplate/add.ts","../src/functions/fineTemplate/delete.ts","../src/functions/fineTemplate/update.ts","../src/functions/invitation/getInvitation.ts","../src/functions/invitation/invite.ts","../src/functions/invitation/register.ts","../src/functions/invitation/withdraw.ts","../src/functions/notification/register.ts","../src/functions/notification/subscribe.ts","../src/functions/paypalMe/edit.ts","../src/functions/person/add.ts","../src/functions/person/delete.ts","../src/functions/person/update.ts","../src/functions/team/new.ts","../src/functions/user/kickout.ts","../src/functions/user/login.ts","../src/functions/user/roleEdit.ts","../src/locales/de.ts","../src/locales/en.ts","../src/types/Configuration.ts","../src/types/Fine.ts","../src/types/FineAmount.ts","../src/types/FineTemplate.ts","../src/types/FineTemplateRepetition.ts","../src/types/Invitation.ts","../src/types/Localization.ts","../src/types/MoneyAmount.ts","../src/types/NotificationProperties.ts","../src/types/PayedState.ts","../src/types/Person.ts","../src/types/PersonPrivateProperties.ts","../src/types/PersonSignInProperties.ts","../src/types/Pluralization.ts","../src/types/Team.ts","../src/types/User.ts","../src/types/UserRole.ts","../src/types/index.ts","../test/localization-utils.ts","../test/localization.de.test.ts","../test/localization.en.test.ts"],"version":"5.8.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stevenkellner/team-conduct-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.34",
|
|
4
4
|
"description": "Firebase API for Team Conduct",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Steven Kellner",
|
|
@@ -22,18 +22,18 @@
|
|
|
22
22
|
"release": "npm run rebuild && npm run lint && npm version patch && git push --follow-tags"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@stevenkellner/firebase-function": "^1.4.
|
|
25
|
+
"@stevenkellner/firebase-function": "^1.4.141",
|
|
26
26
|
"@stevenkellner/typescript-common-functionality": "^1.0.61"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@assertive-ts/core": "^2.1.0",
|
|
30
30
|
"@eslint/compat": "^1.3.1",
|
|
31
31
|
"@eslint/eslintrc": "^3.3.1",
|
|
32
|
-
"@eslint/js": "^9.
|
|
32
|
+
"@eslint/js": "^9.30.0",
|
|
33
33
|
"@types/mocha": "^10.0.10",
|
|
34
34
|
"@typescript-eslint/eslint-plugin": "^8.35.0",
|
|
35
35
|
"@typescript-eslint/parser": "^8.35.0",
|
|
36
|
-
"eslint": "^9.
|
|
36
|
+
"eslint": "^9.30.0",
|
|
37
37
|
"eslint-config-google": "^0.14.0",
|
|
38
38
|
"eslint-plugin-import": "^2.32.0",
|
|
39
39
|
"mocha": "^11.7.1",
|