budget & project apis: bruh

This commit is contained in:
HAPFEX
2025-11-17 16:28:42 +07:00
parent a0295a160c
commit b31682c041
6 changed files with 90 additions and 8 deletions

View File

@@ -41,7 +41,7 @@ export class budgetSearch {
column = `bdgnam, bdgttl`
}
aryResult = await this.budgetSearchService.getBudgetSearch(database, id, column, condition);
aryResult = await this.budgetSearchService.getBudgetSearch(database, column, condition);
} catch (error) {
idx = 1;

View 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
}
}
}