Defining the strategy model

This commit is contained in:
Unknown committed 2019-03-16 10:42:00 +01:00
1 parent 3695a6f47a
commit 3e4c6d6748
5 files changed
+177 -90

No files matched your search

-60
View File
@@ -1,60 +0,0 @@
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;
-12
View File
@@ -1,12 +0,0 @@
import mongoose, { Schema } from 'mongoose';
const formulaSchema = new Schema({
name: {
type: String,
required: true,
},
});
const Formula = mongoose.model('Formula', formulaSchema);
export default Formula;
+3 -6
View File
@@ -1,9 +1,6 @@
import Plotter from './plotter';
import Event from './event';
import Formula from './formula';
/* eslint-disable import/prefer-default-export */
import Strategy from './strategy';
export {
Event,
Plotter,
Formula,
Strategy,
};
-12
View File
@@ -1,12 +0,0 @@
import mongoose, { Schema } from 'mongoose';
const plotterSchema = new Schema({
name: {
type: String,
required: true,
},
});
const Plotter = mongoose.model('Plotter', plotterSchema);
export default Plotter;
+174
View File
@@ -0,0 +1,174 @@
import mongoose, { Schema } from 'mongoose';
const strategySchema = new Schema({
fbId: {
type: String,
required: true,
},
strategies: [{
name: {
type: String,
default: '',
},
entryPoint: {
situations: [{
name: {
type: String,
default: '',
},
conditions: [{
name: {
type: String,
default: '',
},
code: {
type: String,
default: 'false',
},
}],
}],
},
exitPoint: {
situations: [{
name: {
type: String,
default: '',
},
conditions: [{
name: {
type: String,
default: '',
},
code: {
type: String,
default: 'false',
},
}],
}],
},
sellPoint: {
situations: [{
name: {
type: String,
default: '',
},
conditions: [{
name: {
type: String,
default: '',
},
code: {
type: String,
default: 'false',
},
}],
}],
},
buyPoint: {
situations: [{
name: {
type: String,
default: '',
},
conditions: [{
name: {
type: String,
default: '',
},
code: {
type: String,
default: 'false',
},
}],
}],
},
stopLoss: {
phases: [{
name: {
type: String,
default: '',
},
code: {
type: String,
default: 'false',
},
situations: [{
name: {
type: String,
default: '',
},
conditions: [{
name: {
type: String,
default: '',
},
code: {
type: String,
default: 'false',
},
}],
}],
}],
},
buyOrder: {
phases: [{
name: {
type: String,
default: '',
},
code: {
type: String,
default: 'false',
},
situations: [{
name: {
type: String,
default: '',
},
conditions: [{
name: {
type: String,
default: '',
},
code: {
type: String,
default: 'false',
},
}],
}],
}],
},
sellOrder: {
phases: [{
name: {
type: String,
default: '',
},
code: {
type: String,
default: 'false',
},
situations: [{
name: {
type: String,
default: '',
},
conditions: [{
name: {
type: String,
default: '',
},
code: {
type: String,
default: 'false',
},
}],
}],
}],
},
}],
});
const Strategy = mongoose.model('Strategy', strategySchema);
export default Strategy;