first commit

This commit is contained in:
Mojtaba Khorshidkolah
2026-03-05 09:39:35 +03:30
commit a9bd7e890a
9 changed files with 2195 additions and 0 deletions

23
config/controller.js Normal file
View File

@@ -0,0 +1,23 @@
const ServiceHandler = require('./service')
class ControllerHandlerClass {
async getData(req,res,next){
try {
const data = await ServiceHandler.getData();
return res.status(200).json({
status:200,
data,
message:"Ok"
})
} catch (error) {
console.log(error)
next('Server Error ')
}
}
}
const ControllerHandler = new ControllerHandlerClass();
module.exports =ControllerHandler;

31
config/db.js Normal file
View File

@@ -0,0 +1,31 @@
const mssql = require('mssql')
const dotenv = require('dotenv').config()
let pool;
const sqlConfig = {
user:process.env.DB_USER,
password:process.env.DB_PASSWORD,
database:process.env.DB,
server:process.env.SERVER,
port:1433,
pool:{
max:10,
min:0,
idleTimeoutMillis:30000
},
options:{
encrypt:false,
trustServerCertificate:false,
}
}
async function initPool(){
if(pool) return pool;
pool= await mssql.connect(sqlConfig);
return pool;
}
module.exports = {initPool};

9
config/router.js Normal file
View File

@@ -0,0 +1,9 @@
const ControllerHandler =require('./controller')
const express = require('express')
const router = express.Router();
router.get('/get',ControllerHandler.getData)
module.exports = router;

25
config/service.js Normal file
View File

@@ -0,0 +1,25 @@
const {initPool} = require("./db") ;
class ServiceHanlderClass {
async getData(){
const pool = await initPool();
try {
const result = await pool.request().query("EXEC TDP.dbo.SP_ListFullPatientStatus01 ");
// await pool.close();
// pool=null;
// console.log('closed')
return result;
} catch (error) {
console.log(error)
throw new Error(error)
}
}
}
const ServiceHandler = new ServiceHanlderClass();
module.exports = ServiceHandler;