Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DocumentLinkVisitor with JSON‐Based Visitor Data #220

Open
8 tasks
mahid797 opened this issue Feb 23, 2025 · 0 comments
Open
8 tasks

Add DocumentLinkVisitor with JSON‐Based Visitor Data #220

mahid797 opened this issue Feb 23, 2025 · 0 comments
Assignees
Labels
Backend Backend Related Issue 🔥Critical Must be addressed immediately; blocking core functionality or major bug
Milestone

Comments

@mahid797
Copy link
Collaborator

We want a separate DocumentLinkVisitor table (renamed from LinkVisitors) that stores each
visitor’s submitted data as JSON. This allows maximum flexibility for future additions (e.g., phone,
address, custom fields). We also rename columns for consistency (firstName, lastName, etc.) and
track “visitedAt” rather than “createdAt.”

Goals & Scope

  • Rename LinkVisitorsDocumentLinkVisitor.

  • Rename columns:

    • linkIddocumentLinkId
    • createdAtvisitedAt
    • Make naming consistent across the schema for all tables—either underscore
      (first_name,last_name) or camelCase (lastName,firstName).
  • Add a JSON column (visitorData) for storing dynamic visitor field submissions.

  • Decide if we also keep dedicated firstName, lastName, email columns or if everything
    (including name/email) moves into JSON.

Detailed Tasks

  1. Rename Model

    • In schema.prisma, rename LinkVisitors to DocumentLinkVisitor.
  2. Convert to JSON Storage

    • Use visitorFieldsConfig to validate incoming visitor data before writing to visitorData.

    • Add visitorData Json? to store user‐submitted data. Example:

      { "name": "Alice", "email": "[email protected]" }
    • Use the same visitorFieldsConfig to verify that submitted fields are valid keys before
      writing them to visitorData.

    • We can keep name/email columns if we want quick queries, or we can remove them entirely.

  3. Field Renames (If Keeping Name/Email Columns)

    • first_namefirstName, last_namelastName, emailemail.
    • createdAtvisitedAt for clarity.
  4. Update Code & Migrations

    • Adjust the LinkService (or DocumentLinkService) methods that create visitor records.
    • If we keep name/email columns but also store them in JSON, ensure they stay in sync (or
      consider removing them).
    • Migrate existing data from LinkVisitors into DocumentLinkVisitor.
  5. Future Growth

    • With visitorData in place, new fields (phone, address, etc.) can be stored seamlessly.
    • The front end sees which fields are required (via DocumentLink.visitorFields), and the server
      logs the submission in visitorData.

Acceptance Criteria

  • DocumentLinkVisitor table (renamed from LinkVisitors) is present in the schema.
  • Columns are renamed (documentLinkId, visitedAt, etc.).
  • A JSON field (visitorData) is included to store the user’s dynamic data.
  • Migrations complete successfully, with old data migrated to new columns if needed.
  • The backend API that logs a visitor (e.g., POST /public_links/[linkId]/access) now writes to
    visitorData.
  • If name/email columns remain, confirm they are updated consistently with the JSON data or
    removed if not needed.
  • Frontend uses the same config to dynamically render checkboxes and input fields with correct
    labels and types.
  • Any invalid field keys sent from the frontend are rejected by the backend with appropriate
    error messages based on visitorFieldsConfig.

Notes

  • After these schema changes, the frontend can rely on visitorFields from DocumentLink to
    dynamically decide which fields to request, then store them in DocumentLinkVisitor.visitorData.
  • The server doesn’t store labels or input types—only the minimal flags or list of field keys.
@mahid797 mahid797 added Backend Backend Related Issue ⚡Important High-impact issue that needs to be resolved before the next release labels Feb 23, 2025
@mahid797 mahid797 added this to the v0.1 milestone Feb 23, 2025
@mahid797 mahid797 added 🔥Critical Must be addressed immediately; blocking core functionality or major bug and removed ⚡Important High-impact issue that needs to be resolved before the next release labels Feb 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend Backend Related Issue 🔥Critical Must be addressed immediately; blocking core functionality or major bug
Projects
None yet
Development

No branches or pull requests

2 participants