-
Notifications
You must be signed in to change notification settings - Fork 2
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
Rework invitations backend #185
Conversation
IidaKainu
commented
Oct 27, 2021
- Add timestamp and unique constraint (combination of roadmapId & email) to invitations
- Add route for getting invitations
json = super.$parseDatabaseJson(json); | ||
const date = json.updatedAt && new Date(json.updatedAt); | ||
json.updatedAt = date; | ||
json.valid = date >= moment().subtract(48, 'hours').toDate(); | ||
return json; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had a bit of trouble comparing the date: went with a solution similar to what's described here: Vincit/objection.js#91 (comment)
Changes are looking good 👍 But I'm not sure how I feel about using moment.js, though. Their official page is saying: Moment.js is a legacy project, now in maintenance mode. In most cases, you should choose a different library. Moment was built for the previous era of the JavaScript ecosystem. The modern web looks much different these days. Moment has evolved somewhat over the years, but it has essentially the same design as it did when it was created in 2011. Another common argument against using Moment in modern applications is its size. Moment doesn't work well with modern "tree shaking" algorithms, so it tends to increase the size of web application bundles. If one needs internationalization or time zone support, Moment can get quite large. Recently, Chrome Dev Tools started showing recommendations for replacing Moment for the size alone. We generally support this move. More information: https://momentjs.com/docs/#/-project-status/ I would probably pick some other library, maybe even one of the libraries they suggest (or go without a library and work with js only if nothing too complicated is needed): If the date is only used in substracting time, you could use these techniques without additional libraries. There's also a good discussion on daylight savings times etc. Instead of 48 hours, subtract 2 days and instead of a month, subtract 30 days. This would also get rid of a problem where sometimes month would be 28 days and sometimes 31. |
3875576
to
c93b244
Compare
Thank you for sharing the info about moment.js! 🙏 I have not worked much with js dates, so I had no idea. |
Your solution looks good, especially when no additional libraries were needed for this 👍 I think it could be improved a bit if you made a function for the daysAgo -part and moved it to utils folder. It would remove a little bit of code-repeating since the same lines of code are used in two place (getting values for monthAgo in invitations.controller and twoDaysAgo in invitations.model) and maybe even more if you need to use these date-modifiers later in development as well. Something like this (caution: these are written in this text field for example purposes only, might not work as wanted 😄):
and it could be then used like
Otherwise looking great and ready to go! 🔥 |
Add timestamp and unique constraint (combination of roadmapId & email) to invitations. Add route for getting invitations.
c93b244
to
d9cfe6d
Compare
Great suggestion, added 👍 |