forked from MyZubster-Ecosystem/myzubster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProposal.js
More file actions
56 lines (48 loc) 路 1.92 KB
/
Copy pathProposal.js
File metadata and controls
56 lines (48 loc) 路 1.92 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
47
48
49
50
51
52
53
54
55
56
const mongoose = require('mongoose');
const STATUSES = ['draft', 'active', 'passed', 'rejected', 'executed', 'cancelled'];
const CATEGORIES = ['funding', 'feature', 'policy', 'treasury', 'parameter_change', 'other'];
const proposalSchema = new mongoose.Schema(
{
title: { type: String, required: true, trim: true, maxlength: 200 },
description: { type: String, required: true, maxlength: 5000 },
category: { type: String, enum: CATEGORIES, default: 'other' },
proposerId: { type: String, required: true, index: true },
status: { type: String, enum: STATUSES, default: 'draft', index: true },
// Voting params
quorum: { type: Number, default: 50 }, // min % of total tokens that must vote
approvalThreshold: { type: Number, default: 50 }, // min % yes votes to pass
votingStartsAt: { type: Date, default: null },
votingEndsAt: { type: Date, default: null },
// Tally (denormalised for fast reads)
votesFor: { type: Number, default: 0 },
votesAgainst: { type: Number, default: 0 },
votesAbstain: { type: Number, default: 0 },
totalVotingPower: { type: Number, default: 0 },
// Execution
executionPayload: { type: mongoose.Schema.Types.Mixed, default: null },
executedAt: { type: Date, default: null },
// Discussion
comments: [{
authorId: { type: String, required: true },
text: { type: String, required: true, maxlength: 2000 },
createdAt: { type: Date, default: Date.now },
}],
},
{
versionKey: false,
timestamps: true,
toJSON: {
virtuals: true,
transform: (_doc, ret) => {
ret.id = ret._id.toString();
delete ret._id;
return ret;
},
},
}
);
proposalSchema.index({ status: 1, votingEndsAt: 1 });
proposalSchema.index({ proposerId: 1, status: 1 });
module.exports = mongoose.model('Proposal', proposalSchema);
module.exports.STATUSES = STATUSES;
module.exports.CATEGORIES = CATEGORIES;