forked from MyZubster-Ecosystem/myzubster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreasury.js
More file actions
37 lines (33 loc) 路 1.11 KB
/
Copy pathTreasury.js
File metadata and controls
37 lines (33 loc) 路 1.11 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
const mongoose = require('mongoose');
const TX_TYPES = ['deposit', 'withdrawal', 'transfer', 'reward'];
const treasurySchema = new mongoose.Schema(
{
name: { type: String, required: true, trim: true, default: 'Main Treasury' },
balance: { type: Number, default: 0, min: 0 },
currency: { type: String, default: 'XMR' },
ownerId: { type: String, required: true, index: true },
transactions: [{
type: { type: String, enum: TX_TYPES, required: true },
amount: { type: Number, required: true },
from: { type: String, default: '' },
to: { type: String, default: '' },
proposalId: { type: mongoose.Schema.Types.ObjectId, ref: 'Proposal', default: null },
note: { type: String, default: '' },
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;
},
},
}
);
treasurySchema.index({ ownerId: 1 });
module.exports = mongoose.model('Treasury', treasurySchema);