diff --git a/ems/package-lock.json b/ems/package-lock.json index 5c68257..6fe8748 100644 --- a/ems/package-lock.json +++ b/ems/package-lock.json @@ -13,7 +13,7 @@ "axios": "^1.7.4", "body-parser": "^1.20.2", "cors": "^2.8.5", - "dotenv": "^16.4.5", + "dotenv": "^16.4.7", "express": "^4.19.2", "express-validator": "^7.2.0", "ioredis": "^5.4.1", @@ -1525,9 +1525,9 @@ } }, "node_modules/dotenv": { - "version": "16.4.5", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", - "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "version": "16.4.7", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", + "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", "engines": { "node": ">=12" }, diff --git a/ems/package.json b/ems/package.json index 9879497..299e7f8 100644 --- a/ems/package.json +++ b/ems/package.json @@ -17,7 +17,7 @@ "axios": "^1.7.4", "body-parser": "^1.20.2", "cors": "^2.8.5", - "dotenv": "^16.4.5", + "dotenv": "^16.4.7", "express": "^4.19.2", "express-validator": "^7.2.0", "ioredis": "^5.4.1", diff --git a/ems/src/api/general/index.ts b/ems/src/api/general/index.ts index 84f9d1f..07e2bbe 100644 --- a/ems/src/api/general/index.ts +++ b/ems/src/api/general/index.ts @@ -1,6 +1,6 @@ import express, { Request, Response } from 'express'; import { tediousQuery } from '../../utils/tedious'; -import { GeneralDB } from '../../constants/db'; +import { GeneralDB, GisDB } from '../../constants/db'; const router = express.Router() router.get('/regions/all', async (req: Request, res: Response) => { @@ -120,7 +120,7 @@ router.get('/objects/list', async (req: Request, res: Response) => { type_id, CAST(LEFT(caption_params, CHARINDEX(',', caption_params + ',') - 1) AS VARCHAR(255)), -- Explicitly casting to VARCHAR STUFF(caption_params, 1, CHARINDEX(',', caption_params + ','), '') - FROM New_Gis..caption_params + FROM ${GisDB}..caption_params WHERE city_id = -1 AND user_id = -1 UNION ALL @@ -143,7 +143,7 @@ router.get('/objects/list', async (req: Request, res: Response) => { FROM ${GeneralDB}..vObjects o JOIN cte_split c ON o.type = c.type_id JOIN ${GeneralDB}..tParameters p ON p.id = split_value - JOIN ${GeneralDB}..tValues v + LEFT JOIN ${GeneralDB}..tValues v ON v.id_param = split_value AND v.id_object = o.object_id diff --git a/ems/src/index.ts b/ems/src/index.ts index a7dc3f9..62feece 100644 --- a/ems/src/index.ts +++ b/ems/src/index.ts @@ -6,6 +6,7 @@ import gisRouter from './api/gis' import nodesRouter from './api/nodes' import tilesRouter from './api/tiles' import staticRouter from './api/static' +import 'dotenv/config' const app = express() const PORT = process.env.EMS_PORT || 5000 diff --git a/ems/src/utils/tedious.ts b/ems/src/utils/tedious.ts index 6dc2704..799bcea 100644 --- a/ems/src/utils/tedious.ts +++ b/ems/src/utils/tedious.ts @@ -1,25 +1,30 @@ import { Connection, ConnectionConfiguration, Request } from "tedious"; +import 'dotenv/config' + +const MSSQL_HOST = process.env.MSSQL_HOST || 'localhost' +const MSSQL_LOGIN = process.env.MSSQL_LOGIN || 'sa' +const MSSQL_PASSWORD = process.env.MSSQL_PASSWORD || '' +const MSSQL_DB = process.env.MSSQL_DB || 'nGeneral' +const MSSQL_PORT = Number(process.env.MSSQL_PORT) || 1433 const tediousConfig: ConnectionConfiguration = { - server: 'localhost', + server: MSSQL_HOST, options: { trustServerCertificate: true, - port: 1433, - database: 'nGeneral' + port: MSSQL_PORT, + database: MSSQL_DB }, authentication: { type: 'default', options: { - userName: 'SA', - password: 'oMhthmsvbYHc' + userName: MSSQL_LOGIN, + password: MSSQL_PASSWORD } } } export function tediousQuery(query: string) { // Read all rows from table - - return new Promise((resolve, reject) => { const connection = new Connection(tediousConfig)