Files
Superalgos/server/src/schema/mutations/UpdateExecutionSummary.js
T
mati108@gmail.com f942581f58 Realease candidate update
- Rename to superalgos
- Improved version of listing bots
- History bots
- Create new bots
2019-01-24 10:05:31 -03:00

72 lines
1.5 KiB
JavaScript

import {
GraphQLNonNull,
GraphQLID,
GraphQLString,
GraphQLInt,
GraphQLFloat
} from 'graphql'
import {
OperationsError
} from '../../errors'
import { Clone } from '../../models'
import logger from '../../config/logger'
const args = {
id: { type: new GraphQLNonNull(GraphQLID) },
summaryDate: { type: GraphQLInt },
buyAverage: { type: GraphQLFloat },
sellAverage: { type: GraphQLFloat },
marketRate: { type: GraphQLFloat },
combinedProfitsA: { type: GraphQLFloat },
combinedProfitsB: { type: GraphQLFloat },
assetA: { type: GraphQLString },
assetB: { type: GraphQLString }
}
const resolve = async (parent,
{ id, summaryDate, buyAverage, sellAverage, marketRate, combinedProfitsA,
combinedProfitsB, assetA, assetB
}) => {
logger.debug('UpdateExecutionSummary -> Entering Function.')
const query = { _id: id }
const options = { new: true }
const update = {
summaryDate: summaryDate,
buyAverage: buyAverage,
sellAverage: sellAverage,
marketRate: marketRate,
combinedProfitsA: combinedProfitsA,
combinedProfitsB: combinedProfitsB,
assetA: assetA,
assetB: assetB
}
let sucessful
await Clone.findOneAndUpdate(query, update, options, (err, doc) => {
if (err){
throw new OperationsError(err)
} else {
logger.debug('Execution summary updated')
sucessful = true
}
})
if(sucessful){
return 'Execution summary updated.'
}
}
const mutation = {
updateExecutionSummary: {
type: GraphQLString,
args,
resolve
}
}
export default mutation