-
-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathcreateFakeTestimony.ts
More file actions
105 lines (84 loc) · 2.51 KB
/
createFakeTestimony.ts
File metadata and controls
105 lines (84 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import * as functions from "firebase-functions/v1"
import { checkAdmin, checkAdminv2, checkAuth, checkAuthv2 } from "../common"
import { auth, db } from "../firebase"
import { Testimony } from "../testimony/types"
import { Timestamp } from "../firebase"
import { onCall, CallableRequest } from "firebase-functions/v2/https"
// for populating admin module for testing & demonstration--alert--no auth checked here.
//@TODO: remove
export const createFakeTestimony = functions.https.onCall(
async (data, context) => {
console.log("running fake testimony")
checkAuth(context, false)
checkAdmin(context)
const { uid, fullName, email } = data
const author = {
uid,
fullName,
email,
password: "password",
public: true,
role: "user"
}
await auth.createUser({ uid })
await db.doc(`profiles/${uid}`).set(author)
const id = `${uid}ttmny`
const testimony: Testimony = {
id,
authorUid: author.uid,
authorDisplayName: "none",
authorRole: "user",
billTitle: "An act",
version: 2,
billId: "H1002",
publishedAt: Timestamp.now(),
court: 192,
position: "oppose",
fullName: fullName,
content: fullName + " " + fullName + " " + fullName + " " + fullName,
public: true,
updatedAt: Timestamp.now()
}
const testRef = db.doc(`users/${uid}/publishedTestimony/${id}`)
await testRef.set(testimony)
return { uid: uid, tid: id }
}
)
export const createFakeTestimonyv2 = onCall(
async (request: CallableRequest) => {
console.log("running fake testimony")
checkAuthv2(request, false)
checkAdminv2(request)
const { uid, fullName, email } = request.data
const author = {
uid,
fullName,
email,
password: "password",
public: true,
role: "user"
}
await auth.createUser({ uid })
await db.doc(`profiles/${uid}`).set(author)
const id = `${uid}ttmny`
const testimony: Testimony = {
id,
authorUid: author.uid,
authorDisplayName: "none",
authorRole: "user",
billTitle: "An act",
version: 2,
billId: "H1002",
publishedAt: Timestamp.now(),
court: 192,
position: "oppose",
fullName: fullName,
content: fullName + " " + fullName + " " + fullName + " " + fullName,
public: true,
updatedAt: Timestamp.now()
}
const testRef = db.doc(`users/${uid}/publishedTestimony/${id}`)
await testRef.set(testimony)
return { uid: uid, tid: id }
}
)