crazy-odds-bet-shared 1.0.26 → 1.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/models/index.js +4 -0
- package/models/permission.js +21 -0
- package/models/role.js +21 -0
- package/models/user.js +7 -0
- package/package.json +1 -1
package/models/index.js
CHANGED
|
@@ -6,6 +6,8 @@ const { Team } = require('./team');
|
|
|
6
6
|
const { Player } = require('./player');
|
|
7
7
|
const { Fixture, FixtureStatus } = require('./fixture');
|
|
8
8
|
const { User } = require('./user');
|
|
9
|
+
const { Permission } = require('./permission');
|
|
10
|
+
const { Role } = require('./role');
|
|
9
11
|
const { MarketTemplate } = require('./marketTemplate');
|
|
10
12
|
const { Market } = require('./market');
|
|
11
13
|
const { Odd } = require('./odd');
|
|
@@ -23,6 +25,8 @@ module.exports = {
|
|
|
23
25
|
Fixture,
|
|
24
26
|
FixtureStatus,
|
|
25
27
|
User,
|
|
28
|
+
Permission,
|
|
29
|
+
Role,
|
|
26
30
|
MarketTemplate,
|
|
27
31
|
Market,
|
|
28
32
|
Odd,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const { Schema, model } = require('mongoose');
|
|
2
|
+
const { createBaseSchema, baseSchemaOptions } = require('./base');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Permission schema - granular permission codes (e.g. "users:read", "roles:write")
|
|
6
|
+
*/
|
|
7
|
+
const permissionSchema = new Schema(
|
|
8
|
+
{
|
|
9
|
+
...createBaseSchema(),
|
|
10
|
+
code: { type: String, required: true, unique: true, trim: true },
|
|
11
|
+
name: { type: String, required: true, trim: true },
|
|
12
|
+
description: { type: String, default: '' }
|
|
13
|
+
},
|
|
14
|
+
baseSchemaOptions
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
permissionSchema.index({ code: 1 });
|
|
18
|
+
|
|
19
|
+
const Permission = model('Permission', permissionSchema);
|
|
20
|
+
|
|
21
|
+
module.exports = { Permission };
|
package/models/role.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const { Schema, model } = require('mongoose');
|
|
2
|
+
const { createBaseSchema, baseSchemaOptions } = require('./base');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Role schema - named roles with a set of permission IDs (inherited by users assigned this role)
|
|
6
|
+
*/
|
|
7
|
+
const roleSchema = new Schema(
|
|
8
|
+
{
|
|
9
|
+
...createBaseSchema(),
|
|
10
|
+
name: { type: String, required: true, unique: true, trim: true },
|
|
11
|
+
description: { type: String, default: '' },
|
|
12
|
+
permissionIds: [{ type: String, ref: 'Permission' }]
|
|
13
|
+
},
|
|
14
|
+
baseSchemaOptions
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
roleSchema.index({ name: 1 });
|
|
18
|
+
|
|
19
|
+
const Role = model('Role', roleSchema);
|
|
20
|
+
|
|
21
|
+
module.exports = { Role };
|
package/models/user.js
CHANGED
|
@@ -10,7 +10,12 @@ const userSchema = new Schema(
|
|
|
10
10
|
email: { type: String, required: true, unique: true, lowercase: true, trim: true },
|
|
11
11
|
password: { type: String, required: true },
|
|
12
12
|
name: { type: String, required: true },
|
|
13
|
+
/** @deprecated Prefer roleId. Kept for backward compatibility. */
|
|
13
14
|
role: { type: String, enum: ['admin', 'user'], default: 'user' },
|
|
15
|
+
roleId: { type: String, ref: 'Role', default: null },
|
|
16
|
+
/** Custom permission IDs added on top of role permissions */
|
|
17
|
+
permissionIds: [{ type: String, ref: 'Permission' }],
|
|
18
|
+
config: { type: Schema.Types.Mixed, default: {} },
|
|
14
19
|
isActive: { type: Boolean, default: true }
|
|
15
20
|
},
|
|
16
21
|
baseSchemaOptions
|
|
@@ -19,6 +24,8 @@ const userSchema = new Schema(
|
|
|
19
24
|
// Indexes
|
|
20
25
|
userSchema.index({ isActive: 1 });
|
|
21
26
|
userSchema.index({ role: 1 });
|
|
27
|
+
userSchema.index({ roleId: 1 });
|
|
28
|
+
userSchema.index({ email: 1, password: 1, isActive: 1 });
|
|
22
29
|
|
|
23
30
|
// Static methods
|
|
24
31
|
userSchema.static('findByEmail', function (email) {
|