mirror of
https://github.com/sergeyyarkov/asu_tools_service.git
synced 2026-10-11 18:39:15 +03:00
refactor
This commit is contained in:
parent
53a8cab4fb
commit
8d0536e779
@ -3,6 +3,8 @@ import { clients } from "#root/index.js";
|
|||||||
import { reportsService } from "#services/index.js";
|
import { reportsService } from "#services/index.js";
|
||||||
import { serializeError } from "serialize-error";
|
import { serializeError } from "serialize-error";
|
||||||
|
|
||||||
|
/** @import { HttpRouteHandler } from "#root/http-server/types/http-server.js" */
|
||||||
|
|
||||||
const MAX_CONCURRENT_PARSE_CLIENT = Number.parseInt(process.env.REPORT_CONCURRENT_PARSE_CLIENTS || "3", 10);
|
const MAX_CONCURRENT_PARSE_CLIENT = Number.parseInt(process.env.REPORT_CONCURRENT_PARSE_CLIENTS || "3", 10);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -11,7 +13,7 @@ const MAX_CONCURRENT_PARSE_CLIENT = Number.parseInt(process.env.REPORT_CONCURREN
|
|||||||
* Description: Принимает на вход файл отчетов в формате Excel, парсит его, проверяет связи с БД,
|
* Description: Принимает на вход файл отчетов в формате Excel, парсит его, проверяет связи с БД,
|
||||||
* отдает идентификатор на статус парсинга.
|
* отдает идентификатор на статус парсинга.
|
||||||
*
|
*
|
||||||
* @type {import("#root/http-server/types/http-server.js").HttpRouteHandler}
|
* @type {HttpRouteHandler}
|
||||||
*/
|
*/
|
||||||
export default async (ctx) => {
|
export default async (ctx) => {
|
||||||
const { res, searchParams } = ctx;
|
const { res, searchParams } = ctx;
|
||||||
@ -72,4 +74,6 @@ export default async (ctx) => {
|
|||||||
} else {
|
} else {
|
||||||
throw new BadRequestError();
|
throw new BadRequestError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,14 +1,16 @@
|
|||||||
import { clients } from "#root/index.js";
|
import { clients } from "#root/index.js";
|
||||||
import crypto from "node:crypto";
|
import crypto from "node:crypto";
|
||||||
|
|
||||||
|
/** @import { HttpRouteHandler } from "#root/http-server/types/http-server.js" */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL: /api/reports_status_parse
|
* URL: /api/reports_status_parse
|
||||||
* Method: GET
|
* Method: GET
|
||||||
* Description: Отправляет частями в формате JSON информацию о текущем статусе парсинга отчетов
|
* Description: Отправляет частями в формате JSON информацию о текущем статусе парсинга отчетов
|
||||||
*
|
*
|
||||||
* @type {import("#root/http-server/types/http-server.js").HttpRouteHandler}
|
* @type {HttpRouteHandler}
|
||||||
*/
|
*/
|
||||||
export default (ctx) => {
|
export default async (ctx) => {
|
||||||
const { res } = ctx;
|
const { res } = ctx;
|
||||||
const clientId = crypto.randomUUID();
|
const clientId = crypto.randomUUID();
|
||||||
|
|
||||||
@ -30,4 +32,6 @@ export default (ctx) => {
|
|||||||
clients.delete(clientId);
|
clients.delete(clientId);
|
||||||
res.res.end();
|
res.res.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2,6 +2,8 @@ import { BadRequestError } from "#root/http-server/index.js";
|
|||||||
import { reportsService } from "#root/services/reports.service.js";
|
import { reportsService } from "#root/services/reports.service.js";
|
||||||
import { reportsSchema } from "#schemas/report.schema.js";
|
import { reportsSchema } from "#schemas/report.schema.js";
|
||||||
|
|
||||||
|
/** @import { HttpRouteHandler } from "#root/http-server/types/http-server.js" */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL: /api/reports_sync
|
* URL: /api/reports_sync
|
||||||
* Method: POST
|
* Method: POST
|
||||||
@ -16,4 +18,6 @@ export default async ({ res, data }) => {
|
|||||||
|
|
||||||
const rows = await reportsService.syncReportsWithDatabase(payload);
|
const rows = await reportsService.syncReportsWithDatabase(payload);
|
||||||
res.sendJson({ data: { rows } });
|
res.sendJson({ data: { rows } });
|
||||||
|
|
||||||
|
return;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { ReportModel } from "#models/index.js";
|
|||||||
import { ReportExecutorTable, ReportTable } from "#tables/index.js";
|
import { ReportExecutorTable, ReportTable } from "#tables/index.js";
|
||||||
import { UOW } from "./index.js";
|
import { UOW } from "./index.js";
|
||||||
|
|
||||||
/** @import { ReportColumns } from "#tables/report.table.js" */
|
/** @import { ReportColumns } from "#models/types.js" */
|
||||||
|
|
||||||
export const reportRepository = {
|
export const reportRepository = {
|
||||||
async getAll() {
|
async getAll() {
|
||||||
|
|||||||
@ -4,7 +4,7 @@ export class BaseTable {
|
|||||||
static tableName = "";
|
static tableName = "";
|
||||||
static table = new sql.Table(this.tableName);
|
static table = new sql.Table(this.tableName);
|
||||||
|
|
||||||
/** @type {Record<string, sql.ISqlType & sql.IColumnOptions>} */
|
/** @type {Record<string, { type: (() => sql.ISqlType) | sql.ISqlType } & sql.IColumnOptions>} */
|
||||||
static columns = {};
|
static columns = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,7 +23,6 @@ export class BaseTable {
|
|||||||
*/
|
*/
|
||||||
static init(table) {
|
static init(table) {
|
||||||
table = table || this.table;
|
table = table || this.table;
|
||||||
// TODO: fix types
|
|
||||||
Object.entries(this.columns).forEach(([name, { type, ...opts }]) => table.columns.add(name, type, opts));
|
Object.entries(this.columns).forEach(([name, { type, ...opts }]) => table.columns.add(name, type, opts));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user