Skip to main content

คุณสมบัติระดับระบบ (System Attribute)

ภาพรวม

System Attribute คือ attribute มาตรฐานที่ระบบนิยามไว้ส่วนกลาง ไม่ใช่สิ่งที่ลูกค้าตั้งขึ้นเอง จึงต่างจาก Attribute Master ซึ่งเป็น custom attribute แยกตาม LINE OA

attribute กลุ่มนี้ทำหน้าที่เป็นชุด attribute พื้นฐานที่ทุก OA มีเหมือนกัน เช่น field มาตรฐาน ของ LINE profile หรือ attribute ที่ใช้ประกอบเป็น merge tag ระบบใน Template Message

ในเชิงโครงสร้างเป็นโมดูล CRUD ที่เรียบง่าย มีเพียง 4 endpoint

Business Flow

  1. ดูรายการGET /api/system-attribute คืน attribute ระบบทั้งหมด โดย GORM เติมเงื่อนไข deleted_date IS NULL ให้อัตโนมัติ เพราะ entity ประกาศ gorm.DeletedAt
  2. สร้างใหม่POST /api/system-attribute สร้าง attribute ระบบด้วย CreateSystemAttributeDto
  3. แก้ไขPUT /api/system-attribute/:id การอัปเดตต้องใช้ Unscoped() เพราะระบบเดิมที่เขียนด้วย TypeORM ไม่ได้ใส่ soft-delete filter ในคำสั่ง update() จึงต้องทำให้ตรงกันเพื่อรักษา behavior parity
  4. ลบDELETE /api/system-attribute/:id เป็นการ soft delete
  5. การนำไปใช้ — ผลลัพธ์ถูกนำไปใช้ต่อสองทางหลัก คือ GET /api/template-message/merge-tags?showSystem=true ที่รวม attribute ระบบเข้าไปในรายการ merge tag และการประกอบร่วมกับ custom attribute เวลาสร้างฟอร์มหรือรายงาน

ไฟล์และฟังก์ชันหลัก

โค้ดอยู่ที่ internal/modules/systemattribute/ ประกอบด้วย controller.go, service.go และ dto.go

Route ทั้งหมดลงทะเบียนบน authed.Group("/system-attribute")

MethodRouteHandlerPolicy
GET/api/system-attributeh.findAllread system-attribute
POST/api/system-attributeh.createcreate system-attribute
PUT/api/system-attribute/:idh.updateupdate system-attribute
DELETE/api/system-attribute/:idh.removedelete system-attribute

โมดูลนี้ ไม่มี ModuleGate และไม่มี SuperAdminGuard ครอบ ผู้เรียกเพียงต้องผ่าน global JwtAuth เท่านั้น

จุดเชื่อมต่อกับ Service อื่น

  • Permission — ต้องผ่าน global JwtAuth ซึ่งบังคับให้มี lineOaId ใน token ส่วน PolicyModuleSystemAttribute ยังเป็นเพียง metadata และไม่ได้บังคับใช้
  • ตารางที่เกี่ยวข้องsystem_attribute ซึ่งใช้ soft delete ผ่าน gorm.DeletedAt
  • ผู้บริโภคข้อมูล — Template Message (สำหรับ merge tag ระบบ), Form Builder และรายงานเพื่อนทั้งหมด
  • เปรียบเทียบ — Attribute Master ทำหน้าที่เดียวกันแต่เป็น custom attribute แยกตาม OA