Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
    • Help
    • Submit feedback
    • Contribute to GitLab
  • Sign in
U
upgrade-data-crawler-be
  • Project
    • Project
    • Details
    • Activity
    • Releases
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
  • Issues 0
    • Issues 0
    • List
    • Board
    • Labels
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • ThinhNC
  • upgrade-data-crawler-be
  • Merge Requests
  • !4

Merged
Opened Sep 03, 2026 by ThinhNC@ThinhNC
  • Report abuse
Report abuse

refactor(common): standardize hardcoded constants and enforce zero-hardcode architecture

Refactor: Standardize Constants and Enforce Zero-Hardcode Architecture

Summary of Changes

This PR eliminates all hardcoded string literals and Prisma enum leakage across the backend codebase (data-crawler-be), adhering strictly to the layer separation and Prisma exclusivity rules defined in AGENTS.md.


Key Highlights

1. Centralized Constants Layer (src/common/constants/)

  • Added CRAWL_MODE & CrawlMode (src/common/constants/crawl-mode.constant.ts): Standardized 'SCRAPE', 'CRAWL', 'SITEMAP', and 'URL_LIST'.
  • Added SCHEDULE_FREQUENCY & ScheduleFrequency (src/common/constants/schedule-frequency.constant.ts): Standardized 'DAILY', 'WEEKLY', 'MONTHLY', and 'CUSTOM'.
  • Added ASSET_TYPE & AssetType (src/common/constants/asset-type.constant.ts): Standardized 'IMAGE', 'LINK', 'PDF', 'FILE', 'VIDEO', and 'OTHER'.
  • Added DEFAULT_TIMEZONE (src/common/constants/timezone.constant.ts): Centralized default timezone 'Asia/Ho_Chi_Minh'.
  • Barrel Export (src/common/constants/index.ts): Re-exports all domain constants for single-point import.

2. Zero-Hardcode Refactoring

  • Crawl Jobs & Worker (crawl.worker.processor.ts, crawl-job.service.ts, crawl-job.validation.ts):
    • Replaced hardcoded status strings with JOB_STATUS.* (COMPLETED, RUNNING, FAILED, CANCELED, etc.).
    • Replaced mode comparisons and array definitions with CRAWL_MODE.* and z.nativeEnum(CRAWL_MODE).
    • Replaced export type strings with EXPORT_TYPE.* and z.nativeEnum(EXPORT_TYPE).
  • Crawl Schedules (crawl-schedule.service.ts, crawl-schedule.validation.ts, crawl-schedule.repository.ts):
    • Replaced hardcoded timezone 'Asia/Ho_Chi_Minh' with DEFAULT_TIMEZONE.
    • Replaced hardcoded schedule frequencies with SCHEDULE_FREQUENCY.* and z.nativeEnum(SCHEDULE_FREQUENCY).
  • Users & Auth (auth.service.ts, user.service.ts, user.validation.ts):
    • Replaced 'ADMIN' literal with ROLES.ADMIN.
    • Used z.nativeEnum(ROLES) in user query and creation schemas.
    • Replaced hardcoded timezone with DEFAULT_TIMEZONE.
  • Exports & Dashboard (export.service.ts, crawl-export.service.ts, dashboard.repository.ts):
    • Bound export handler keys using [EXPORT_TYPE.*].
    • Replaced hardcoded status counts with JOB_STATUS.*.

3. Strict Prisma Exclusivity Enforcement (AGENTS.md §1)

  • Removed @prisma/client enum imports (UserRole, CrawlMode, CrawlJobStatus, ScheduleFrequency, ExportType, AssetType) from non-repository layers (Services, Controllers, DTOs, and Middlewares).
  • Isolated DTO and Service typing strictly through domain constant types.

4. Documentation & Guidelines (AGENTS.md)

  • Added the Zero Hardcode Principle under Section 1 invariant rules, providing clear declarations, validation patterns, and usage code examples for future development.

Check out, review, and merge locally

Step 1. Fetch and check out the branch for this merge request

git fetch origin
git checkout -b refactor/standardize-constants-and-zero-hardcode origin/refactor/standardize-constants-and-zero-hardcode

Step 2. Review the changes locally

Step 3. Merge the branch and fix any conflicts that come up

git fetch origin
git checkout origin/develop
git merge --no-ff refactor/standardize-constants-and-zero-hardcode

Step 4. Push the result of the merge to GitLab

git push origin develop

Note that pushing to GitLab requires write access to this repository.

Tip: You can also checkout merge requests locally by following these guidelines.

  • Discussion 0
  • Commits 1
  • Changes 193
Assignee
No assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
0
Labels
None
Assign labels
  • View project labels
Reference: ThinhNC/upgrade-data-crawler-be!4

Revert this merge request

This will create a new commit in order to revert the existing changes.

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.

Cherry-pick this merge request

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.