forked from ttc/micro-service-api
budget & project apis: bruh
This commit is contained in:
@@ -41,7 +41,7 @@ export class budgetSearch {
|
|||||||
column = `bdgnam, bdgttl`
|
column = `bdgnam, bdgttl`
|
||||||
}
|
}
|
||||||
|
|
||||||
aryResult = await this.budgetSearchService.getBudgetSearch(database, id, column, condition);
|
aryResult = await this.budgetSearchService.getBudgetSearch(database, column, condition);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
idx = 1;
|
idx = 1;
|
||||||
|
|||||||
54
exthernal-ttc-api/src/controllers/projectSearchController.js
Normal file
54
exthernal-ttc-api/src/controllers/projectSearchController.js
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import { ProjectSearchService } from '../services/projectSearchService.js'
|
||||||
|
import { sendError } from '../utils/response.js'
|
||||||
|
// import { OftenError } from '../utils/oftenError.js'
|
||||||
|
import { GeneralService } from '../share/generalservice.js';
|
||||||
|
import { trim_all_array } from '../utils/trim.js'
|
||||||
|
import { verifyToken, generateToken } from '../utils/token.js'
|
||||||
|
|
||||||
|
export class projectSearch {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.generalService = new GeneralService();
|
||||||
|
this.projectSearchService = new ProjectSearchService();
|
||||||
|
}
|
||||||
|
|
||||||
|
async onNavigate(req, res) {
|
||||||
|
this.generalService.devhint(1, 'projectSearch.js', 'onNavigate() start');
|
||||||
|
let organization = req.body.organization;
|
||||||
|
const prommis = await this.onProjectSearch(req, res, organization);
|
||||||
|
return prommis;
|
||||||
|
}
|
||||||
|
|
||||||
|
async onProjectSearch(req, res, database) {
|
||||||
|
let idx = -1
|
||||||
|
let aryResult = []
|
||||||
|
let condition = {}
|
||||||
|
try {
|
||||||
|
// let username = req.body.request.username;
|
||||||
|
// let password = req.body.request.password;
|
||||||
|
let token = req.headers.authorization?.split(' ')[1];
|
||||||
|
const decoded = verifyToken(token);
|
||||||
|
|
||||||
|
let id = decoded.id
|
||||||
|
let username = decoded.name
|
||||||
|
database = decoded.organization
|
||||||
|
let columnParams = req.query.column
|
||||||
|
var column = ""
|
||||||
|
if(columnParams == 'edit'){
|
||||||
|
column = `prjnam, prjwntbdg`
|
||||||
|
condition['prjseq'] = req.body.request.bdgseq
|
||||||
|
} else if(columnParams == 'result' || columnParams == undefined || columnParams == ''){
|
||||||
|
column = `prjnam, prjttl`
|
||||||
|
}
|
||||||
|
|
||||||
|
aryResult = await this.projectSearchService.getProjectSearch(database, id, column, condition);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
idx = 1;
|
||||||
|
} finally {
|
||||||
|
if (idx === 1) return sendError('เกิดข้อผิดพลาดไม่คาดคิดเกิดขึ้น', 'Unexpected error');
|
||||||
|
if (aryResult == 0) return sendError('ไม่พบการมีอยู่ของข้อมูล', 'Cannot Find Any Data');
|
||||||
|
return aryResult
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,13 +2,15 @@ import express from 'express'
|
|||||||
// import { budgetSetup } from '../controllers/budgetSetupController.js'
|
// import { budgetSetup } from '../controllers/budgetSetupController.js'
|
||||||
import { budgetSearch } from '../controllers/budgetSearchController.js'
|
import { budgetSearch } from '../controllers/budgetSearchController.js'
|
||||||
import { budgetAdd } from '../controllers/budgetAddController.js'
|
import { budgetAdd } from '../controllers/budgetAddController.js'
|
||||||
|
import { projectSearch } from '../controllers/projectSearchController.js'
|
||||||
|
|
||||||
// import { authMiddleware } from '../middlewares/auth.js'
|
// import { authMiddleware } from '../middlewares/auth.js'
|
||||||
// import { sendResponse } from '../utils/response.js'
|
// import { sendResponse } from '../utils/response.js'
|
||||||
|
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
const controller_projectSearch_post = new projectSearch()
|
||||||
const controller_budgetSearch_post = new budgetSearch()
|
const controller_budgetSearch_post = new budgetSearch()
|
||||||
const controller_budgetAdd_put = new budgetAdd()
|
const controller_budgetAdd_post = new budgetAdd()
|
||||||
|
|
||||||
// router.post('/budgetSetup', async (req, res) => {
|
// router.post('/budgetSetup', async (req, res) => {
|
||||||
// const result = await controller_budgetSetup_post.onNavigate(req, res)
|
// const result = await controller_budgetSetup_post.onNavigate(req, res)
|
||||||
@@ -16,7 +18,7 @@ const controller_budgetAdd_put = new budgetAdd()
|
|||||||
// })
|
// })
|
||||||
|
|
||||||
router.post('/budgetadd', async (req, res) => {
|
router.post('/budgetadd', async (req, res) => {
|
||||||
const result = await controller_budgetAdd_put.onNavigate(req, res)
|
const result = await controller_budgetAdd_post.onNavigate(req, res)
|
||||||
if (result) return res.json(result)
|
if (result) return res.json(result)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -25,10 +27,10 @@ router.post('/budgetsearch', async (req, res) => {
|
|||||||
if (result) return res.json(result)
|
if (result) return res.json(result)
|
||||||
})
|
})
|
||||||
|
|
||||||
// router.get('/projectsearch', async (req, res) => {
|
router.post('/projectsearch', async (req, res) => {
|
||||||
// const result = await controller_budgetSetup_post.onNavigate(req, res)
|
const result = await controller_projectSearch_post.onNavigate(req, res)
|
||||||
// if (result) return res.json(result)
|
if (result) return res.json(result)
|
||||||
// })
|
})
|
||||||
|
|
||||||
// router.put('/budgetexpense', async (req, res) => {
|
// router.put('/budgetexpense', async (req, res) => {
|
||||||
// const result = await controller_budgetSetup_post.onNavigate(req, res)
|
// const result = await controller_budgetSetup_post.onNavigate(req, res)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export class BudgetSearchService {
|
|||||||
this.generalService = new GeneralService()
|
this.generalService = new GeneralService()
|
||||||
}
|
}
|
||||||
|
|
||||||
async getBudgetSearch(database, id, column, condition) {
|
async getBudgetSearch(database, column, condition) {
|
||||||
const sql = `
|
const sql = `
|
||||||
SELECT
|
SELECT
|
||||||
${column}
|
${column}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { GeneralService } from '../share/generalservice.js'
|
||||||
|
|
||||||
|
export class ProjectSearchService {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.generalService = new GeneralService()
|
||||||
|
}
|
||||||
|
|
||||||
|
async getProjectSearch(database, id, column, condition) {
|
||||||
|
const sql = `
|
||||||
|
SELECT
|
||||||
|
${column}
|
||||||
|
FROM ${database}.prjmst
|
||||||
|
WHERE 1=1
|
||||||
|
`
|
||||||
|
const params = []
|
||||||
|
const result = await this.generalService.executeQueryConditions(database, sql, condition);
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// bdgseq,
|
||||||
|
// bdgnam,
|
||||||
|
// bdgcod,
|
||||||
|
// bdgttl,
|
||||||
|
// bdgedtdtm
|
||||||
Reference in New Issue
Block a user