Spaces:
Paused
Paused
changing things in workspace
Browse files- seedUsers.js +63 -0
- src/controllers/threads.js +1 -0
- src/controllers/workspaces.js +8 -0
seedUsers.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const prisma = require('./src/lib/prisma');
|
| 2 |
+
const bcrypt = require('bcryptjs');
|
| 3 |
+
|
| 4 |
+
const NICHES = ['Tech', 'Health', 'Finance', 'Travel', 'Lifestyle', 'Business', 'Education'];
|
| 5 |
+
|
| 6 |
+
const generateRandomUsersAndWorkspaces = async () => {
|
| 7 |
+
const salt = await bcrypt.genSalt(10);
|
| 8 |
+
const hashedPassword = await bcrypt.hash('Password123!', salt);
|
| 9 |
+
let count = 0;
|
| 10 |
+
|
| 11 |
+
console.log('Inserting 20 fully onboarded users...');
|
| 12 |
+
|
| 13 |
+
for (let i = 0; i < 20; i++) {
|
| 14 |
+
const randomSuffix = Math.floor(Math.random() * 1000000);
|
| 15 |
+
const firstName = `User${randomSuffix}`;
|
| 16 |
+
const lastName = `Test`;
|
| 17 |
+
const name = `${firstName} ${lastName}`;
|
| 18 |
+
const email = `user${randomSuffix}@example.com`;
|
| 19 |
+
|
| 20 |
+
const domain = `site${randomSuffix}.com`;
|
| 21 |
+
const websiteName = `Awesome Site ${randomSuffix}`;
|
| 22 |
+
const description = `This is a randomly generated description for ${domain}. We provide great content about our niche.`;
|
| 23 |
+
const niche = NICHES[Math.floor(Math.random() * NICHES.length)];
|
| 24 |
+
|
| 25 |
+
try {
|
| 26 |
+
await prisma.user.create({
|
| 27 |
+
data: {
|
| 28 |
+
name,
|
| 29 |
+
email,
|
| 30 |
+
hashedPassword,
|
| 31 |
+
role: 'CLIENT',
|
| 32 |
+
teamMemberships: {
|
| 33 |
+
create: {
|
| 34 |
+
role: 'OWNER',
|
| 35 |
+
workspace: {
|
| 36 |
+
create: {
|
| 37 |
+
domain,
|
| 38 |
+
websiteName,
|
| 39 |
+
description,
|
| 40 |
+
niche,
|
| 41 |
+
country: 'USA',
|
| 42 |
+
language: 'English',
|
| 43 |
+
monthlyTraffic: Math.floor(Math.random() * 50000) + 1000,
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
});
|
| 50 |
+
count++;
|
| 51 |
+
} catch (err) {
|
| 52 |
+
console.error(`Error creating user ${email}:`, err.message);
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
console.log(`Successfully inserted ${count} fully onboarded users with workspaces!`);
|
| 57 |
+
console.log('Sample user email:', `user*@example.com`);
|
| 58 |
+
console.log('All users have the password: Password123!');
|
| 59 |
+
|
| 60 |
+
await prisma.$disconnect();
|
| 61 |
+
};
|
| 62 |
+
|
| 63 |
+
generateRandomUsersAndWorkspaces();
|
src/controllers/threads.js
CHANGED
|
@@ -41,6 +41,7 @@ const createThread = async (req, res) => {
|
|
| 41 |
receiverWorkspaceId,
|
| 42 |
stage: 'NEW',
|
| 43 |
status: 'PENDING',
|
|
|
|
| 44 |
},
|
| 45 |
include: {
|
| 46 |
giverWorkspace: true,
|
|
|
|
| 41 |
receiverWorkspaceId,
|
| 42 |
stage: 'NEW',
|
| 43 |
status: 'PENDING',
|
| 44 |
+
giverAccepted: true,
|
| 45 |
},
|
| 46 |
include: {
|
| 47 |
giverWorkspace: true,
|
src/controllers/workspaces.js
CHANGED
|
@@ -7,6 +7,10 @@ const createWorkspace = async (req, res) => {
|
|
| 7 |
return res.status(400).json({ error: 'Domain, website name, and description are required' });
|
| 8 |
}
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
try {
|
| 11 |
// Check user doesn't already have a workspace
|
| 12 |
const existing = await prisma.teamMember.findFirst({
|
|
@@ -80,6 +84,10 @@ const updateMyWorkspace = async (req, res) => {
|
|
| 80 |
return res.status(403).json({ error: 'Only owners can update workspace details' });
|
| 81 |
}
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
const updated = await prisma.workspace.update({
|
| 84 |
where: { id: member.workspaceId },
|
| 85 |
data: {
|
|
|
|
| 7 |
return res.status(400).json({ error: 'Domain, website name, and description are required' });
|
| 8 |
}
|
| 9 |
|
| 10 |
+
if (!domain.toLowerCase().trim().endsWith('.com')) {
|
| 11 |
+
return res.status(400).json({ error: 'Only .com domains are allowed.' });
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
try {
|
| 15 |
// Check user doesn't already have a workspace
|
| 16 |
const existing = await prisma.teamMember.findFirst({
|
|
|
|
| 84 |
return res.status(403).json({ error: 'Only owners can update workspace details' });
|
| 85 |
}
|
| 86 |
|
| 87 |
+
if (domain && !domain.toLowerCase().trim().endsWith('.com')) {
|
| 88 |
+
return res.status(400).json({ error: 'Only .com domains are allowed.' });
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
const updated = await prisma.workspace.update({
|
| 92 |
where: { id: member.workspaceId },
|
| 93 |
data: {
|