Daily Quest Actions & UserActionLog

admin / quest / action-log
Endpoints: GET /api/v1/admin/daily-quests/actions · POST /api/v1/admin/daily-quests  ·  Table: daily_quests · user_action_logs
13
Action options
from ActionType enum
0
DB query
metadata API only maps enum
1
Tracking table
user_action_logs
JOIN
Circle approval
logs JOIN_CIRCLE on accept

User Perspective


Admin
Khi tạo daily quest, UI gọi GET /admin/daily-quests/actions để lấy danh sách action gồm value, labelunit. API này không gọi database.
Quest
Daily quest dùng actionrequirement để mô tả mục tiêu, ví dụ action POST_CREATED với requirement 3 nghĩa là cần đăng 3 bài.
Tracking
Các hành động user thực hiện được ghi vào UserActionLog với userId, type, targetId, metadatacreatedAt để phục vụ tính tiến độ quest sau này.

Flow Diagram


Admin Create Quest UI GET actions ActionType to label/unit POST daily quest action + requirement User performs action UserActionLogService generic + typed methods Insert user_action_logs userId + type + metadata

Daily quest định nghĩa action cần đạt; UserActionLog ghi nhận hành động thực tế để layer tính tiến độ có dữ liệu truy vấn.

API Detail


# API / Module Ghi chú nghiệp vụ Status
01
GET /admin/daily-quests/actions
Admin daily quest action options
Trả danh sách action từ enum ActionType, mỗi item có dạng { value, label, unit }. Không query DB. done
02
POST /admin/daily-quests
Create daily quest
Body nhận thêm action. targetCount đã bỏ, số lượng mục tiêu dùng requirement. done
03
UserActionLog module
Repository + service
logAction generic và method rõ nghĩa cho từng action: post, quote, share, like, follow, invite, join circle, leave circle. done
04
POST /circle/{publicId}/manage/join-request/respond
Approve/reject join request
Yêu cầu quyền ACCEPT_USE_JOIN. Khi admin/owner accept thành công, hệ thống tạo log JOIN_CIRCLE cho user được duyệt, metadata có approvedByIdsource: "JOIN_REQUEST". noted

Action Mapping


Action Label Unit Source flow
POST_CREATEDĐăng bàibàiPost thường và circle post.
POST_DELETEDXoá bàibàiSoft delete post thường.
LIKE_CREATEDThích bàilượtChỉ ghi khi Redis sAdd trả 1.
FOLLOW_FOLLOWING_CREATEDTheo dõi người dùngngườiGhi cho actor khi follow mới hoặc follow lại.
FLOW_FOLLOWER_CREATEDCó người theo dõingườiGhi cho target user khi có follower mới.
QUOTE_CREATEDQuote bàibàiCreate quote post.
QUOTE_DELETEDXoá quotebàiDelete post type QUOTE.
SHARE_CREATEDChia sẻ bàilượtCreate repost/share.
SHARE_DELETEDXoá chia sẻlượtDelete post type REPOST.
INVITE_SENTGửi lời mờilời mờiCircle invitation flows.
INVITE_ACCEPTEDChấp nhận lời mờilời mờiUser accept circle invitation.
JOIN_CIRCLEĐược duyệt vào nhómnhómAdmin/owner accept join request.
LEAVE_CIRCLERời nhómnhómService method đã có, chưa wire vì chưa có leave circle flow.

Implementation Progress


Done
DailyQuest lưu action_enum, create/list trả action và không dùng targetCount.
Admin action API map từ enum sang value, label, unit.
UserActionLog có repository/service và đã wire vào post, like, follow, invitation, approve join request.
Swagger admin/circle đã có schema, path docs và note permission/log.
Pending environment
Chạy prisma generate, prisma validatenpm run typecheck trên môi trường không bị giới hạn WSL1/Node.
Layer tính tiến độ daily quest theo user_action_logs có thể triển khai sau khi chốt rule reset/ngày và timezone.

Design Notes


Data
requirement là số lượng action cần đạt. targetCount không còn nằm trong DailyQuest.
Enum
FLOW_FOLLOWER_CREATED được giữ nguyên theo enum hiện có để tránh đổi contract. Nếu muốn sửa typo thành FOLLOW_FOLLOWER_CREATED, cần migration riêng.
Transaction
Các method log nhận optional tx để ghi cùng transaction khi flow chính cần đảm bảo atomic side effect.
Risk
Hiện log insert nằm trong flow chính; nếu database ghi log lỗi thì request nghiệp vụ có thể fail. Có thể tách async queue nếu muốn ưu tiên độ bền UX hơn tính atomic.