Skip to content

86exm8u3j metrics sent today#11

Open
Lavi2910 wants to merge 5 commits into
mainfrom
86exm8u3j-metricsSentToday
Open

86exm8u3j metrics sent today#11
Lavi2910 wants to merge 5 commits into
mainfrom
86exm8u3j-metricsSentToday

Conversation

@Lavi2910
Copy link
Copy Markdown
Collaborator

Description

Backend metrics to db
Please include a summary of the changes and the related issue.

Related Issue(s)

86exm8u3j
Fixes # (issue number)

Checklist:

  • I have performed a self-review of my own code
  • My changes generate no new warnings

Screenshots (if appropriate):

@Lavi2910 Lavi2910 requested a review from Tamir198 May 21, 2026 22:30
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Warning

Rate limit exceeded

@Lavi2910 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 44 minutes and 1 second before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c3283efb-2758-4a82-bc2d-6ee6884d21d2

📥 Commits

Reviewing files that changed from the base of the PR and between 16ac4aa and 2535848.

📒 Files selected for processing (7)
  • src/app.ts
  • src/constants/error.constants.ts
  • src/controllers/metrics.controller.ts
  • src/models/metricsModel.mongoose.ts
  • src/routes/metrics.routes.ts
  • src/services/metrics.service.ts
  • src/utils/date.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 86exm8u3j-metricsSentToday

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread src/services/metrics.service.ts Outdated
import { Metrics, metricsModel } from '@/models/metricsModel.mongoose';
import { REPORT_ALREADY_SUBMITTED } from '@/constants/error.constants';

export const SentToday = async (patientId: string) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Export the service object like this:

export const serviceName = {
 method1 : ....
}

Like we always did so far

Comment thread src/routes/metrics.routes.ts
Comment thread src/services/metrics.service.ts Outdated
import { REPORT_ALREADY_SUBMITTED } from '@/constants/error.constants';

export const SentToday = async (patientId: string) => {
const startOfDay = new Date();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Date related functions should come from the relevant util functions

Comment thread src/services/metrics.service.ts Outdated
patientId,
createdAt: { $gte: startOfDay },
});
return alreadySubmitted ? true : false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

return alreadySubmitted

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

but already submitted could return null

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can do Boolean(null) or wrap the entire exists method in boolean this way you wont have to deal with those checks

Comment thread src/services/metrics.service.ts Outdated
return alreadySubmitted ? true : false;
};

export const SubmitReport = async (patientId: string, metrics: Omit<Metrics, 'patientId'>) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are we omitting patientId in here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

because on the metrics type we have patientId for the model but here we have got it from the params so i separated it

Comment thread src/services/metrics.service.ts Outdated
};

export const SubmitReport = async (patientId: string, metrics: Omit<Metrics, 'patientId'>) => {
const alreadySubmitted = await SentToday(patientId);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

a boolean function should start with is -> isSentToday

@Lavi2910 Lavi2910 requested a review from Tamir198 May 22, 2026 11:45
Comment thread src/services/metrics.service.ts Outdated
patientId,
createdAt: { $gte: startOfDay },
});
return alreadySubmitted ? true : false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can do Boolean(null) or wrap the entire exists method in boolean this way you wont have to deal with those checks

@Lavi2910 Lavi2910 requested a review from Tamir198 May 22, 2026 12:00

export const SentToday = async (req: Request, res: Response, next: NextFunction) => {
try {
const patientId = req.params.patientId as string;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here, give it a generic type

return Boolean(alreadySubmitted);
};

const SubmitReport = async (patientId: string, metrics: Omit<Metrics, 'patientId'>) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would create a new type in a separate file for metrics

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