-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
328 lines (269 loc) · 7.56 KB
/
test.js
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
const { prisma } = require('./generated/prisma');
var _ = require('lodash');
const mail = require('./src/utils/nodemailer')
var fs = require('fs')
const randomWords = require('./src/utils/random-words')
const test = {
dates: ["2018-12-19"]
}
console.log(_.update(test, 'dates', function(a) { return { set: a }}))
// mail.sendEmail("hello-old=friend", "SLdkvlir", ["[email protected]"])
// for (i = 0; i < 100; i++) {
// const slugWordsNo = Math.floor(Math.random() * 1.999 + 3)
// console.log(randomWords({ exactly: slugWordsNo, join: '-' }))
// }
// var wordArray = []
// fs.readFile('./words.txt', 'utf8', function(err, data) {
// if (err) {
// console.log(err)
// }
// const splitArray = data.split("\n")
// for (i = 0; i < splitArray.length; i++) {
// if (!/[!@#$%^&*'-/(),.?":{}|<>]/.test(splitArray[i])) {
// if (i % 200 == 0) {
// wordArray.push('"' + splitArray[i] + '"\n')
// } else {
// wordArray.push('"' + splitArray[i] + '"')
// }
// }
// }
// fs.writeFile('./words-clean.txt', wordArray, function(err) {
// console.log(err)
// console.log('file saved')
// })
// console.log('number of words: ' + wordArray.length);
// })
async function getAllUsers() {
const allUsers = await prisma.users()
throw new Error("hello this is an error")
}
async function getShow(slug) {
const fragment = `
fragment RespondentsOnShow on Show {
id
slug
name
isPrivate
isAnonymous
startDate
endDate
respondents {
user {
name
email
}
response
role
}
createdAt
}
`
const show = await prisma.show({ slug: slug }).$fragment(fragment)
return show
}
async function getShows(email) {
const shows = await prisma.shows({
where: {
respondents_every: {
user: {
email: email
}
}
}
})
return shows
}
async function getShowRespondents() {
}
async function editUserSetings(email, data) {
update = await prisma.updateUser({
where: { email: email },
data: data
})
console.log(update)
return update
}
async function updateShow() {
const user = {
email: "[email protected]"
}
const fragment = `
fragment RespondentsOnShow on Show {
respondents {
user {
email
}
role
}
}
`
// check if current requesting user is admin of current show
const showRespondents = await prisma.show({ slug: "menon-green" }).$fragment(fragment)
userData = _.find(showRespondents.respondents, function (a) { return a.user.email == user.email })
if (userData.role != 'admin') {
return
}
const editShowSettings = await prisma.updateShow({
where: {
slug: "menon-green"
},
data: {
isAnonymous: false
}
})
return {
editShowSettings
}
}
async function deleteShow() {
const user = {
email: "[email protected]"
}
const fragment = `
fragment RespondentsOnShow on Show {
respondents {
user {
email
}
role
}
}
`
// check if current requesting user is admin of current show
const showRespondents = await prisma.show({ slug: "menon-red" }).$fragment(fragment)
console.log('show resp: ' + showRespondents.respondents[0].user.email)
userData = _.find(showRespondents.respondents, function (a) { return a.user.email == user.email })
console.log('user found ' + userData.role)
if (userData.role != 'admin') {
return
}
const deleteShow = await prisma.deleteShow({
slug: "menon-red"
})
return {
deleteShow
}
}
async function addRespondents() {
const user = {
email: "[email protected]"
}
const fragment = `
fragment RespondentsOnShow on Show {
respondents {
user {
email
}
role
}
}
`
// check if current requesting user is admin of current show
const showRespondents = await prisma.show({ slug: "menon-green" }).$fragment(fragment)
userData = _.find(showRespondents.respondents, function (a) { return a.user.email == user.email })
if (userData.role != 'admin') {
return
}
arr = [
{ respondentEmail: "[email protected]", respondentRole: "member" },
{ respondentEmail: "[email protected]", respondentRole: "member" },
]
respondentsArray = arr.map(function (a) {
return {
user: {
connect: {
email: a.respondentEmail
}
},
role: a.respondentRole
}
})
const addRespondents = await prisma.updateShow({
where: { slug: "menon-green" },
data: {
respondents: {
create: respondentsArray
}
}
})
console.log(addRespondents)
return {
addRespondents
}
}
async function deleteRespondents() {
const user = {
email: "[email protected]"
}
const fragment = `
fragment RespondentsOnShow on Show {
respondents {
id
user {
email
}
role
}
}
`
// check if current requesting user is admin of current show
const showRespondents = await prisma.show({ slug: "menon-green" }).$fragment(fragment)
userData = _.find(showRespondents.respondents, function (a) { return a.user.email == user.email })
if (userData.role != 'admin') {
return
}
arr = ['[email protected]', '[email protected]']
const respondentsUidArray = arr.map(function (email) {
const matchingUser = _.find(showRespondents.respondents, function (a) { return a.user.email == email })
return {
id: matchingUser.id
}
})
console.log(respondentsUidArray)
const addRespondents = await prisma.updateShow({
where: { slug: "menon-green" },
data: {
respondents: {
delete: respondentsUidArray
}
}
})
console.log(addRespondents)
return {
addRespondents
}
}
async function shows() {
await createUser
console.log(createUser)
}
function join() {
hello = [{
numberOne: '1',
numberTwo: {
email: 'hello'
}
}]
hello2 = {
numberThree: '3'
}
butt = _.find(hello, function (a) { return a.numberTwo.email == 'hello' })
console.log(_.find(hello, function (a) { return a.numberTwo.email == 'hello' }))
console.log('hello')
console.log(butt == null)
}
async function helloIamGroot() {
const butt = await prisma.$exists.show({
slug: "express-land-pocket",
respondents_every: {
role: "admin"
}
})
console.log(butt)
return butt
}
// getAllUsers(function(users) {
// console.log(users)
// }).catch(function(err) {5
// console.error(err)
// })