forked from MyZubster-Ecosystem/myzubster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelegation.js
More file actions
28 lines (25 loc) 路 816 Bytes
/
Copy pathDelegation.js
File metadata and controls
28 lines (25 loc) 路 816 Bytes
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
const mongoose = require('mongoose');
const delegationSchema = new mongoose.Schema(
{
delegatorId: { type: String, required: true, index: true },
delegateId: { type: String, required: true, index: true },
tokenWeight: { type: Number, required: true, min: 1 },
scope: { type: String, default: 'all' }, // 'all' | category name
isActive: { type: Boolean, default: true, index: true },
expiresAt: { type: Date, default: null },
},
{
versionKey: false,
timestamps: true,
toJSON: {
virtuals: true,
transform: (_doc, ret) => {
ret.id = ret._id.toString();
delete ret._id;
return ret;
},
},
}
);
delegationSchema.index({ delegatorId: 1, delegateId: 1, scope: 1 });
module.exports = mongoose.model('Delegation', delegationSchema);