-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgen-users.js
289 lines (261 loc) · 7.87 KB
/
gen-users.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
/* eslint-disable */
// FETCHING TICKETS FROM SYMPLA AND CREATING USER OBJECTS
// Fetching tickets from the Sympla API
const apiUrl = 'https://api.sympla.com.br/public/v3/events/2696886/participants?fields=first_name,last_name,email,ticket_name,ticket_num_qr_code,custom_form'
const token = '10ef3fa4339c27bb14027a050a778fdde9e34510e949cd28aefacb3030d285ac'
const requestOptions = {
method: 'GET',
headers: {
s_token: token,
},
}
// const response = await fetch(apiUrl, requestOptions).then(response => response.json())
// const tickets = response.data
const participants = []
const DAY1_ACTIVITIES = ['1', 'Soft Skills', 'ASP.NET', 'UI/UX', 'Beatriz']
const DAY2_ACTIVITIES = ['2', 'Análise', 'CRUD', 'Arduino']
const DAY3_ACTIVITIES = ['3', 'Front', 'Android']
// Function that adds the bough ticket into the right day array on the user object
const addActivity = (participant, ticket) => {
if (ticket.ticket_name.includes('Combo')) {
participant.tickets.day1.push({
ticket_name: ticket.ticket_name,
ticket_qrcode: ticket.ticket_num_qr_code
})
participant.tickets.day2.push({
ticket_name: ticket.ticket_name,
ticket_qrcode: ticket.ticket_num_qr_code
})
participant.tickets.day3.push({
ticket_name: ticket.ticket_name,
ticket_qrcode: ticket.ticket_num_qr_code
})
}
else if (DAY1_ACTIVITIES.some(v => ticket.ticket_name.includes(v))) {
participant.tickets.day1.push({
ticket_name: ticket.ticket_name,
ticket_qrcode: ticket.ticket_num_qr_code
})
}
else if (DAY2_ACTIVITIES.some(v => ticket.ticket_name.includes(v))) {
participant.tickets.day2.push({
ticket_name: ticket.ticket_name,
ticket_qrcode: ticket.ticket_num_qr_code
})
}
else if (DAY3_ACTIVITIES.some(v => ticket.ticket_name.includes(v))) {
participant.tickets.day3.push({
ticket_name: ticket.ticket_name,
ticket_qrcode: ticket.ticket_num_qr_code
})
}
}
const tickets = [
{
first_name: 'Felipe',
last_name: 'Tolentino Pereira',
email: '[email protected]',
custom_form: [
{value: '147.954.817-09'}
],
ticket_name: 'Combo - Todos os dias (Palestras)',
ticket_num_qr_code: 'TTUVUD4WJN'
},
{
first_name: 'Felipe',
last_name: 'Tolentino Pereira',
email: '[email protected]',
custom_form: [
{value: '147.954.817-09'}
],
ticket_name: 'Minicurso - Análise de Dados',
ticket_num_qr_code: 'TU3SADTHBL'
},
{
first_name: 'Felipe',
last_name: 'Tolentino Pereira',
email: '[email protected]',
custom_form: [
{value: '147.954.817-09'}
],
ticket_name: 'Minicurso - Do Zero ao CRUD! (Backend)',
ticket_num_qr_code: 'TU3SADTLXC'
},
{
first_name: 'Felipe',
last_name: 'Tolentino Pereira',
email: '[email protected]',
custom_form: [
{value: '147.954.817-09'}
],
ticket_name: 'Minicurso - Introdução à Android Nativo',
ticket_num_qr_code: 'TU3SADTV2Z'
},
]
// Loop through all tickets fetched from the Sympla API and
// create the user objects. Add tickets bough from the same person
// in the same user object.
tickets.forEach(ticket => {
var participant = participants.find(
participant => participant.cpf === ticket.custom_form[0].value
);
if (participant) {
addActivity(participant, ticket)
}
else {
participant = {
first_name: ticket.first_name,
last_name: ticket.last_name,
email: ticket.email,
cpf: ticket.custom_form[0].value,
tickets: {
day1: [],
day2: [],
day3: []
}
}
addActivity(participant, ticket);
participants.push(participant);
}
});
// USE THE NEWLY CREATED USER OBJECTS TO CREATE SUPABASE USERS PwOppHfgy9ls k55TgNSbIsTR
import { createClient } from '@supabase/supabase-js'
const url = 'https://kejnzgchwgonxhcmltfl.supabase.co'
const key = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imtlam56Z2Nod2dvbnhoY21sdGZsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MzA3MDk0NzAsImV4cCI6MjA0NjI4NTQ3MH0.WtyE1sPnawhcLXw4U0s5QOTcIZ1-N-l3zNBZ7JMOGSU'
const client = createClient(url, key)
function genPassword() {
const chars = '0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*()ABCDEFGHIJKLMNOPQRSTUVWXYZ'
let password = ''
for (let i = 0; i < 12; i++) {
const num = Math.floor(Math.random() * chars.length)
password += chars.substring(num, num + 1)
}
console.log(password)
return password
}
for (let i = 0; i < 2; i++) {
try {
const { error } = await client.auth.signUp({
email: participants[i].email,
password: genPassword(),
options: {
data: {
first_name: participants[i].first_name,
last_name: participants[i].last_name,
cpf: participants[i].cpf,
tickets: participants[i].tickets,
admin: false
}
}
})
if (error) throw error;
console.log("success")
}
catch(error) {
console.log(error)
}
}
// try {
// const { error } = await client.auth.signUp({
// email: '[email protected]',
// password: 'admin123',
// options: {
// data: {
// first_name: 'admin',
// last_name: 'admin',
// cpf: '000.000.000-00',
// tickets: {},
// admin: true
// }
// }
// })
// if (error) throw error;
// console.log("success")
// }
// catch(error) {
// console.log(error)
// }
// try {
// const { error } = await client.auth.signInWithPassword({
// email: '[email protected]',
// password: 'undefinedu5Anw^ha',
// })
// if (error)
// throw error
// }
// catch (error) {
// console.log(error)
// }
// const { data: { user } } = await client.auth.getUser()
// console.log(user.user_metadata.tickets[0].ticket_qrcode)
// for (const participant of participants) {
// for (const day in participant.tickets) {
// const tickets = participant.tickets[day]
// for (const ticket of tickets) {
// let table;
// let diff;
// if (ticket.ticket_name.includes('Combo')) {
// table = 'checkin-talks'
// diff = day.slice(-1);
// }
// else if (ticket.ticket_name.includes('DIA 1')) {
// table = 'checkin-talks'
// diff = '1'
// }
// else if (ticket.ticket_name.includes('DIA 2')) {
// table = 'checkin-talks'
// diff = '2'
// }
// else if (ticket.ticket_name.includes('DIA 3')) {
// table = 'checkin-talks'
// diff = '3'
// }
// else if (ticket.ticket_name.includes('UI')) {
// table = 'checkin-courses'
// diff = 'UI'
// }
// else if (ticket.ticket_name.includes('ASP')) {
// table = 'checkin-courses'
// diff = 'ASP'
// }
// else if (ticket.ticket_name.includes('Skills')) {
// table = 'checkin-courses'
// diff = 'Beatriz'
// }
// else if (ticket.ticket_name.includes('Dados')) {
// table = 'checkin-courses'
// diff = 'Dados'
// }
// else if (ticket.ticket_name.includes('CRUD')) {
// table = 'checkin-courses'
// diff = 'CRUD'
// }
// else if (ticket.ticket_name.includes('Arduino')) {
// table = 'checkin-courses'
// diff = 'Arduino'
// }
// else if (ticket.ticket_name.includes('HTML')) {
// table = 'checkin-courses'
// diff = 'HTML'
// }
// else if (ticket.ticket_name.includes('Android')) {
// table = 'checkin-courses'
// diff = 'Android'
// }
// try {
// const { error } = await client.from(table)
// .insert({
// qrcode: ticket.ticket_qrcode,
// participant_name: `${participant.first_name} ${participant.last_name}`,
// differentiator: diff
// })
// if (error)
// throw error
// }
// catch (error) {
// console.log(error.message)
// }
// }
// }
// }
// oikmEUrZyjYs