Skip to content

Commit 8e97381

Browse files
committed
feat(role): enhance Role schema with permissions and system flags
- Add new fields to Role schema: - description (String, optional) - permissions (Array of Permission ObjectIds) - isSystem (Boolean) for system-level roles - Update validation schemas for create and update operations - Add ObjectId validation for permission references
1 parent 7d137b5 commit 8e97381

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/domains/role/request.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,32 @@ const mongoose = require('mongoose');
33

44
const createSchema = Joi.object().keys({
55
name: Joi.string().required(),
6-
displayName: Joi.string().required()
6+
displayName: Joi.string().required(),
7+
description: Joi.string().allow('').optional(),
8+
permissions: Joi.array().items(
9+
Joi.string().custom((value, helpers) => {
10+
if (!mongoose.Types.ObjectId.isValid(value)) {
11+
return helpers.error('any.invalid');
12+
}
13+
return value;
14+
}, 'ObjectId validation')
15+
).optional(),
16+
isSystem: Joi.boolean().default(false)
717
});
818

919
const updateSchema = Joi.object().keys({
1020
name: Joi.string(),
11-
displayName: Joi.string()
21+
displayName: Joi.string(),
22+
description: Joi.string().allow(''),
23+
permissions: Joi.array().items(
24+
Joi.string().custom((value, helpers) => {
25+
if (!mongoose.Types.ObjectId.isValid(value)) {
26+
return helpers.error('any.invalid');
27+
}
28+
return value;
29+
}, 'ObjectId validation')
30+
),
31+
isSystem: Joi.boolean()
1232
});
1333

1434
const idSchema = Joi.object().keys({

src/domains/role/schema.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ const schema = new mongoose.Schema({
1212
displayName: {
1313
type: String,
1414
required: true,
15+
},
16+
description: {
17+
type: String,
18+
default: '',
19+
},
20+
permissions: [{
21+
type: mongoose.Schema.Types.ObjectId,
22+
ref: 'Permission'
23+
}],
24+
isSystem: {
25+
type: Boolean,
26+
default: false // To mark system-level roles like 'superadmin'
1527
}
1628
});
1729

0 commit comments

Comments
 (0)