opt-cc/server/models/awarding.js

47 lines
879 B
JavaScript
Raw Permalink Normal View History

2018-03-12 09:26:44 +01:00
'use strict';
2017-05-10 11:04:06 +02:00
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const AwardingSchema = new Schema({
userId: {
type: mongoose.Schema.Types.ObjectId,
2018-03-12 09:26:44 +01:00
ref: 'User',
2017-05-10 11:04:06 +02:00
},
decorationId: {
type: mongoose.Schema.Types.ObjectId,
2018-03-12 09:26:44 +01:00
ref: 'Decoration',
2017-05-10 11:04:06 +02:00
},
reason: {
type: String,
2018-03-12 09:26:44 +01:00
required: true,
2017-05-10 11:04:06 +02:00
},
2017-06-09 18:30:35 +02:00
proposer: {
type: mongoose.Schema.Types.ObjectId,
ref: 'AppUser',
2018-03-12 09:26:44 +01:00
required: true,
2017-06-09 18:30:35 +02:00
},
2017-05-10 11:04:06 +02:00
confirmed: {
2017-06-10 22:07:32 +02:00
type: Number,
2018-03-12 09:26:44 +01:00
get: (v) => Math.round(v),
set: (v) => Math.round(v),
2017-06-10 22:07:32 +02:00
min: 0,
max: 2,
2018-03-12 09:26:44 +01:00
default: 0,
2017-05-10 11:04:06 +02:00
},
rejectReason: {
2018-03-12 09:26:44 +01:00
type: String,
},
2017-05-10 11:04:06 +02:00
date: {
type: Date,
2018-03-12 09:26:44 +01:00
default: Date.now(),
},
2017-05-10 11:04:06 +02:00
}, {
collection: 'awarding',
2018-03-12 09:26:44 +01:00
timestamps: {createdAt: 'timestamp'},
2017-05-10 11:04:06 +02:00
});
// optional more indices
AwardingSchema.index({timestamp: 1});
module.exports = mongoose.model('Awarding', AwardingSchema);