diff --git a/handlers/reports/parseExcel.handler.js b/handlers/reports/parseExcel.handler.js index 7bedf74..260d7cd 100644 --- a/handlers/reports/parseExcel.handler.js +++ b/handlers/reports/parseExcel.handler.js @@ -156,9 +156,13 @@ async function checkReportAssigments(report, callback, rejectCond) { const executorSurnames = extractSurnamesFromExecutorField(report.executorNames); - const equipment = await db - .request() - .query(`select id, name from dbo.asu_system_api_subsystemlist where name like N'%${report.equipment}%';`); + const equipment = await db.request() + .query(`select t1.id, t1.name, t1.location_id, t3.name as base_location_name, t2.name as location_name, t2.base_location_id + from dbo.asu_system_api_subsystemlist as t1 + left join dbo.asu_system_api_location as t2 on t2.id = t1.location_id + left join dbo.asu_system_api_baselocation as t3 on t3.id = t2.base_location_id + where t1.name like N'%${report.equipment}%'; + `); const applicant = await db .request() @@ -185,10 +189,20 @@ async function checkReportAssigments(report, callback, rejectCond) { const hasEquipmentLink = equipment.recordset.length !== 0; const hasApplicantLink = applicant.recordset.length !== 0; + const location = + hasEquipmentLink && equipment.recordset[0].location_id + ? { + id: equipment.recordset[0].location_id, + name: equipment.recordset[0].location_name, + base_location_name: equipment.recordset[0].base_location_name, + base_location: equipment.recordset[0].base_location_id + } + : null; + callback({ ...report, executors, - equipment: hasEquipmentLink ? { id: equipment.recordset[0].id, name: equipment.recordset[0].name } : null, + equipment: hasEquipmentLink ? { id: equipment.recordset[0].id, name: equipment.recordset[0].name, location } : null, applicant: hasApplicantLink ? { id: applicant.recordset[0].id, name: applicant.recordset[0].name } : null }); } diff --git a/index.js b/index.js index 31e0f27..9d51395 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ import path from "node:path"; +import fsp from "node:fs/promises"; import { createServer } from "./http-server/index.js"; import { reportsHandlers } from "./handlers/index.js"; import packageJson from "./package.json" with { type: "json" }; @@ -41,5 +42,6 @@ export const routeMap = { createServer({ routeMap, enableCors: true }).listen(SERVER_PORT, async () => { console.log(`Service ${packageJson.name} is running at port ${SERVER_PORT}.`); + await fsp.mkdir(path.join(process.cwd(), "/uploads"), { recursive: true }); await db.connect().then(() => console.log("Database connected!")); }); diff --git a/models.d.ts b/models.d.ts index 6e039f5..ee8fec3 100644 --- a/models.d.ts +++ b/models.d.ts @@ -1,6 +1,13 @@ type ReportModel = { date: string; - equipment?: string | { id: string; name: string } | null; + equipment?: + | string + | { + id: string; + name: string; + location: { id: string; name: string; base_location_name: string; base_location: string } | null; + } + | null; applicant?: string | { id: string; name: string } | null; reason_call: string; job_description: string;