-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
fix imports #58
fix imports #58
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import { Hono } from "hono"; | ||
import { sendBatchEmail, sendEmail } from "@repo/mail"; | ||
import { mailBatchSchema, mailSchema } from "@repo/types"; | ||
import { zValidator } from "@hono/zod-validator"; | ||
|
||
|
@@ -8,6 +7,7 @@ const app = new Hono(); | |
app | ||
.post("/send", zValidator("json", mailSchema), async (c) => { | ||
const { email, subject } = c.req.valid("json"); | ||
const { sendEmail } = await import("@repo/mail"); | ||
const { data, error } = await sendEmail(email, subject); | ||
if (error) { | ||
return c.json( | ||
|
@@ -35,6 +35,7 @@ app | |
app | ||
.post("/send-batch", zValidator("json", mailBatchSchema), async (c) => { | ||
const { emails, subject } = c.req.valid("json"); | ||
const { sendBatchEmail } = await import("@repo/mail"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Apply similar caching pattern and improve error messages The dynamic import pattern is duplicated here and could benefit from the same caching approach. Additionally, the error messages could be more specific for batch operations. Consider implementing similar caching and improving error messages: +let sendBatchEmailFn: typeof import("@repo/mail")["sendBatchEmail"] | null = null;
+
app
.post("/send-batch", zValidator("json", mailBatchSchema), async (c) => {
const { emails, subject } = c.req.valid("json");
- const { sendBatchEmail } = await import("@repo/mail");
+ try {
+ if (!sendBatchEmailFn) {
+ const { sendBatchEmail } = await import("@repo/mail");
+ sendBatchEmailFn = sendBatchEmail;
+ }
+ const { data, error } = await sendBatchEmailFn(emails, subject);
+ if (error) {
+ return c.json(
+ {
- message: "Email sent failed",
+ message: "Batch email operation failed",
+ error: error.message
+ },
+ 400
+ );
+ }
+ } catch (importError) {
+ return c.json(
+ {
+ message: "Email service initialization failed",
+ },
+ 500
+ );
+ }
|
||
const { data, error } = await sendBatchEmail(emails, subject); | ||
if (error) { | ||
return c.json( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { Hono } from "hono"; | |
import { auth as Auth } from "@repo/auth"; | ||
import { cors } from "hono/cors"; | ||
import mail from "./mail"; | ||
import hello from "./test"; | ||
import test from "./test"; | ||
import session from "./session"; | ||
import auth from "./auth"; | ||
import status from "./status"; | ||
|
@@ -38,7 +38,7 @@ app.use( | |
|
||
app.route("/health", health); | ||
app.route("/session", session); | ||
app.route("/test", hello); | ||
app.route("/hello", test); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Renaming test route to hello is intentional but implementation needs alignment The route change from
Suggested changes:
🔗 Analysis chainVerify the intent of renaming test route to hello There's an inconsistency between:
This makes the code less maintainable. Please verify if this was intentional and consider aligning these names. Let me gather more information about the route handler and its usage. Let me check the content of the test handler file and the test file to understand the full context. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check the contents and usage of the test module to understand its purpose
# Check the implementation of the test module
echo "Checking test module implementation:"
cat apps/api/app/api/test.ts || echo "File not found"
# Look for any references to the old route
echo -e "\nChecking for references to old route path:"
rg -l "/test" --type ts
Length of output: 373 Script: #!/bin/bash
# Check the content of the route file to understand the context
echo "Checking route file content:"
cat "apps/api/app/api/[[...route]]/route.ts"
# Look for any test-related files that might contain the handler
echo -e "\nLooking for test-related files:"
fd -t f -e ts test
# Search for 'test' function/variable declarations
echo -e "\nSearching for test handler definition:"
ast-grep --pattern 'const test = $_'
Length of output: 1670 Script: #!/bin/bash
# Check the test handler implementation
echo "Checking test handler implementation:"
cat "apps/api/app/api/[[...route]]/test.ts"
# Check the test file content
echo -e "\nChecking test file content:"
cat "apps/api/tests/hello.test.ts"
Length of output: 3285 |
||
app.route("/mail", mail); | ||
app.route("/auth", auth); | ||
app.route("/status", status); | ||
|
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.
🛠️ Refactor suggestion
Consider caching the dynamic import result
The dynamic import is executed on every request, which could introduce unnecessary latency. Additionally, the import failure isn't explicitly handled.
Consider moving the import outside the route handler and implementing proper error handling: