-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathcreateuser.js
More file actions
70 lines (63 loc) · 2.02 KB
/
Copy pathcreateuser.js
File metadata and controls
70 lines (63 loc) · 2.02 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
const { PrismaClient } = require("@prisma/client");
const prisma = new PrismaClient();
// const bcrypt = require("bcrypt");
function generateRandomPhoneNumber() {
return Math.floor(1000000000 + Math.random() * 9000000000).toString();
}
async function deleteUsers(n) {
const emailPattern = [];
for (let i = 1; i <= n; i++) {
emailPattern.push(`user${i}@example.com`);
}
try {
// Delete users matching the email pattern
const deletedUsers = await prisma.user.deleteMany({
where: {
email: {
in: emailPattern, // Delete users where the email is in the list
},
},
});
console.log(`${deletedUsers.count} users deleted successfully.`);
} catch (error) {
console.error("Error deleting users:", error);
} finally {
await prisma.$disconnect();
}
}
async function createUsers(n) {
const users = [];
// const password = "123"; // default password
// const hashedPassword = await bcrypt.hash(password, 10); // hashing the password
for (let i = 1; i <= n; i++) {
const user = {
email: `member_creative${i}@example.com`,
name: `CREATIVE ${i}`,
access: "CREATIVE",
year: "3rd",
password: '$2a$10$z7cMuHyEvicDsSqS8nr4luPDaNLkA7m0rmkQihLh.4EyeyodkJqe6',
rollNumber: `220530${i}`,
school: "CSE",
college: "KIIT",
contactNo: generateRandomPhoneNumber(), // random 10 digit number
whatsappNo: generateRandomPhoneNumber(), // random 10 digit number
regForm: [], // no regForm initially
// editProfileCount: 5, // initialize editProfileCount to 5
};
users.push(user);
}
try {
const createdUsers = await prisma.user.createMany({
data: users
// skipDuplicates: true, // Skip if there's already a user with the same email
});
console.log(`${createdUsers.count} users created successfully.`);
} catch (error) {
console.error("Error creating users:", error);
} finally {
await prisma.$disconnect();
}
}
// Example usage: Create 10 users
createUsers(10);
// deleteUsers(50)