Skip to content

Commit ed79c21

Browse files
committed
fix: build errors
1 parent 444b483 commit ed79c21

File tree

3 files changed

+133
-66
lines changed

3 files changed

+133
-66
lines changed

apps/server/src/index.ts

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { db } from "@call/db";
55
import routes from "./routes/index.js";
66
import { Hono } from "hono";
77
import { logger } from "hono/logger";
8-
import { serve } from '@hono/node-server';
9-
import chalk from 'chalk';
10-
import { networkInterfaces } from 'os';
8+
import { serve } from "@hono/node-server";
9+
import chalk from "chalk";
10+
import { networkInterfaces } from "os";
1111

1212
export interface ReqVariables {
1313
user: typeof auth.$Infer.Session.user | null;
@@ -37,11 +37,11 @@ app.use(
3737
},
3838
credentials: true,
3939
allowHeaders: [
40-
"Content-Type",
41-
"Authorization",
40+
"Content-Type",
41+
"Authorization",
4242
"X-Requested-With",
4343
"Accept",
44-
"Origin"
44+
"Origin",
4545
],
4646
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"],
4747
exposeHeaders: ["Set-Cookie"],
@@ -74,49 +74,58 @@ const getNetworkIP = () => {
7474
const nets = networkInterfaces();
7575
for (const name of Object.keys(nets)) {
7676
for (const net of nets[name] || []) {
77-
if (net.family === 'IPv4' && !net.internal) {
77+
if (net.family === "IPv4" && !net.internal) {
7878
return net.address;
7979
}
8080
}
8181
}
82-
return '127.0.0.1';
82+
return "127.0.0.1";
8383
};
8484

8585
const logServerStart = (port: number) => {
8686
const networkIP = getNetworkIP();
87-
88-
console.log(chalk.cyan('\nServer Starting...'));
89-
console.log(chalk.gray('━'.repeat(50)));
87+
88+
console.log(chalk.cyan("\nServer Starting..."));
89+
console.log(chalk.gray("━".repeat(50)));
9090
console.log(chalk.green(`Server running on port ${port}`));
9191
console.log(chalk.blue(`Local: http://localhost:${port}`));
9292
console.log(chalk.blue(`Network: http://${networkIP}:${port}`));
93-
console.log(chalk.gray('━'.repeat(50)));
94-
console.log(chalk.yellow('Press Ctrl+C to stop\n'));
93+
console.log(chalk.gray("━".repeat(50)));
94+
console.log(chalk.yellow("Press Ctrl+C to stop\n"));
9595
};
9696

97-
const startServerWithEventHandling = async (startPort: number, maxAttempts: number = 50): Promise<void> => {
97+
const startServerWithEventHandling = async (
98+
startPort: number,
99+
maxAttempts: number = 50
100+
): Promise<void> => {
98101
return new Promise((resolve, reject) => {
99102
let currentPort = startPort;
100103
let attempts = 0;
101-
104+
102105
const tryPort = () => {
103106
if (attempts >= maxAttempts) {
104-
reject(new Error(`Could not start server after ${maxAttempts} attempts`));
107+
reject(
108+
new Error(`Could not start server after ${maxAttempts} attempts`)
109+
);
105110
return;
106111
}
107-
112+
108113
try {
109114
const server = serve({
110115
fetch: app.fetch,
111116
port: currentPort,
112-
hostname: '0.0.0.0',
117+
hostname: "0.0.0.0",
113118
});
114119

115-
server.once('error', (error: any) => {
116-
if (error.code === 'EADDRINUSE') {
120+
server.once("error", (error: any) => {
121+
if (error.code === "EADDRINUSE") {
117122
attempts++;
118123
currentPort++;
119-
console.log(chalk.yellow(`Port ${currentPort - 1} is busy, trying ${currentPort}...`));
124+
console.log(
125+
chalk.yellow(
126+
`Port ${currentPort - 1} is busy, trying ${currentPort}...`
127+
)
128+
);
120129
tryPort();
121130
} else {
122131
reject(error);
@@ -125,23 +134,25 @@ const startServerWithEventHandling = async (startPort: number, maxAttempts: numb
125134

126135
process.nextTick(() => {
127136
if (currentPort !== startPort) {
128-
console.log(chalk.yellow(`Port ${startPort} was busy, using ${currentPort} instead`));
137+
console.log(
138+
chalk.yellow(
139+
`Port ${startPort} was busy, using ${currentPort} instead`
140+
)
141+
);
129142
}
130143
logServerStart(currentPort);
131144
resolve();
132145
});
133-
134146
} catch (error) {
135147
reject(error);
136148
}
137149
};
138-
150+
139151
tryPort();
140152
});
141153
};
142154

143-
startServerWithEventHandling(Number(port))
144-
.catch((error) => {
145-
console.log(chalk.red(`\nFailed to start server: ${error.message}`));
146-
process.exit(1);
147-
});
155+
startServerWithEventHandling(Number(port)).catch((error) => {
156+
console.log(chalk.red(`\nFailed to start server: ${error.message}`));
157+
process.exit(1);
158+
});

apps/server/src/routes/auth/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ authRouter.patch("/update-profile", async (c) => {
5757
const result = updateProfileSchema.safeParse(body);
5858

5959
if (!result.success) {
60-
return c.json({ message: result.error.errors[0]?.message || "Invalid input" }, 400);
60+
return c.json(
61+
{ message: result.error.errors[0]?.message || "Invalid input" },
62+
400
63+
);
6164
}
6265

6366
const { name } = result.data;
@@ -107,15 +110,15 @@ authRouter.patch("/update-profile-image", async (c) => {
107110
// Update user profile with the new image
108111
await db
109112
.update(userTable)
110-
.set({
113+
.set({
111114
image: dataUrl,
112-
updatedAt: new Date()
115+
updatedAt: new Date(),
113116
})
114117
.where(eq(userTable.id, user.id));
115118

116-
return c.json({
119+
return c.json({
117120
message: "Profile image updated successfully",
118-
image: dataUrl
121+
image: dataUrl,
119122
});
120123
} catch (err) {
121124
console.error("[PATCH /update-profile-image] Error:", err);

apps/server/src/routes/contacts/index.ts

Lines changed: 85 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { contactRequests, contacts, user as userTable } from "@call/db/schema";
55
import { createId } from "@paralleldrive/cuid2";
66
import { and, eq, or } from "drizzle-orm";
77
import type { ReqVariables } from "../../index.js";
8-
import { sendMail } from '@call/auth/utils/send-mail';
8+
import { sendMail } from "@call/auth/utils/send-mail";
99

1010
const contactsRoutes = new Hono<{ Variables: ReqVariables }>();
1111

@@ -26,38 +26,54 @@ contactsRoutes.post("/invite", async (c) => {
2626
const result = inviteSchema.safeParse(body);
2727

2828
if (!result.success) {
29-
return c.json({ message: result.error.errors[0]?.message || "Invalid input" }, 400);
29+
return c.json(
30+
{ message: result.error.errors[0]?.message || "Invalid input" },
31+
400
32+
);
3033
}
3134
const { receiverEmail } = result.data;
3235

3336
if (receiverEmail === user.email) {
34-
return c.json({ message: "You cannot send a contact request to yourself." }, 400);
37+
return c.json(
38+
{ message: "You cannot send a contact request to yourself." },
39+
400
40+
);
3541
}
3642

37-
const [receiver] = await db.select({ id: userTable.id }).from(userTable).where(eq(userTable.email, receiverEmail));
43+
const [receiver] = await db
44+
.select({ id: userTable.id })
45+
.from(userTable)
46+
.where(eq(userTable.email, receiverEmail));
3847

3948
if (!receiver) {
4049
await sendMail({
4150
to: receiverEmail,
4251
subject: "Invitation to join Call",
4352
text: `You are invited to join Call by ${user.name} here is the link ${process.env.FRONTEND_URL}/login`,
44-
4553
});
46-
return c.json({ message: "Email sent to receiver to invite them to the app." }, 200);
54+
return c.json(
55+
{ message: "Email sent to receiver to invite them to the app." },
56+
200
57+
);
4758
}
4859

4960
const receiverId = receiver.id;
5061

51-
const [existingRelation] = await db
52-
.select({ check: contacts.userId })
53-
.from(contacts)
54-
.where(and(eq(contacts.userId, senderId), eq(contacts.contactId, receiverId)))
55-
.limit(1);
56-
57-
if (existingRelation) {
58-
return c.json({ message: "You are already contacts with this user." }, 409);
59-
}
60-
62+
const [existingRelation] = await db
63+
.select({ check: contacts.userId })
64+
.from(contacts)
65+
.where(
66+
and(eq(contacts.userId, senderId), eq(contacts.contactId, receiverId))
67+
)
68+
.limit(1);
69+
70+
if (existingRelation) {
71+
return c.json(
72+
{ message: "You are already contacts with this user." },
73+
409
74+
);
75+
}
76+
6177
const [existingRequest] = await db
6278
.select({ id: contactRequests.id })
6379
.from(contactRequests)
@@ -71,7 +87,10 @@ contactsRoutes.post("/invite", async (c) => {
7187
.limit(1);
7288

7389
if (existingRequest) {
74-
return c.json({ message: "A pending request to this user already exists." }, 409);
90+
return c.json(
91+
{ message: "A pending request to this user already exists." },
92+
409
93+
);
7594
}
7695

7796
await db.insert(contactRequests).values({
@@ -105,10 +124,15 @@ contactsRoutes.get("/requests", async (c) => {
105124
})
106125
.from(contactRequests)
107126
.leftJoin(userTable, eq(contactRequests.senderId, userTable.id))
108-
.where(and(eq(contactRequests.receiverId, userId), eq(contactRequests.status, "pending")));
127+
.where(
128+
and(
129+
eq(contactRequests.receiverId, userId),
130+
eq(contactRequests.status, "pending")
131+
)
132+
);
109133

110134
// Ensure senderName and senderEmail are always present (fallback to empty string if null)
111-
const requests = pendingRequests.map(r => ({
135+
const requests = pendingRequests.map((r) => ({
112136
...r,
113137
senderName: r.senderName || "",
114138
senderEmail: r.senderEmail || "",
@@ -131,15 +155,30 @@ contactsRoutes.patch("/requests/:id/accept", async (c) => {
131155
const [request] = await tx
132156
.select()
133157
.from(contactRequests)
134-
.where(and(eq(contactRequests.id, requestId), eq(contactRequests.receiverId, userId), eq(contactRequests.status, "pending")));
158+
.where(
159+
and(
160+
eq(contactRequests.id, requestId),
161+
eq(contactRequests.receiverId, userId),
162+
eq(contactRequests.status, "pending")
163+
)
164+
);
135165

136166
if (!request) {
137-
return c.json({ message: "Request not found, already handled, or you are not the recipient." }, 404);
167+
return c.json(
168+
{
169+
message:
170+
"Request not found, already handled, or you are not the recipient.",
171+
},
172+
404
173+
);
138174
}
139-
175+
140176
const senderId = request.senderId;
141177

142-
await tx.update(contactRequests).set({ status: "accepted" }).where(eq(contactRequests.id, requestId));
178+
await tx
179+
.update(contactRequests)
180+
.set({ status: "accepted" })
181+
.where(eq(contactRequests.id, requestId));
143182

144183
await tx.insert(contacts).values([
145184
{ userId: userId, contactId: senderId, createdAt: new Date() },
@@ -163,10 +202,22 @@ contactsRoutes.patch("/requests/:id/reject", async (c) => {
163202
const { rowCount } = await db
164203
.update(contactRequests)
165204
.set({ status: "rejected" })
166-
.where(and(eq(contactRequests.id, requestId), eq(contactRequests.receiverId, userId), eq(contactRequests.status, "pending")));
205+
.where(
206+
and(
207+
eq(contactRequests.id, requestId),
208+
eq(contactRequests.receiverId, userId),
209+
eq(contactRequests.status, "pending")
210+
)
211+
);
167212

168213
if (rowCount === 0) {
169-
return c.json({ message: "Request not found, already handled, or you are not the recipient." }, 404);
214+
return c.json(
215+
{
216+
message:
217+
"Request not found, already handled, or you are not the recipient.",
218+
},
219+
404
220+
);
170221
}
171222

172223
return c.json({ message: "Contact request rejected." });
@@ -207,12 +258,14 @@ contactsRoutes.delete("/:id", async (c) => {
207258
try {
208259
await db.transaction(async (tx) => {
209260
// Delete both sides of the contact relationship
210-
await tx.delete(contacts).where(
211-
or(
212-
and(eq(contacts.userId, userId), eq(contacts.contactId, contactId)),
213-
and(eq(contacts.userId, contactId), eq(contacts.contactId, userId))
214-
)
215-
);
261+
await tx
262+
.delete(contacts)
263+
.where(
264+
or(
265+
and(eq(contacts.userId, userId), eq(contacts.contactId, contactId)),
266+
and(eq(contacts.userId, contactId), eq(contacts.contactId, userId))
267+
)
268+
);
216269
});
217270

218271
return c.json({ message: "Contact deleted successfully." });
@@ -222,4 +275,4 @@ contactsRoutes.delete("/:id", async (c) => {
222275
}
223276
});
224277

225-
export default contactsRoutes;
278+
export default contactsRoutes;

0 commit comments

Comments
 (0)