forked from MyZubster-Ecosystem/myzubster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVote.js
More file actions
30 lines (26 loc) 路 853 Bytes
/
Copy pathVote.js
File metadata and controls
30 lines (26 loc) 路 853 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
29
30
const mongoose = require('mongoose');
const CHOICES = ['for', 'against', 'abstain'];
const voteSchema = new mongoose.Schema(
{
proposalId: { type: mongoose.Schema.Types.ObjectId, ref: 'Proposal', required: true, index: true },
voterId: { type: String, required: true },
choice: { type: String, enum: CHOICES, required: true },
weight: { type: Number, required: true, min: 0 },
reason: { type: String, trim: true, default: '', maxlength: 500 },
},
{
versionKey: false,
timestamps: true,
toJSON: {
virtuals: true,
transform: (_doc, ret) => {
ret.id = ret._id.toString();
delete ret._id;
return ret;
},
},
}
);
// One vote per voter per proposal
voteSchema.index({ proposalId: 1, voterId: 1 }, { unique: true });
module.exports = mongoose.model('Vote', voteSchema);