690412:1716 Done Task-FE-AI-03
CI / CD Pipeline / build (push) Failing after 7m53s
CI / CD Pipeline / deploy (push) Has been skipped

This commit is contained in:
2026-04-12 17:16:37 +07:00
parent ca0454a043
commit 02400fd88c
8 changed files with 514 additions and 180 deletions
@@ -1,7 +1,7 @@
# Code Snippets
**Version:** 1.8.4
**Last Updated:** 2026-03-24
**Version:** 1.8.6
**Last Updated:** 2026-04-10
**Location:** `specs/05-Engineering-Guidelines/05-06-code-snippets.md`
---
@@ -92,6 +92,68 @@ return entity;
---
## Workflow Transition Pattern
```typescript
// [workflow-transition] → Pattern สำหรับการเปลี่ยนสถานะเอกสารอย่างปลอดภัย
// ใช้ใน: WorkflowEngineService
async transitionStatus(
publicId: string, // รับ UUIDv7 เท่านั้น (ADR-019)
targetStatus: DocumentStatus,
actor: RequestWithUser
): Promise<Document> {
// 1. ค้นหา Entity ด้วย publicId และตรวจสอบการมีอยู่
const document = await this.repo.findOne({
where: { publicId },
relations: ['currentAssignee'],
});
if (!document) {
this.logger.warn(`ไม่พบเอกสาร UUID: ${publicId}`, 'WorkflowService');
throw new NotFoundException(ErrorCode.DOC_NOT_FOUND);
}
// 2. ตรวจสอบว่า transition นี้ถูกต้องตาม DSL (ADR-001)
await this.workflowEngine.validateTransition(document.workflowState, targetStatus);
// 3. Business Logic Validation: ตรวจสอบสิทธิ์ผู้รับผิดชอบ
if (document.currentAssignee?.publicId !== actor.user.publicId) {
throw new ForbiddenException(ErrorCode.UNAUTHORIZED_TRANSITION);
}
// 4. ปรับปรุงสถานะและใช้ @VersionColumn ใน Entity เพื่อทำ Optimistic Locking
try {
document.status = targetStatus;
document.updatedBy = actor.user.publicId;
const savedDoc = await this.repo.save(document);
// 5. บันทึก Audit Log
this.logger.log(
`เอกสาร ${publicId} เปลี่ยนสถานะเป็น ${targetStatus} โดย ${actor.user.publicId}`
);
// 6. ส่งงานเข้า Queue (BullMQ) สำหรับการส่ง Notification/Email (ADR-008)
await this.notificationQueue.add('status-change', {
docId: savedDoc.publicId,
status: targetStatus,
recipientPublicId: savedDoc.creatorPublicId, // ใช้ publicId ตาม ADR-019
});
return savedDoc;
} catch (error) {
if (error instanceof OptimisticLockVersionMismatchError) {
// ป้องกันการแก้ไขซ้ำซ้อนในเวลาเดียวกัน (Race Condition)
throw new ConflictException('ข้อมูลถูกแก้ไขโดยผู้อื่นไปก่อนหน้าแล้ว กรุณารีเฟรชหน้าจอ');
}
throw error;
}
}
```
---
## Reference
- [Backend Guidelines](05-02-backend-guidelines.md)
+48 -5
View File
@@ -10,9 +10,9 @@
| Attribute | Value |
| ------------------ | -------------------------------- |
| **Version** | 1.8.1 |
| **Version** | 1.8.6 |
| **Status** | Active |
| **Last Updated** | 2026-03-16 |
| **Last Updated** | 2026-04-10 |
| **Owner** | Nattanin Peancharoen |
| **Classification** | Internal Technical Documentation |
@@ -29,6 +29,10 @@
- [2. Backend Guidelines](#2-backend-guidelines)
- [3. Frontend Guidelines](#3-frontend-guidelines)
- [4. Document Numbering System](#4-document-numbering-system)
- [5. Git Conventions](#5-git-conventions)
- [6. Code Snippets](#6-code-snippets)
- [7. UUID Implementation Plan](#7-uuid-implementation-plan)
- [8. i18n Guidelines](#8-i18n-guidelines)
- [🧪 Testing Strategy](#-testing-strategy)
- [🛠️ Technology Stack Recap](#-technology-stack-recap)
- [🔗 Related Documents](#-related-documents)
@@ -79,7 +83,7 @@
- React Hook Form + Zod for Client Validation
- API Client Interceptors (Auth & Idempotency)
### 4. [Document Numbering System](../01-Requirements/business-rules/01-02-02-doc-numbering-rules.md)
### 4. [Document Numbering System](../01-Requirements/01-02-business-rules/01-02-02-doc-numbering-rules.md)
**รายละเอียดการนำระบบออกเลขที่เอกสารไปใช้งาน**
@@ -88,6 +92,45 @@
- Reservation Flow (Phase 1: Reserve, Phase 2: Confirm)
- API Specs for Numbering Management
### 5. [Git Conventions](./05-05-git-conventions.md)
**มาตรฐานการใช้ Git และ Commit Messages**
- Branch Naming (feature/, fix/, hotfix/)
- Commit Message Format (Conventional Commits)
- PR/Merge กระบวนการ
- [Git Cheatsheet](./05-05-git-cheatsheet.md) — คำสั่งที่ใช้บ่อย
### 6. [Code Snippets](./05-06-code-snippets.md)
**ตัวอย่างโค้ดที่ใช้ซ้ำบ่อย (Reusable Patterns)**
- Backend DTO Pattern with `@IsUUID()`
- Frontend RHF + Zod Form Pattern
- UUID Safe Pattern
- Backend Error Handling Pattern
- Workflow Transition Pattern
- Redis Cache Pattern
- Frontend TanStack Query Pattern
### 7. [UUID Implementation Plan](./05-07-hybrid-uuid-implementation-plan.md)
**แผนการ Implement Hybrid Identifier (ADR-019)**
- Migration Strategy (INT → UUIDv7)
- Backend: `UuidBaseEntity` Pattern
- Frontend: `publicId` Usage Guidelines
- API Response Standardization
### 8. [i18n Guidelines](./05-08-i18n-guidelines.md)
**แนวทางการทำ Localization**
- i18n Key Structure (Thai/English)
- Error Message Keys vs Hardcoded Text
- Frontend Locale Organization
- Comments Language Policy (Thai for business, English for technical)
---
## 🧪 Testing Strategy
@@ -123,9 +166,9 @@
<div align="center">
**LCBP3-DMS Implementation Specification v1.8.1**
**LCBP3-DMS Implementation Specification v1.8.6**
[FullStack](./05-01-fullstack-js-guidelines.md) • [Backend](./05-02-backend-guidelines.md) • [Frontend](./05-03-frontend-guidelines.md) • [Testing](./05-04-testing-strategy.md)
[FullStack](./05-01-fullstack-js-guidelines.md) • [Backend](./05-02-backend-guidelines.md) • [Frontend](./05-03-frontend-guidelines.md) • [Testing](./05-04-testing-strategy.md) • [Git](./05-05-git-conventions.md) • [Snippets](./05-06-code-snippets.md) • [UUID](./05-07-hybrid-uuid-implementation-plan.md) • [i18n](./05-08-i18n-guidelines.md)
[Main README](../../README.md) • [Architecture](../02-Architecture/README.md) • [Requirements](../01-Requirements/README.md)
+11 -5
View File
@@ -1,7 +1,7 @@
# Architecture Decision Records (ADRs)
**Version:** 1.8.2
**Last Updated:** 2026-04-04
**Version:** 1.8.5
**Last Updated:** 2026-04-10
**Project:** LCBP3-DMS (Laem Chabang Port Phase 3 - Document Management System)
---
@@ -50,6 +50,7 @@ Architecture Decision Records (ADRs) เป็นเอกสารที่บ
| ADR | Title | Status | Date | Summary |
| --------------------------------------------------- | ------------------------------------ | --------------------- | ---------- | --------------------------------------------------------------- |
| [ADR-004](./ADR-004-database-schema-design-strategy.md) | Database Schema Design Strategy | ✅ Accepted | 2026-04-04 | Selective Normalization + Standard Patterns (UUID, Soft Delete, Audit) |
| [ADR-005](./ADR-005-technology-stack.md) | Technology Stack Selection | ✅ Accepted | 2026-02-24 | Full Stack TypeScript: NestJS 11 + Next.js 16 + MariaDB + Redis |
| [ADR-006](./ADR-006-redis-caching-strategy.md) | Redis Usage & Caching Strategy | ✅ Accepted | 2026-02-24 | Redis สำหรับ Distributed Lock, Cache, Queue, และ Rate Limiting |
| [ADR-009](./ADR-009-database-migration-strategy.md) | Database Migration & Deployment | ✅ Accepted (Pending) | 2026-02-24 | TypeORM Migrations พร้อม Blue-Green Deployment |
@@ -59,6 +60,8 @@ Architecture Decision Records (ADRs) เป็นเอกสารที่บ
| ADR | Title | Status | Date | Summary |
| --------------------------------------------------- | ----------------------------- | ---------------------------- | ---------- | ----------------------------------------------------------------------------- |
| [ADR-003](./ADR-003-api-design-strategy.md) | API Design Strategy | ✅ Accepted | 2026-04-04 | Hybrid REST + Action Strategy สำหรับ Resource และ Workflow Operations |
| [ADR-007](./ADR-007-error-handling-strategy.md) | Error Handling & Recovery | ✅ Accepted | 2026-04-04 | Layered Error Classification พร้อม User-friendly Messages และ Recovery Actions |
| [ADR-008](./ADR-008-email-notification-strategy.md) | Email & Notification Strategy | ✅ Accepted (Pending Review) | 2026-02-24 | BullMQ + Redis Queue สำหรับ Multi-channel Notifications (Email, LINE, In-app) |
### Observability
@@ -113,12 +116,15 @@ Architecture Decision Records (ADRs) เป็นเอกสารที่บ
### 4. Infrastructure & Performance
- **ADR-004:** Database Schema Design - Selective Normalization + Standard Patterns
- **ADR-005:** Technology Stack - TypeScript ecosystem (NestJS 11, Next.js 16)
- **ADR-006:** Redis - Caching และ Distributed coordination
- **ADR-015:** Deployment - Docker Compose with Blue-Green Deployment
### 5. API & Integration
- **ADR-003:** API Design - Hybrid REST + Action Strategy สำหรับ Resource และ Workflow Operations
- **ADR-007:** Error Handling - Layered Classification (Validation / Business / System) พร้อม Recovery Actions
- **ADR-008:** Notification - BullMQ Queue สำหรับ Multi-channel notifications
### 6. Observability & Monitoring
@@ -369,9 +375,9 @@ graph TB
---
**Version:** 1.8.2 (Enhanced Template + Review Process)
**Last Review:** 2026-04-04
**Next Review:** 2026-10-04
**Version:** 1.8.5 (Added ADR-003, ADR-004, ADR-007)
**Last Review:** 2026-04-10
**Next Review:** 2026-10-10
---