From 6edd85ac9357bbd8030536af1ed3ce20d1e3af47 Mon Sep 17 00:00:00 2001 From: rozetko Date: Fri, 5 Apr 2019 11:00:19 +0300 Subject: [PATCH] Batch detection #500 (#502) --- server/src/routes/analytic_units_router.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/src/routes/analytic_units_router.ts b/server/src/routes/analytic_units_router.ts index f2bb4f3..406b288 100644 --- a/server/src/routes/analytic_units_router.ts +++ b/server/src/routes/analytic_units_router.ts @@ -4,6 +4,7 @@ import * as AnalyticUnit from '../models/analytic_unit_model'; import { createAnalyticUnitFromObject } from '../controllers/analytics_controller'; import * as Router from 'koa-router'; +import * as _ from 'lodash'; async function getStatus(ctx: Router.IRouterContext) { @@ -122,8 +123,10 @@ async function deleteUnit(ctx: Router.IRouterContext) { } async function runDetect(ctx: Router.IRouterContext) { - const { id: analyticUnitId } = ctx.request.body as { id: AnalyticUnit.AnalyticUnitId }; - AnalyticsController.runFirstLearning(analyticUnitId); + const { ids } = ctx.request.body as { ids: AnalyticUnit.AnalyticUnitId[] }; + + await Promise.all(ids.map(AnalyticsController.runFirstLearning)); + ctx.response.body = { code: 200, message: 'Success'