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

update alerts to navlinks #454

Merged
merged 2 commits into from
Jul 31, 2024
Merged

Conversation

diegoalzate
Copy link
Contributor

@diegoalzate diegoalzate commented Jul 31, 2024

overview

  • renames alerts to navlinks
  • adds events id to navlinks
  • adds events/:id/nav-links to get the valid navlinks in a event

Summary by CodeRabbit

  • New Features

    • Introduced a new navigation links feature, replacing the previous alerts system.
    • Added the ability to retrieve active navigation links based on specific criteria.
  • Enhancements

    • Improved database schema to establish relationships between navigation links and events.
    • Updated the application routing to incorporate navigation links.
  • Bug Fixes

    • Resolved issues related to querying the previous alerts functionality.

@diegoalzate diegoalzate added the feature New feature or request label Jul 31, 2024
@diegoalzate diegoalzate requested a review from camilovegag July 31, 2024 14:59
@diegoalzate diegoalzate self-assigned this Jul 31, 2024
Copy link

coderabbitai bot commented Jul 31, 2024

Walkthrough

This migration introduces substantial updates to the database schema, including the renaming of the alerts table to nav_links and the addition of an event_id column to establish connections with events. These changes permeate the application, with adjustments made to handlers, routers, and schemas, thereby enhancing data integrity and improving the overall functionality regarding event-related navigation.

Changes

File(s) Change Summary
migrations/0029_mushy_vermin.sql Renamed alerts table to nav_links, added event_id column, and established a foreign key.
migrations/meta/0029_snapshot.json Defined schema for multiple tables, including nav_links, with relevant columns and constraints.
src/db/schema/events.ts Updated to include a relationship to navLinks.
src/db/schema/index.ts Changed export from alerts to nav-links.
src/db/schema/nav-links.ts Renamed table from alerts to nav_links, added eventId, and updated types and relations.
src/handlers/events.ts Introduced getEventNavLinksHandler to retrieve navigation links for specific events.
src/handlers/nav-links.ts Added getActiveNavLinks to fetch active navigation links, replacing getActiveAlerts.
src/routers/api.ts Replaced alertsRouter with navLinksRouter.
src/routers/events.ts Added endpoint to retrieve navigation links associated with events.
src/routers/nav-links.ts Renamed router from alertsRouter to navLinksRouter.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant API
    participant EventHandler
    participant NavLinksHandler
    participant Database

    User->>API: Request navigation links by event ID
    API->>EventHandler: Route to event related handler
    EventHandler->>NavLinksHandler: Get navigation links
    NavLinksHandler->>Database: Query nav_links with event ID
    Database-->>NavLinksHandler: Return navigation links
    NavLinksHandler-->>EventHandler: Send navigation links back
    EventHandler-->>API: Return navigation links to user
Loading

Poem

🐇 In the garden, links now bloom,
Navigation paths dispel the gloom.
From alerts to navs, a joyful hop,
Events and stories never stop!
With every click, new journeys start,
A rabbit's cheer, from the heart! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 42d8698 and fa30085.

Files selected for processing (11)
  • migrations/0029_mushy_vermin.sql (1 hunks)
  • migrations/meta/0029_snapshot.json (1 hunks)
  • migrations/meta/_journal.json (1 hunks)
  • src/db/schema/events.ts (2 hunks)
  • src/db/schema/index.ts (1 hunks)
  • src/db/schema/nav-links.ts (1 hunks)
  • src/handlers/events.ts (2 hunks)
  • src/handlers/nav-links.ts (1 hunks)
  • src/routers/api.ts (2 hunks)
  • src/routers/events.ts (2 hunks)
  • src/routers/nav-links.ts (1 hunks)
Additional comments not posted (33)
migrations/0029_mushy_vermin.sql (4)

1-1: LGTM!

The statement correctly renames the alerts table to nav_links.


2-2: LGTM!

The statement correctly adds a new column event_id of type uuid to the nav_links table.


4-4: LGTM!

