Files
Superalgos/server/src/schema/mutations/RemoveCloneMutation.js
T
mati108@gmail.com b25a66e26e Adding changes after team review
- Add Wait Time explanation on add clone
- AACloud logs, execution time
- Remove status and logs queries from Kubernates and push them from AACloud
- Order list results
2019-02-01 17:40:36 -03:00

73 lines
1.6 KiB
JavaScript

import {
GraphQLNonNull,
GraphQLID,
GraphQLString
} from 'graphql'
import {
AuthentificationError,
OperationsError
} from '../../errors'
import { Clone } from '../../models'
import logger from '../../config/logger'
import removeKuberneteClone from '../../kubernetes/removeClone'
import teamQuery from '../../graphQLCalls/teamQuery'
import { isDefined } from '../../config/utils'
import cloneDetails from '../cloneDetails'
const args = {
id: { type: new GraphQLNonNull(GraphQLID) }
}
const resolve = async (parent, { id }, context) => {
logger.debug('removeClone -> Entering Fuction.')
if (!context.userId) {
throw new AuthentificationError()
}
let clone = await Clone.findOne({
_id: id,
authId: context.userId,
active: true
})
if(!isDefined(clone)){
throw new OperationsError('You are not authorized to remove this clone.')
}
let team = await teamQuery(context.authorization)
clone = await cloneDetails(context.userId, team.data.data.teams_TeamById, clone)
logger.debug('removeClone -> Removing Clone from Kubernates.')
await removeKuberneteClone(clone)
const query = {
_id: id,
authId: context.userId
}
const options = { new: true }
const update = { active: false }
Clone.findOneAndUpdate(query, update, options, (err, doc) => {
if (err){
logger.error('removeClone -> Error removing clone from the DB. %s', err.stack)
throw new OperationsError(err)
}else{
logger.debug('removeClone -> Clone Removed from the DB.')
return('Clone Removed.')
}
})
}
const mutation = {
removeClone: {
type: GraphQLString,
args,
resolve
}
}
export default mutation