Skip to content

2way-batch — Persistence & Integrations

บทนี้อธิบายชั้นข้อมูลและการเชื่อมต่อภายนอกของ 2way-batch (branch: master) — MSSQL ผ่าน TypeORM, ตารางที่ cron อ้างถึง, และการยิง LINE ผ่าน HTTP hardcode

ดู wiring ที่ 01-repository-map และ cron flow ที่ 02-core-pipeline


Database connection

Connection เดียวชื่อ 'main':

รายการค่าอ้างอิง
Drivermssqlapp.module.ts:21
CredentialsDB_HOST / DB_PORT / DB_USER / DB_PASSWORD / DB_NAMEconfiguration.ts:4-10app.module.ts:22-26
synchronizefalseapp.module.ts:27
logging['error','query']app.module.ts:28
TLS encryptfalseapp.module.ts:32
trustServerCertificatetrueapp.module.ts:31

ไม่มีหลักฐานใน git ว่า DB_NAME production คืออะไร — ไม่มี .env.example

TypeORM โหลด entity ทุกไฟล์ใต้ src/**/*.entity{.ts,.js} (app.module.ts:29) — รวม complaint/announce entities ที่ cron ไม่แตะ


Entity inventory (25 ไฟล์)

ไฟล์ตาราง / หมายเหตุใช้โดย cron path?
t_content.entity.tst_contentใช่ (query หลัก)
t_content_assign.entity.tst_content_assignใช่
t_content_status.entity.tst_content_statusใช่
t_content_flow_history.entity.tst_content_flow_historyใช่
m_content_type.entity.tsm_content_typeใช่
m_content_flow.entity.tsm_content_flowใช่
m_status.entity.tsm_statusใช่ (+ initializer)
m_config.entity.tsm_configใช่ (list.empCode.hrAdmin)
userLine.entity.tsuserLineใช่ (LINE id lookup)
m_error_message.entity.tserror messagesinitializer ของ SurveysUtil
t_send_notify.entity.tsnotifyไม่ใน cron methods ปัจจุบัน
t_content_manager.entity.ts / m_user_manager.entity.ts / m_topic.entity.ts / m_role.entity.tsmanager/topic/roleไม่ใน cron
*_complaint*.entity.ts (หลายไฟล์)complaint domainไม่ — module ไม่ mount
base.tsBaseEntityใช้ร่วม

TContent (ตัวอย่างคอลัมน์หลัก)

topic_name, offer_date, link_url, tot_assign, relations ไป type/assign/status/flow (t_content.entity.ts:10-50)

UserLine

ตาราง userLine — คอลัมน์ userID, lineID, richMenuID, isActive (userLine.entity.ts:3-24)

Lookup ใน cron: where userID = :empCode (surveys.repository.ts:591-593)

MConfig

ตาราง m_configmodule, name, value (m_config.entity.ts:4-16)

HR admin list: findOne where name = 'list.empCode.hrAdmin' (surveys.repository.ts:587-589, surveys.constant.ts:10) — ค่าเป็น string คั่นด้วย comma แล้ว split ใน cron (survey.task.service.ts:143)


Survey flow short names (constants + config maps)

จาก SurveysConstant (surveys.constant.ts:2-10):

Constantค่าความหมายในโค้ด
CONTENT_TYPEsurveyfilter m_content_type.name_en
SHORT_NAME_IN_SCOPEACScreate in-scope (stub method ชื่ออ้าง)
SHORT_NAME_OUT_SCOPEACDused by fetchCreateOutScope
SHORT_NAME_HR_ADMIN_APPROVEDHAPused by fetchApproval
CREATE_CODES00status code filter out-scope path

configuration.ts มี map contentStatus.survey.* ซ้ำความหมายเดียวกันแบบ static (configuration.ts:19-40) — cron อ่านจาก SurveysConstant + DB maps ของ SurveysUtil เป็นหลัก ไม่ได้อ่าน object นี้ตรง ๆ ใน survey.task.service.ts


SurveysUtil initializer — in-memory maps

เมื่อ SurveysService ถูกสร้าง (ผ่าน SurveyTaskModule providers):

typescript
constructor(..., private readonly dao: SurveysRepository) {
  SurveysUtil.initializer(entityManager);
}

แหล่ง: surveys.service.ts:21-27

initializer โหลด (surveys.util.ts:25-62):

  1. MContentFlow short_name ACS / ACD
  2. ทุก MStatus ที่ group_name = 'survey' และ is_active = 1 → map ตาม mapping และ code
  3. ทุก MErrorMessage ที่ active
  4. ทุก MContentFlow ที่ group_name = 'Survey'

getActionCodeByName คืน .code จาก map (surveys.util.ts:125-128) — ใช้ใน dead cron methods และใน updateSurveys

ถ้า DB ยังไม่พร้อมตอน boot — map ว่าง → การเปิด fetchApproval จะ fail เมื่อเรียก getActionCodeByName


Repository helpers ที่ cron พึ่งพา

MethodSQL / behaviorอ้างอิง
findAllContentAssignBySurveyIdTContentAssign where content_idsurveys.repository.ts:663-665
findLineIDAsEmpCodeUserLine where userIDsurveys.repository.ts:591-593
findEmployeeCodeOfHrAdminMConfig where name keysurveys.repository.ts:587-589
updateSurvey (ผ่าน service)insert flow history + update statusเรียกจาก updateSurveys

หมายเหตุ: findByConditionV2 ใน repository มี raw SQL string ที่ interpolate dto.empCode (surveys.repository.ts:70) — ไม่ถูกเรียกจาก cron และ controller surveys ไม่ได้ mount — แต่เป็น debt ถ้า uncomment SurveysModule (QUAL-2WAYBATCH-04)


Outbound integration — LINE via hardcoded HTTP

Batch ไม่ได้เรียก https://api.line.me โดยตรงใน LineService

SurveyTaskService
  → LineService.pushMassage
  → POST http://10.188.128.126:9340/2way-batch/api/v1/line

แหล่ง: line.service.ts:17-41

รายการค่าที่พิสูจน์ได้
Host10.188.128.126 (hardcode)
Port9340
Path/2way-batch/api/v1/line
Body{ replyToken, messages }
Success status expected201
Env overrideไม่มี

เปรียบเทียบกับ 2way-line-service ที่เรียก LINE API จริงด้วย LINE_AUTH_TOKEN (ดูเอกสาร volume ของ line-service) — คนละ hop

config.lineToken / LINE_AUTH_TOKEN ใน configuration.ts:11 ไม่ได้ถูกอ่าน ใน 2way-batch/src/modules/line/line.service.ts


Inbound — nginx path vs Nest prefix

LayerPathอ้างอิง
nginx location/2way-batch/ → strip ไป :9340/nginx/conf.d/default.conf:3-8
Nest global prefix${BASE_PATH}api/v1main.ts:23-25
Hardcoded push URLรวม /2way-batch/api/v1/lineline.service.ts:26

ถ้า BASE_PATH ที่ process จริงว่าง หรือเป็นค่าอื่น — path ที่ hardcode อาจไม่ตรงกับ route จริงของตัวเองหรือของ gateway อื่น เป็น UNVERIFIED ที่ runtime


สิ่งที่ไม่มีใน repo นี้

รายการสถานะ
.env.exampleไม่มี
docker-compose.ymlไม่มี
การเรียก CENTRALIZE_SERVER / cu-central / vtrc-apiไม่พบในซอร์ส cron/line ของ batch
Direct LINE Messaging APIไม่มีใน LineService ของ batch

สิ่งที่อยู่นอกขอบเขตบทนี้