The statement correctly adds a foreign key constraint to the event_id column, referencing the id column in the events table.


5-7: LGTM!

The EXCEPTION block correctly handles potential duplicate constraint errors by ignoring them.

src/routers/nav-links.ts (3)

3-3: LGTM!

The import statement correctly imports the getActiveNavLinks function from the nav-links handler.


8-8: LGTM!

The function signature correctly renames the router function to navLinksRouter and accepts a dbPool parameter.


9-9: LGTM!

The router.get method correctly uses the getActiveNavLinks function and the isLoggedIn middleware.

src/db/schema/index.ts (1)

21-21: LGTM!

The line correctly exports all entities from the nav-links module.

src/handlers/nav-links.ts (2)

7-7: Rename function to reflect new functionality.

The function name has been updated to getActiveNavLinks to reflect the new focus on navigation links.


10-13: Ensure correct table and field names in the query.

The query logic has been updated to fetch from the navLinks table. Ensure that the field names (active, startAt, endAt) are correct and exist in the navLinks table.

Verification successful

Field names are correct.

The fields active, startAt, and endAt exist in the navLinks table definition. The query logic in the src/handlers/nav-links.ts file is correct.

  • src/db/schema/nav-links.ts, lines 10-12
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the field names in the navLinks table.

# Test: Check if the fields `active`, `startAt`, and `endAt` exist in the `navLinks` table.
rg --type sql -A 5 'CREATE TABLE nav_links'

Length of output: 45


Script:

#!/bin/bash
# Locate all SQL files and search for the `CREATE TABLE` statement for `nav_links` table to verify field names.

# Find all SQL files
fd -e sql -x rg 'CREATE TABLE nav_links' {} +

Length of output: 1351


Script:

#!/bin/bash
# Search for the `navLinks` table definition in the application code to verify field names.

# Use ast-grep to search for the `navLinks` table definition
ast-grep --lang typescript --pattern 'const navLinks = $_' 

Length of output: 953

src/db/schema/nav-links.ts (2)

18-23: Ensure correct relations definition.

The relations definition establishes a one-to-one relationship between navLinks and events. Ensure that the relation logic is correctly implemented.

Verification successful

Relations definition is correctly implemented.

The navLinks table correctly references the events table with the eventId field pointing to the id field in events.

  • navLinks table definition: src/db/schema/nav-links.ts
  • events table definition: src/db/schema/events.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the relations definition.

# Test: Check if the relations logic is correctly implemented.
rg --type sql -A 5 'ALTER TABLE nav_links'

Length of output: 44


Script:

#!/bin/bash
# Search for the definition of the navLinks table
ast-grep --lang typescript --pattern 'const navLinks = $_' 

# Search for the definition of the events table
ast-grep --lang typescript --pattern 'const events = $_' 

Length of output: 4176


5-13: Ensure correct table and field references.

The eventId field references the id field in the events table. Ensure that the reference is correct and the events table exists.

Verification successful

Let's refine our search to check for the events table definition in TypeScript files, as it might be defined there instead of SQL files.


The eventId field correctly references the id field in the events table.

  • The events table is defined in src/db/schema/events.ts.
  • The id field is present in the events table.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the `events` table and `id` field.

# Test: Check if the `events` table and `id` field exist.
rg --type sql -A 5 'CREATE TABLE events'

Length of output: 42


Script:

#!/bin/bash
# Description: Verify the `events` table and `id` field in TypeScript files.

# Test: Check if the `events` table and `id` field exist in TypeScript files.
rg --type ts -A 10 'pgTable.*events'

Length of output: 822

src/routers/events.ts (1)

30-30: Ensure correct implementation of the new route handler.

The new route definition appears correct. Ensure that the handler function getEventNavLinksHandler is correctly implemented and handles errors appropriately.

src/db/schema/events.ts (2)

7-7: Import statement for navLinks looks good.

The import statement is correctly added and necessary for the changes in the file.


28-28: Addition of navLinks relationship is correct.

The relationship is correctly defined and integrated into eventsRelations.

