Browse Source

fix typescript errors

pull/1/head
rozetko 4 years ago
parent
commit
bfee62daf2
  1. 10
      server/src/routes/analytic_units_router.ts
  2. 14
      server/src/routes/data_router.ts
  3. 2
      server/src/routes/detections_router.ts
  4. 2
      server/src/routes/panel_router.ts
  5. 2
      server/src/routes/segments_router.ts
  6. 2
      server/src/services/data_layer/nedb.ts
  7. 2
      server/src/services/json_service.ts

10
server/src/routes/analytic_units_router.ts

@ -8,7 +8,7 @@ import * as _ from 'lodash';
async function getStatus(ctx: Router.IRouterContext) { async function getStatus(ctx: Router.IRouterContext) {
let analyticUnitId = ctx.request.query.id; let analyticUnitId = ctx.request.query.id as string;
if(analyticUnitId === undefined) { if(analyticUnitId === undefined) {
throw new Error('Cannot get status of undefined id'); throw new Error('Cannot get status of undefined id');
} }
@ -23,12 +23,14 @@ async function getStatus(ctx: Router.IRouterContext) {
}; };
if(analyticUnit.status === AnalyticUnit.AnalyticUnitStatus.FAILED) { if(analyticUnit.status === AnalyticUnit.AnalyticUnitStatus.FAILED) {
ctx.response.body.errorMessage = analyticUnit.error; ctx.response.body = {
errorMessage: analyticUnit.error
};
} }
} }
async function getUnits(ctx: Router.IRouterContext) { async function getUnits(ctx: Router.IRouterContext) {
const panelId = ctx.request.query.panelId; const panelId = ctx.request.query.panelId as string;
if(panelId === undefined) { if(panelId === undefined) {
throw new Error('Cannot get units of undefined panelId'); throw new Error('Cannot get units of undefined panelId');
} }
@ -118,7 +120,7 @@ async function updateAlert(ctx: Router.IRouterContext) {
} }
async function deleteUnit(ctx: Router.IRouterContext) { async function deleteUnit(ctx: Router.IRouterContext) {
const analyticUnitId = ctx.request.query.id; const analyticUnitId = ctx.request.query.id as string;
if(analyticUnitId === undefined) { if(analyticUnitId === undefined) {
throw new Error('Cannot delete undefined id'); throw new Error('Cannot delete undefined id');
} }

14
server/src/routes/data_router.ts

@ -6,24 +6,24 @@ import * as Router from 'koa-router';
async function query(ctx: Router.IRouterContext) { async function query(ctx: Router.IRouterContext) {
let from = ctx.request.query.from; let queryFrom = ctx.request.query.from as string;
let to = ctx.request.query.to; let queryTo = ctx.request.query.to as string;
const analyticUnitId = ctx.request.query.analyticUnitId; const analyticUnitId = ctx.request.query.analyticUnitId as string;
if(analyticUnitId === undefined) { if(analyticUnitId === undefined) {
throw new Error(`data router error: request must contain analyticUnitId`); throw new Error(`data router error: request must contain analyticUnitId`);
} }
if(from === undefined) { if(queryFrom === undefined) {
throw new Error(`data router error: request must contain 'from'`) throw new Error(`data router error: request must contain 'from'`)
} }
if(to === undefined) { if(queryTo === undefined) {
throw new Error(`data router error: request must contain 'to'`) throw new Error(`data router error: request must contain 'to'`)
} }
from = +from; const from = +queryFrom;
to = +to; const to = +queryTo;
if(from === NaN) { if(from === NaN) {
throw new Error(`from must be not NaN`); throw new Error(`from must be not NaN`);

2
server/src/routes/detections_router.ts

@ -10,7 +10,7 @@ declare type DetectionSpansResponse = {
} }
export async function getDetectionSpans(ctx: Router.IRouterContext) { export async function getDetectionSpans(ctx: Router.IRouterContext) {
let id: AnalyticUnitId = ctx.request.query.id; const id = ctx.request.query.id as AnalyticUnitId;
if(id === undefined || id === '') { if(id === undefined || id === '') {
throw new Error('analyticUnitId (id) is missing'); throw new Error('analyticUnitId (id) is missing');
} }

2
server/src/routes/panel_router.ts

@ -5,7 +5,7 @@ import * as Router from 'koa-router';
async function exportGrafanaPanelTemplate(ctx: Router.IRouterContext) { async function exportGrafanaPanelTemplate(ctx: Router.IRouterContext) {
let panelId = ctx.request.query.panelId; const panelId = ctx.request.query.panelId as string;
if(panelId === undefined) { if(panelId === undefined) {
throw new Error('Cannot export analytic units with undefined panelId'); throw new Error('Cannot export analytic units with undefined panelId');
} }

2
server/src/routes/segments_router.ts

@ -7,7 +7,7 @@ import * as Router from 'koa-router';
export async function getSegments(ctx: Router.IRouterContext) { export async function getSegments(ctx: Router.IRouterContext) {
let id: AnalyticUnitId = ctx.request.query.id; const id = ctx.request.query.id as AnalyticUnitId;
if(id === undefined || id === '') { if(id === undefined || id === '') {
throw new Error('analyticUnitId (id) is missing'); throw new Error('analyticUnitId (id) is missing');
} }

2
server/src/services/data_layer/nedb.ts

@ -36,7 +36,7 @@ export class NeDbQueryWrapper implements DbQueryWrapper {
// https://github.com/louischatriot/nedb#updating-documents // https://github.com/louischatriot/nedb#updating-documents
let nedbUpdateQuery = { $set: updateQuery } let nedbUpdateQuery = { $set: updateQuery }
query = wrapIdToQuery(query); query = wrapIdToQuery(query);
return new Promise<any>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
nd.update( nd.update(
query, query,
nedbUpdateQuery, nedbUpdateQuery,

2
server/src/services/json_service.ts

@ -22,7 +22,7 @@ async function getJsonData(filename: string): Promise<Object> {
} }
function writeJsonData(filename: string, data: Object) { function writeJsonData(filename: string, data: Object) {
return new Promise((resolve, reject) => { return new Promise<void>((resolve, reject) => {
fs.writeFile(filename, JSON.stringify(data), 'utf8', (err) => { fs.writeFile(filename, JSON.stringify(data), 'utf8', (err) => {
if(err) { if(err) {
console.error(err); console.error(err);

Loading…
Cancel
Save