interns_playground — Repository Map & API Surface
บทนี้ (branch: main) แผนที่โค้ดและรายการ route ที่ mount จริงใน server.ts
โครงสร้าง
interns_playground/ (branch: main)
├── package.json # name: todo-list-api
├── README.md # มี DB credential plaintext
├── tsconfig.json
├── sql/create_table.sql # schema todos
├── docs/export-pdf-workflow.md # โจทย์ PDF
└── src/
├── server.ts # entrypoint
├── config/
│ ├── database.ts # pg Pool + default host
│ └── swagger.ts
├── routes/
│ ├── todo.routes.ts
│ ├── task.routes.ts
│ ├── user.routes.ts
│ └── product.routes.ts
├── controllers/
├── models/ # todo, task, user, product, cart
├── types/
└── views/products-pdf.ejsBoot (server.ts)
dotenv.config()
express()
cors + json + urlencoded
view engine ejs
POST /upload (multer → public/)
/api-docs (Swagger)
GET /health
/api/todos | /api/tasks | /api/users | /api/products
404 + error handlers
listen(PORT)(src/server.ts:12-79)
HTTP surface
Infra
| Method | Path | Citation |
|---|---|---|
| GET | /health | server.ts:45-51 |
| POST | /upload | server.ts:30-36 |
| GET | /api-docs | server.ts:38-42 |
Todos — /api/todos
| Method | Path | Handler | Citation |
|---|---|---|---|
| GET | / | getAllTodos | todo.routes.ts:34 |
| GET | /:id | getTodoById | todo.routes.ts:81 |
| POST | / | createTodo | todo.routes.ts:121 |
| PUT | /:id | updateTodo | todo.routes.ts:174 |
| DELETE | /:id | deleteTodo | todo.routes.ts:222 |
| PATCH | /:id/soft-delete | softDeleteTodo | todo.routes.ts:270 |
Tasks — /api/tasks
| Method | Path | Handler | Citation |
|---|---|---|---|
| GET | / | getAllTask | task.routes.ts:34 |
| GET | /:title | getTaskTitle | task.routes.ts:126 |
(route ตาม status ถูก comment — task.routes.ts:80)
Users — /api/users
| Method | Path | Handler | Citation |
|---|---|---|---|
| GET | / | getAllUser | user.routes.ts:35 |
| GET | /user/:id | getuserById | user.routes.ts:82 |
| POST | / | CreateUser | user.routes.ts:122 |
| PATCH | /:id | CreateUserById (+ upload) | user.routes.ts:163 |
| GET | /FileUpload | getUserFile | user.routes.ts:193 |
Products — /api/products
| Method | Path | Handler | Citation |
|---|---|---|---|
| POST | / | createProducts | product.routes.ts:43 |
| GET | / | getProducts | product.routes.ts:84 |
| GET | /filter | findProduct | product.routes.ts:125 |
| GET | /:id | getProductById | product.routes.ts:173 |
| PUT | /:id | updateProduct | product.routes.ts:226 |
| PATCH | /:id | updateStatus | product.routes.ts:279 |
| GET | /export/pdf | exportPDF | product.routes.ts:302 |
| GET | /create/excel | createExcel | product.routes.ts:325 |
หมายเหตุ Express: ลำดับ route สำคัญ — /export/pdf และ /filter ต้องประกาศก่อน /:id (ในไฟล์ปัจจุบัน /export/pdf อยู่หลัง /:id ที่บรรทัด 173 vs 302) — อาจทำให้ export ถูกตีความเป็น id ได้ UNVERIFIED ที่ runtime ว่าชนหรือไม่ ควรตรวจลำดับก่อนใช้โจทย์ PDF
PDF workflow อธิบายใน docs/export-pdf-workflow.md
Database defaults
| Env var | Fallback ในโค้ด | Citation |
|---|---|---|
DB_HOST | host ใน database.ts | database.ts:7 |
DB_PORT | 5432 | database.ts:8 |
DB_NAME | interns_db | database.ts:9 |
DB_USER / DB_PASSWORD | ค่า default ใน source | database.ts:10-11 |
SQL ที่ commit: sql/create_table.sql สำหรับตาราง todos
สิ่งที่ไม่มีใน repo นี้
- การอ้างอิง service VTRC อื่น
- Dockerfile / Bitbucket pipeline ของแพลตฟอร์ม production
- Auth แบบ JWT ของ VTRC (มีโจทย์ login บน feature branch แยก — ไม่ยืนยันว่า merge เข้า
mainครบ)
ไป 02 · Scorecard →