Add and remove bot to ecosystem
This commit is contained in:
1 parent
6d28784d91
commit
9a6b8a1572
9 files changed
+227
-4
No files matched your search
@@ -0,0 +1,63 @@
|
||||
import logger from '../../utils/logger'
|
||||
import { BotInputType, } from '../types/input'
|
||||
import { BotType, } from '../types'
|
||||
import { Ecosystem } from '../../models'
|
||||
|
||||
export const args = { bot: { type: BotInputType } }
|
||||
|
||||
const resolve = async (parent, { bot }, context) => {
|
||||
logger.debug('removeBot -> Dev team: %s. Bot: %s', bot.devTeam, bot.codeName)
|
||||
try {
|
||||
|
||||
let userEcosystem = await Ecosystem.findOne({
|
||||
authId: context.userId
|
||||
})
|
||||
|
||||
if (!userEcosystem) {
|
||||
throw 'Ecosystem not found for the user.'
|
||||
}
|
||||
|
||||
let removedBotClone
|
||||
for (let i = 0; i < userEcosystem.devTeams.length; i++) {
|
||||
const auxTeam = userEcosystem.devTeams[i]
|
||||
if (auxTeam.codeName === bot.devTeam) {
|
||||
for (let j = 0; j < auxTeam.bots.length; j++) {
|
||||
const auxBot = auxTeam.bots[j]
|
||||
if (auxBot.codeName + '-' + bot.cloneId === bot.codeName) {
|
||||
for (let k = 0; k < auxBot.products.length; k++) {
|
||||
const auxProduct = auxBot.products[k]
|
||||
if (auxProduct.codeName === bot.productCodeName) {
|
||||
removedBotClone = auxBot
|
||||
auxTeam.bots.splice(j, 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (removedBotClone) {
|
||||
await userEcosystem.save()
|
||||
return removedBotClone
|
||||
} else {
|
||||
throw 'Algobot not found.'
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
logger.error('removeBot -> Error: %s', err.message)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
const mutation = {
|
||||
removeBot: {
|
||||
type: BotType,
|
||||
args,
|
||||
resolve,
|
||||
}
|
||||
}
|
||||
|
||||
export default mutation;
|
||||
Reference in new issue
Block a user