From 4752614c0105b864d00e97179b4b77ccbad89e2d Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Wed, 16 Oct 2019 19:16:14 +0000 Subject: [webapp/clients] Add the choice to select backends when deleting clients [group/clients] Checkbox list of the clients in the permanently delete dialog [server/backendhelper] Only deletes from the selected backends (array with backendids) --- server/api/clients.js | 2 +- server/lib/external-backends/backendhelper.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'server') diff --git a/server/api/clients.js b/server/api/clients.js index a6d151a..d72207b 100644 --- a/server/api/clients.js +++ b/server/api/clients.js @@ -29,7 +29,7 @@ router.getAsync('/:id', async (req, res) => { router.postAsync(['', '/:id'], async (req, res) => { if (req.query.delete !== undefined && req.query.delete !== 'false') { if (!Array.isArray(req.body.ids)) return HttpResponse.invalidBodyValue('ids', 'an array').send(res) - await backendHelper.deleteClients(req.body.ids) + await backendHelper.deleteClients(req.body.ids, req.body.backendIds) const count = await db.client.destroy({ where: { id: req.body.ids } }) HttpResponse.successBatch('deleted', 'client', count).send(res) } else { diff --git a/server/lib/external-backends/backendhelper.js b/server/lib/external-backends/backendhelper.js index 7e682d1..485b5f6 100644 --- a/server/lib/external-backends/backendhelper.js +++ b/server/lib/external-backends/backendhelper.js @@ -116,9 +116,15 @@ async function updateClient (client) { return result } -async function deleteClients (clientids) { +async function deleteClients (clientids, backendIds) { // Get all backends and call deleteClient for each instance. - const backends = await db.backend.findAll({ where: { '$clientMappings.clientid$': clientids }, include: ['clientMappings'] }) + const backends = await db.backend.findAll({ + where: { + id: { [db.Op.in]: backendIds }, + '$clientMappings.clientid$': clientids + }, + include: ['clientMappings'] + }) backends.forEach(backend => { const ba = new ExternalBackends() -- cgit v1.2.3-55-g7522