86exm8u3j metrics sent today#11
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| import { Metrics, metricsModel } from '@/models/metricsModel.mongoose'; | ||
| import { REPORT_ALREADY_SUBMITTED } from '@/constants/error.constants'; | ||
|
|
||
| export const SentToday = async (patientId: string) => { |
There was a problem hiding this comment.
Export the service object like this:
export const serviceName = {
method1 : ....
}Like we always did so far
| import { REPORT_ALREADY_SUBMITTED } from '@/constants/error.constants'; | ||
|
|
||
| export const SentToday = async (patientId: string) => { | ||
| const startOfDay = new Date(); |
There was a problem hiding this comment.
Date related functions should come from the relevant util functions
| patientId, | ||
| createdAt: { $gte: startOfDay }, | ||
| }); | ||
| return alreadySubmitted ? true : false; |
There was a problem hiding this comment.
but already submitted could return null
There was a problem hiding this comment.
You can do Boolean(null) or wrap the entire exists method in boolean this way you wont have to deal with those checks
| return alreadySubmitted ? true : false; | ||
| }; | ||
|
|
||
| export const SubmitReport = async (patientId: string, metrics: Omit<Metrics, 'patientId'>) => { |
There was a problem hiding this comment.
Why are we omitting patientId in here?
There was a problem hiding this comment.
because on the metrics type we have patientId for the model but here we have got it from the params so i separated it
| }; | ||
|
|
||
| export const SubmitReport = async (patientId: string, metrics: Omit<Metrics, 'patientId'>) => { | ||
| const alreadySubmitted = await SentToday(patientId); |
There was a problem hiding this comment.
a boolean function should start with is -> isSentToday
| patientId, | ||
| createdAt: { $gte: startOfDay }, | ||
| }); | ||
| return alreadySubmitted ? true : false; |
There was a problem hiding this comment.
You can do Boolean(null) or wrap the entire exists method in boolean this way you wont have to deal with those checks
|
|
||
| export const SentToday = async (req: Request, res: Response, next: NextFunction) => { | ||
| try { | ||
| const patientId = req.params.patientId as string; |
There was a problem hiding this comment.
We can give a generic type for req instead of force casting this into string
|
|
||
| export const SubmitReport = async (req: Request, res: Response, next: NextFunction) => { | ||
| try { | ||
| const patientId = req.params.patientId as string; |
There was a problem hiding this comment.
Same here, give it a generic type
| return Boolean(alreadySubmitted); | ||
| }; | ||
|
|
||
| const SubmitReport = async (patientId: string, metrics: Omit<Metrics, 'patientId'>) => { |
There was a problem hiding this comment.
I would create a new type in a separate file for metrics
Description
Backend metrics to db
Please include a summary of the changes and the related issue.
Related Issue(s)
86exm8u3j
Fixes # (issue number)
Checklist:
Screenshots (if appropriate):