src/routers/api.ts (2)

18-18: Import statement for navLinksRouter looks good.

The import statement is correctly added and necessary for the changes in the file.


72-72: Routing logic update to use navLinksRouter is correct.

The routing logic is correctly updated to use navLinksRouter instead of alertsRouter.

migrations/meta/_journal.json (1)

209-213: New migration entry is correctly added.

The new entry with idx: 29 is correctly formatted and integrated into the JSON structure.

src/handlers/events.ts (2)

1-1: Import statement changes approved.

The added imports gte, lte, or are necessary for the new function getEventNavLinksHandler.


138-157: Function logic approved.

The function getEventNavLinksHandler correctly implements the required functionality to retrieve navigation links associated with a specific event.

migrations/meta/0029_snapshot.json (13)

7-82: Table schema public.comments approved.

The table schema is well-defined with appropriate data types, constraints, and foreign keys.


83-160: Table schema public.cycles approved.

The table schema is well-defined with appropriate data types, constraints, and foreign keys.


161-241: Table schema public.events approved.

The table schema is well-defined with appropriate data types and constraints.


242-313: Table schema public.federated_credentials approved.

The table schema is well-defined with appropriate data types, constraints, and foreign keys.


314-391: Table schema public.group_categories approved.

The table schema is well-defined with appropriate data types, constraints, and foreign keys.


392-468: Table schema public.groups approved.

The table schema is well-defined with appropriate data types, constraints, and foreign keys.


469-551: Table schema public.users approved.

The table schema is well-defined with appropriate data types, constraints, and unique constraints.


552-653: Table schema public.registrations approved.

The table schema is well-defined with appropriate data types, constraints, and foreign keys.


654-744: Table schema public.questions approved.

The table schema is well-defined with appropriate data types, constraints, and foreign keys.


745-801: Table schema public.registration_field_options approved.

The table schema is well-defined with appropriate data types, constraints, and foreign keys.


802-948: Table schema public.options approved.

The table schema is well-defined with appropriate data types, constraints, and foreign keys.


949-1043: Table schema public.votes approved.

The table schema is well-defined with appropriate data types, constraints, and foreign keys.


1631-1718: Table schema public.nav_links approved.

The table schema is well-defined with appropriate data types, constraints, and foreign keys.

eq(schema.alerts.active, true),
and(lte(schema.alerts.startAt, new Date()), gte(schema.alerts.endAt, new Date())),
eq(schema.navLinks.active, true),
and(lte(schema.navLinks.startAt, new Date()), gte(schema.navLinks.endAt, new Date())),
),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log errors with more context.

Consider adding more context to the error logs to facilitate debugging.

- logger.error(`[ERROR] ${JSON.stringify(e)}`);
+ logger.error(`[ERROR] getActiveNavLinks: ${JSON.stringify(e)}`);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
),
),
logger.error(`[ERROR] getActiveNavLinks: ${JSON.stringify(e)}`);

src/handlers/events.ts Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between fa30085 and 2de0069.

Files selected for processing (1)
  • src/handlers/nav-links.ts (1 hunks)
Additional comments not posted (3)
src/handlers/nav-links.ts (3)

1-5: LGTM!

The import statements are appropriate and necessary for the functionality provided in the file.


7-7: LGTM!

The function definition is appropriate and follows good practices by accepting dependencies via parameters.


8-25: Enhance error logging with more context.

Consider adding more context to the error logs to facilitate debugging.

- logger.error(`[ERROR] ${JSON.stringify(e)}`);
+ logger.error(`[ERROR] getActiveNavLinks: ${JSON.stringify(e)}`);

src/handlers/nav-links.ts Show resolved Hide resolved
Copy link
Collaborator

@camilovegag camilovegag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scrumptious

@diegoalzate diegoalzate merged commit c8f0957 into develop Jul 31, 2024
3 checks passed
@diegoalzate diegoalzate deleted the diego/update-alerts-to-navlinks branch July 31, 2024 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants