diff --git a/back/services/env.ts b/back/services/env.ts index 98fcfbea..d776aeb7 100644 --- a/back/services/env.ts +++ b/back/services/env.ts @@ -201,25 +201,29 @@ export default class EnvService { public async addLabels(ids: number[], labels: string[]) { const docs = await EnvModel.findAll({ where: { id: ids } }); - for (const doc of docs) { - const env = doc.get({ plain: true }); - await EnvModel.update( - { labels: Array.from(new Set((env.labels || []).concat(labels))) }, - { where: { id: env.id } }, - ); - } + await sequelize.transaction(async (t) => { + for (const doc of docs) { + const env = doc.get({ plain: true }); + await EnvModel.update( + { labels: Array.from(new Set((env.labels || []).concat(labels))) }, + { where: { id: env.id }, transaction: t }, + ); + } + }); return await EnvModel.findAll({ where: { id: ids } }); } public async removeLabels(ids: number[], labels: string[]) { const docs = await EnvModel.findAll({ where: { id: ids } }); - for (const doc of docs) { - const env = doc.get({ plain: true }); - await EnvModel.update( - { labels: (env.labels || []).filter((label: string) => !labels.includes(label)) }, - { where: { id: env.id } }, - ); - } + await sequelize.transaction(async (t) => { + for (const doc of docs) { + const env = doc.get({ plain: true }); + await EnvModel.update( + { labels: (env.labels || []).filter((label: string) => !labels.includes(label)) }, + { where: { id: env.id }, transaction: t }, + ); + } + }); return await EnvModel.findAll({ where: { id: ids } }); } diff --git a/src/pages/env/index.tsx b/src/pages/env/index.tsx index 4f1a9cb9..89a78015 100644 --- a/src/pages/env/index.tsx +++ b/src/pages/env/index.tsx @@ -128,7 +128,7 @@ const Env = () => { render: (labels: string[], record: any) => { return ( - {labels?.filter((l) => l).map((label) => ( + {labels?.filter((label) => label).map((label) => ( {label}