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

Create weekly event recurring instance #1658

Merged
merged 10 commits into from
Jan 17, 2024

Conversation

Community-Programmer
Copy link
Contributor

@Community-Programmer Community-Programmer commented Jan 8, 2024

What kind of change does this PR introduce?
Fixed the bug on creating recurring event only single event is created

Issue Number:

Fixes #1583

Did you add tests for your changes?
yes

Snapshots/Videos:

2024-01-08.13-04-09.mp4

If relevant, did you update the documentation?

No

Summary

  • Create a weekly recurring instance

Implementation Details:

Validation:

No other functionalities is affected by changes made in the createEvent mutation
All test files passed
image

Does this PR introduce a breaking change?

Yes

Have you read the contributing guide?

Yes

Copy link

github-actions bot commented Jan 8, 2024

Our Pull Request Approval Process

We have these basic policies to make the approval process smoother for our volunteer team.

Testing Your Code

Please make sure your code passes all tests. Our test code coverage system will fail if these conditions occur:

  1. The overall code coverage drops below the target threshold of the repository
  2. Any file in the pull request has code coverage levels below the repository threshold
  3. Merge conflicts

The process helps maintain the overall reliability of the code base and is a prerequisite for getting your PR approved. Assigned reviewers regularly review the PR queue and tend to focus on PRs that are passing.

Reviewers

When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

@Community-Programmer
Copy link
Contributor Author

Community-Programmer commented Jan 8, 2024

@palisadoes @sumitra19jha @ttaylor92 @xoldyckk

Attention:

I have made the required changes, but the test case is failing because, as suggested by @sumitra19jha, 'to start a transaction and make sure everything is a success or everything fails.'
Transactions are available for replica sets, not for standalone mongod instances.

image

image

So, the test case will fail if we are using a standalone MongoDB for development and testing.

If we want to work with transactions in MongoDB, we'll need to set up a replica set even for our development environment.

Convert a Standalone mongod to a Replica Set

All test cases are passing when using replica sets and MongoDB Atlas

Is there any other approach we should follow or continue with this?

@palisadoes
Copy link
Contributor

@Community-Programmer @sumitra19jha

  1. Though it is a good idea, implementing DB replication is out of scope of this PR
  2. We can create another issue to get that implemented after this PR is merged
  3. Please assume no replication for all tests related to this PR

I'd like to get this merged so that we can start creating issues in Admin and Mobile to implement weekly recurring meetings in their respective UIs

@Community-Programmer
Copy link
Contributor Author

@Community-Programmer @sumitra19jha

  1. Though it is a good idea, implementing DB replication is out of scope of this PR
  2. We can create another issue to get that implemented after this PR is merged
  3. Please assume no replication for all tests related to this PR

I'd like to get this merged so that we can start creating issues in Admin and Mobile to implement weekly recurring meetings in their respective UIs

can we comment out or skip the tests related to database replication for now?

I'll make sure to include clear comments in the code, explicitly stating that these tests are skipped temporarily until database replication is implemented.

This approach ensures that these tests are documented within the PR, and we can easily reintroduce them once the database replication feature is implemented.

@palisadoes
Copy link
Contributor

@Community-Programmer @sumitra19jha

  1. Though it is a good idea, implementing DB replication is out of scope of this PR
  2. We can create another issue to get that implemented after this PR is merged
  3. Please assume no replication for all tests related to this PR

I'd like to get this merged so that we can start creating issues in Admin and Mobile to implement weekly recurring meetings in their respective UIs

can we comment out or skip the tests related to database replication for now?

I'll make sure to include clear comments in the code, explicitly stating that these tests are skipped temporarily until database replication is implemented.

This approach ensures that these tests are documented within the PR, and we can easily reintroduce them once the database replication feature is implemented.

  1. Yes, that is acceptable
  2. @sumitra19jha @xoldyckk Please review

Copy link

codecov bot commented Jan 8, 2024

Codecov Report

Attention: 100 lines in your changes are missing coverage. Please review.

Comparison is base (c0468a4) 98.17% compared to head (cf83b1c) 97.34%.
Report is 161 commits behind head on develop.

❗ Current head cf83b1c differs from pull request most recent head 500656d. Consider uploading reports for the commit 500656d to get more accurate results

