diff --git a/server/src/schema/mutations/RemoveCloneMutation.js b/server/src/schema/mutations/RemoveCloneMutation.js index 694f37c15..e93a0d289 100644 --- a/server/src/schema/mutations/RemoveCloneMutation.js +++ b/server/src/schema/mutations/RemoveCloneMutation.js @@ -17,42 +17,48 @@ const resolve = async (parent, { id }, context) => { if (!context.userId) { throw new AuthentificationError() } + try { + let clone = await Clone.findOne({ + _id: id, + authId: context.userId, + active: true + }) - 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.teamId) - clone = await cloneDetails(context.userId, team.data.data.teams_TeamById, clone) - - logger.debug('removeClone -> Release the clone key.') - await authorizeClone(context.authorization, clone.keyId, clone.id, true) - - 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.') + if (!isDefined(clone)) { + throw new OperationsError('You are not authorized to remove this clone.') } - }) + + let team = await teamQuery(context.authorization, clone.teamId) + clone = await cloneDetails(context.userId, team.data.data.teams_TeamById, clone) + + logger.debug('removeClone -> Release the clone key.') + await authorizeClone(context.authorization, clone.keyId, clone.id, true) + + 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 } + + return new Promise((res, rej) => { + Clone.findOneAndUpdate(query, update, options, (err, doc) => { + if (err) { + logger.error('removeClone -> Error removing clone from the DB. %s', err.stack) + rej(err) + return + } + logger.debug('removeClone -> Clone Removed from the DB.') + res('Clone Removed.') + }) + }) + } catch (error) { + logger.error('Error removing the clone. %s', error.stack) + throw new OperationsError(error.message) + } } const RemoveCloneMutation = { diff --git a/server/src/schema/mutations/UpdateExecutionSummary.js b/server/src/schema/mutations/UpdateExecutionSummary.js index 324771330..dfe434e7d 100644 --- a/server/src/schema/mutations/UpdateExecutionSummary.js +++ b/server/src/schema/mutations/UpdateExecutionSummary.js @@ -35,8 +35,6 @@ const resolve = async (parent, } try { - let sucessful - let clone = await Clone.findOne({ _id: id, active: true @@ -63,19 +61,19 @@ const resolve = async (parent, } logger.debug('UpdateExecutionSummary -> Updating clone on database.') - await Clone.update(query, update, options, (err, clone) => { - if (err) { - logger.error('Error updating execution summary on the database. %s', err.stack) - throw err - } else { + + return new Promise((res, rej) => { + Clone.update(query, update, options, (err, clone) => { + if (err) { + logger.error('Error updating execution summary on the database. %s', err.stack) + rej(err) + return + } logger.debug('Execution summary updated.') - sucessful = true - } + res('Execution summary updated.') + }) }) - if (sucessful) { - return 'Execution summary updated.' - } } catch (error) { logger.error('Error updating the execution summary. %s', error.stack) throw new OperationsError(error.message)