-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateDefaultRole.js
More file actions
46 lines (39 loc) · 1.18 KB
/
Copy pathcreateDefaultRole.js
File metadata and controls
46 lines (39 loc) · 1.18 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
const { MongoClient } = require('mongodb');
const uri = 'mongodb://localhost:27017/tinytots';
const client = new MongoClient(uri);
async function createDefaultRole() {
try {
await client.connect();
const db = client.db('tinytots');
// Check if default role already exists
const existingRole = await db.collection('roles').findOne({ isDefault: true });
if (existingRole) {
console.log('Default role already exists:', existingRole);
return;
}
const defaultRole = {
name: 'user',
description: 'Default user role',
permissions: {
viewProfile: true,
editProfile: true,
viewProducts: true,
makeOrders: true,
viewOrders: true,
cancelOrders: true
},
isDefault: true,
createdAt: new Date(),
updatedAt: new Date()
};
const result = await db.collection('roles').insertOne(defaultRole);
console.log('Default role created successfully');
console.log('Role ID:', result.insertedId);
} catch (error) {
console.error('Error creating default role:', error);
} finally {
await client.close();
process.exit(0);
}
}
createDefaultRole();