Files Patch % Lines
src/utilities/PII/decryption.ts 0.00% 17 Missing ⚠️
src/resolvers/Mutation/updateUserProfile.ts 70.90% 1 Missing and 15 partials ⚠️
src/resolvers/Mutation/createEvent.ts 85.55% 11 Missing and 2 partials ⚠️
src/resolvers/middleware/currentUserExists.ts 45.83% 13 Missing ⚠️
src/utilities/PII/encryption.ts 0.00% 13 Missing ⚠️
src/utilities/PII/isAuthorised.ts 0.00% 11 Missing ⚠️
src/resolvers/Mutation/createPost.ts 86.95% 6 Missing ⚠️
...tilities/encodedVideoStorage/uploadEncodedVideo.ts 96.29% 3 Missing ⚠️
src/resolvers/Mutation/removeAdvertisement.ts 92.85% 2 Missing ⚠️
...c/resolvers/Query/postsByOrganizationConnection.ts 33.33% 2 Missing ⚠️
... and 3 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1658      +/-   ##
===========================================
- Coverage    98.17%   97.34%   -0.84%     
===========================================
  Files          184      202      +18     
  Lines        10767    12352    +1585     
  Branches       835     1000     +165     
===========================================
+ Hits         10571    12024    +1453     
- Misses         186      296     +110     
- Partials        10       32      +22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Community-Programmer
Copy link
Contributor Author

@sumitra19jha @xoldyckk @ttaylor92

Please review

@sumitra19jha
Copy link
Contributor

Please write the code clean and correctly. Have you run the code to see if transactions are working? What do you mean by commenting out for replica? If you need replica, try to resolve it locally and run it there. If you don't, then don't put this unnecessary comments.

Also please note when you ask for review, you have provided a clean code, containing logic, docs and test cases. Every mentor is busy, so when they put their time, they are looking for reviewing your final solution which might need few modifications (in another review) and then done.

@Community-Programmer
Copy link
Contributor Author

I have completely tested the code before submitting the PR. I tested each functionality locally including working of transactions and converted the standalone to replica locally for testing this, also tested it using MongoDB Atlas. I have commented out the code because if this gets merged it will cause trouble for others as test case will fail for them .So I commented out these test cases so that it can be reintroduced in the future once DB replication is implemented.

Also i am documenting all the changes I am doing so that it help others when integrating this feature with Talawa admin and mobile

In terms of cleaner code, I tried my best to reduce complexity and make it as understandable as possible. If you want, I can further clean it up by moving helper functions into a separate file. Further the complexity will increase when dealing with monthly recurring events.

I apologise if asking for a review annoyed you. I understand you are busy reviewing other PRs. I'm sorry for my behavior

Thank you

Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

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

In hindsight, you have commented out test cases and stated that the code is thoroughly tested. The code coverage has declined significantly which is not desirable. This implies the testing done is manual, which is unverifiable. The code has therefore become more unstable.

If your testing logic requires replication to be enabled that means all other tests in the code base are at risk of being removed. This is not acceptable.

Restore the tests and figure out how to verify the functionality your new code thoroughly in an automated way.

@palisadoes
Copy link
Contributor

I'd interpret to start a transaction and make sure everything is a success or everything fails as meaning that there is transaction rollback capability with error handling that an ODM/ORM like Mongoose should support.

@sumitra19jha
Copy link
Contributor

sumitra19jha commented Jan 10, 2024

I'd interpret to start a transaction and make sure everything is a success or everything fails as meaning that there is transaction rollback capability with error handling that an ODM/ORM like Mongoose should support.

Exactly correct. This is what I am trying to explain in my code review. The process is very simple

  1. Start a transaction
  2. Perform all CRUD operations
  3. Commit the transaction
  4. If it fails rollback

Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

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

See comment

tests/resolvers/Mutation/createEvent.spec.ts Outdated Show resolved Hide resolved
@palisadoes palisadoes self-requested a review January 10, 2024 18:48
palisadoes
palisadoes previously approved these changes Jan 10, 2024
@palisadoes
Copy link
Contributor

Please fix the failing tests

Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

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

See comments

tests/resolvers/Mutation/createEvent.spec.ts Show resolved Hide resolved
tests/resolvers/Mutation/createEvent.spec.ts Show resolved Hide resolved
tests/resolvers/Mutation/createEvent.spec.ts Show resolved Hide resolved
tests/resolvers/Mutation/createEvent.spec.ts Show resolved Hide resolved
tests/resolvers/Mutation/createEvent.spec.ts Show resolved Hide resolved
src/helpers/eventInstance.ts Outdated Show resolved Hide resolved
@palisadoes
Copy link
Contributor

