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

Feature/cron sync ro users #53

Merged
merged 3 commits into from
Aug 4, 2023
Merged

Conversation

dhakalaashish
Copy link
Contributor

The syncROUsers function is a cron job that runs periodically and syncs projects, sites for users who are ROs (Restoration Organizations).
This synchronization process is done between the Firealert database and the Plant-for-the-Planet Webapp.

Here's a brief step-by-step overview of what happens during the synchronization process:

  1. The cron job first fetches all the projects and associated sites from the Webapp.
  2. It then fetches all RO users from the Firealert database and creates a map to associate remoteId with userId for easy lookups later.
  3. The script then filters the projects fetched from the Webapp to only include projects related to the RO users.
  4. It identifies any projects that exist in the Webapp but not in the Firealert database, then prepares data for bulk creation of the projects and their associated sites in the Firealert database. For each site in a new project, it checks if the site already existed before and was soft-deleted from the webapp. If the site already existed, it prepares the site for a bulk update, during which it nullifies the projectId and deletedAt fields.
  5. After the new data is added, the function re-fetches all RO projects and its corresponding sites to include any that were just created.
  6. It then identifies any sites in the Firealert database that are not present in the Webapp and soft deletes them by dissociating those sites from their projects (i.e., setting projectId to null).
  7. Then, for each project in the Webapp, the function identifies if the project itself needs to be synced or if any of its corresponding sites need to be created/synced by comparing the lastUpdated values between Firealert and Webapp.
  8. The cron job concludes by returning a response with a success message and counts of the created, updated, and deleted items. In case of an error during the process, the function logs the error and returns a response with an error message.

@vercel
Copy link

vercel bot commented Jul 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
fire-alert ❌ Failed (Inspect) Jul 18, 2023 11:26am

@sagararyal sagararyal merged commit a1895d8 into develop Aug 4, 2023
2 of 3 checks passed
@sagararyal sagararyal deleted the feature/cron-sync-ro-users branch August 4, 2023 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants