Uploading minimal boilerplate
This commit is contained in:
1 parent
8516cac965
commit
5652cb9b6d
42 files changed
+8144
-1
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import mongoose, { Schema } from 'mongoose';
|
||||
import Plotter from './plotter';
|
||||
import Formula from './formula';
|
||||
import {
|
||||
UNPUBLISHED,
|
||||
EventStateEnum,
|
||||
} from '../enums/EventState';
|
||||
|
||||
const { ObjectId } = Schema.Types;
|
||||
|
||||
const eventSchema = new Schema({
|
||||
state: {
|
||||
type: String,
|
||||
enum: EventStateEnum,
|
||||
default: UNPUBLISHED,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
hostId: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
formulaId: {
|
||||
type: ObjectId,
|
||||
ref: Formula.modelName,
|
||||
},
|
||||
plotterId: {
|
||||
type: ObjectId,
|
||||
ref: Plotter.modelName,
|
||||
},
|
||||
prizes: [{
|
||||
rank: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
subPrize: [{
|
||||
condition: String,
|
||||
}],
|
||||
}],
|
||||
});
|
||||
|
||||
eventSchema.pre('find', function populate() {
|
||||
this.populate('formulaId').populate('plotterId');
|
||||
});
|
||||
eventSchema.post('save', (doc, next) => {
|
||||
doc.populate('formulaId').populate('plotterId').execPopulate().then(() => {
|
||||
next();
|
||||
});
|
||||
});
|
||||
eventSchema.post('findOneAndUpdate', (doc, next) => {
|
||||
doc.populate('formulaId').populate('plotterId').execPopulate().then(() => {
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
const Event = mongoose.model('Event', eventSchema);
|
||||
|
||||
export default Event;
|
||||
Reference in new issue
Block a user