Please take a look:

  1. @xoldyckk
  2. @sumitra19jha
  3. @DMills27
  4. @JamaicanFriedChicken

@Community-Programmer
Copy link
Contributor Author

@palisadoes

resolved conversation please do see the comments once

@palisadoes
Copy link
Contributor

How do you plan to handle custom intervals like:

  1. Weekly on Tuesday and Thursday
  2. Third Monday of the month?
  3. Last Friday of the month
  4. Monthly on the first day

Where would that logic our in future?

Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

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

How can the eventInstance.ts file be refactored so that functions to handle different intervals can be worked on simultaneously by multiple contributors minimizing merge conflicts?

We'll need to do this to speed up development time. Make a proposal because this approach will need to be done and is stated in the original issue

src/helpers/eventInstance.ts Outdated Show resolved Hide resolved
@Community-Programmer
Copy link
Contributor Author

@palisadoes

For regular intervals - I have already implemented the functionality for intervals as described below. The backend is set up to manage the scheduling of events based on the specified intervals.
For instance, if today is 12/01/2024, and it's Wednesday, and a weekly event is created, events will be generated every week on Wednesdays.

See below event is created weekly on monday

2024-01-08.13-04-09.mp4

Similarly, I've implemented functionality for events occurring on the first Wednesday, last Wednesday, third Wednesday, etc. The backend takes care of these calculations. Now, we need to work on displaying the corresponding custom messages on the frontend.

For custom intervals - I have thought of using two npm modules one momentjs and one date-fns
https://date-fns.org
https://momentjs.com
this module will help us to get the required date we want to create custom events.

The other functionality is almost complete, and I am waiting for this pull request to be thoroughly reviewed and merged. This will help me become familiar with it and serve as the foundation for all my future work, making it easier for other pull requests to be reviewed

@Community-Programmer
Copy link
Contributor Author

@palisadoes

I am refactoring the file and also switching to moment js and date-fns module so that overall work can be speed up

refactoring like this

eventInstance/
├── index.ts
├── daily.ts
├── weekly.ts
└── monthly.ts

@palisadoes
Copy link
Contributor

Please take a look:

  1. @xoldyckk
  2. @sumitra19jha
  3. @DMills27
  4. @JamaicanFriedChicken

This is ready for review

@palisadoes
Copy link
Contributor

@palisadoes

I am refactoring the file and also switching to moment js and date-fns module so that overall work can be speed up

refactoring like this

eventInstance/
├── index.ts
├── daily.ts
├── weekly.ts
└── monthly.ts

Yes, that's the better approach

Copy link
Contributor

@JamaicanFriedChicken JamaicanFriedChicken left a comment

Choose a reason for hiding this comment

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

It looks good!

@Community-Programmer
Copy link
Contributor Author

Community-Programmer commented Jan 17, 2024

Sorry, I mistakenly closed the PR.

@palisadoes
Copy link
Contributor

  1. The code seems create N number of Event entries for N weeks.
  2. How will someone be able to edit the series? It's not clear. Will that be a separate PR?

@Community-Programmer
Copy link
Contributor Author

@palisadoes

Regarding the editing of events in a series, the plan is to introduce that functionality towards the end of the development process. Initially, we'll focus on adding features for each event creation within the series. Once those features are in place, we'll then extend the functionality to allow for editing the entire series

flow for editing series of event will be like this:

we'll implement a feature where we fetch events based on a specified start date and end date.Also When creating a series of events, I'll include an edit in the event model by adding a new field called recurringId . All recurring events in the same series will have a unique recurringId. This approach will make it easier to identify and edit the entire series of events by referencing the common recurringId.

@palisadoes
Copy link
Contributor

OK. Merging

@palisadoes palisadoes merged commit 663a08b into PalisadoesFoundation:develop Jan 17, 2024
15 checks passed
@palisadoes palisadoes mentioned this pull request Jan 17, 2024
1 task
@palisadoes
Copy link
Contributor

Adding for cross referencing

@DecodeAndCode
Copy link
Contributor

@Community-Programmer I am not able use this weekly recurring property even after adding a sample data in db for a weekly recurring event but in admin its showing its occurance as one. can you please me out here??

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.

5 participants