Add business logic
หมายเหตุ: บทความนี้ยังเป็นภาษาอังกฤษ เนื่องจากคำแปลภาษาไทยกำลังอยู่ระหว่างจัดทำ
Purpose
หัวข้อที่มีชื่อว่า “Purpose”Choose the smallest server-side mechanism that matches the behavior and keeps authorization, validation, and transactions consistent.
Audience
หัวข้อที่มีชื่อว่า “Audience”Application developers and reviewers.
Prerequisites
หัวข้อที่มีชื่อว่า “Prerequisites”An application with its tables, permissions, and metadata workflow defined.
Choose the mechanism
หัวข้อที่มีชื่อว่า “Choose the mechanism”| Behavior | Use |
|---|---|
| Record defaults or validation | Hooks and data events |
| Pre/post lifecycle behavior | Hooks and data events |
| Explicit user operation | Function/action |
| Several related registrations | Script |
| Bounded HTTP or email integration | Async Function/action |
| Other native or reusable integration | Reviewed TypeScript |
Execute related writes inside a transaction through DataContext. A transactional Function is synchronous and atomic. An async Function may await the built-in HTTP and email services, but it must use short explicit ctx.tts() blocks for database writes. Keep validation deterministic, never await network calls inside database transactions, and enforce authorization on the server even when the client hides an action.
Testing
หัวข้อที่มีชื่อว่า “Testing”Test success, rejection, rollback, unauthorized access, and concurrent behavior. See Run tests and debug.