Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/backend/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ const environmentVariableSchema = z.object({
.string()
.regex(
/^\d+[smhd]$/,
"Invalid JWT expiry format. Use formats like '15m', '1h', '7d'."
"Invalid JWT expiry format. Use formats like '15m', '1h', '7d'.",
)
.transform((val) => val as `${number}${"s" | "m" | "h" | "d"}`)
.default("15m"),
JWT_REFRESH_TOKEN_EXPIRY: z
.string()
.regex(
/^\d+[smhd]$/,
"Invalid JWT expiry format. Use formats like '15m', '1h', '7d'."
"Invalid JWT expiry format. Use formats like '15m', '1h', '7d'.",
)
.transform((val) => val as `${number}${"s" | "m" | "h" | "d"}`)
.default("7d"),
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/middlewares/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { GenericError } from "@repo/backend/utils/errors";
const errorHandler: ErrorRequestHandler = (
error: unknown,
req: Request,
res: Response
res: Response,
) => {
console.error(error);

Expand Down
3 changes: 2 additions & 1 deletion apps/backend/src/middlewares/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const validateHandler = (schema: z.ZodSchema) => {
if (error instanceof ZodError) {
const errorMessages = error.errors
.map(
(issue: z.ZodIssue) => `${issue.path.join(".")} is ${issue.message}`
(issue: z.ZodIssue) =>
`${issue.path.join(".")} is ${issue.message}`,
)
.join(", ");
throw new BadRequestError(errorMessages);
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/modules/auth/auth.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ authRouter.post("/send-otp", validateHandler(sendOtpSchema), sendOtpController);
authRouter.post(
"/verify-otp",
validateHandler(verifyOtpSchema),
verifyOtpController
verifyOtpController,
);

authRouter.get(
"/refresh-token",
validateHandler(refreshTokenSchema),
refreshTokenController
refreshTokenController,
);

authRouter.get("/logout", logoutController);
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {

const twilioClient = twilio(
process.env.TWILIO_ACCOUNT_SID,
process.env.TWILIO_AUTH_TOKEN
process.env.TWILIO_AUTH_TOKEN,
);

const sendOtp = async (phoneNumber: string) => {
Expand Down
12 changes: 6 additions & 6 deletions apps/backend/src/modules/auth/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe("Auth API", () => {
const endIndex = cookie[0].indexOf(";", startIndex);
const extractedToken = cookie[0].slice(startIndex, endIndex);
expect(await argon2.verify(refreshTokenRow!.token, extractedToken)).toBe(
true
true,
);
});

Expand Down Expand Up @@ -194,7 +194,7 @@ describe("Auth API", () => {
.get("/api/v1/auth/refresh-token")
.set(
"Cookie",
`${process.env.JWT_REFRESH_TOKEN_COOKIE_KEY}=invalidToken`
`${process.env.JWT_REFRESH_TOKEN_COOKIE_KEY}=invalidToken`,
);

expect(res.status).toBe(401);
Expand All @@ -218,7 +218,7 @@ describe("Auth API", () => {
.get("/api/v1/auth/refresh-token")
.set(
"Cookie",
`${process.env.JWT_REFRESH_TOKEN_COOKIE_KEY}=${refreshToken}`
`${process.env.JWT_REFRESH_TOKEN_COOKIE_KEY}=${refreshToken}`,
);

expect(res.status).toBe(401);
Expand All @@ -245,7 +245,7 @@ describe("Auth API", () => {
.get("/api/v1/auth/refresh-token")
.set(
"Cookie",
`${process.env.JWT_REFRESH_TOKEN_COOKIE_KEY}=${refreshToken}`
`${process.env.JWT_REFRESH_TOKEN_COOKIE_KEY}=${refreshToken}`,
);

expect(res.status).toBe(401);
Expand All @@ -267,7 +267,7 @@ describe("Auth API", () => {
.get("/api/v1/auth/refresh-token")
.set(
"Cookie",
`${process.env.JWT_REFRESH_TOKEN_COOKIE_KEY}=${refreshToken}`
`${process.env.JWT_REFRESH_TOKEN_COOKIE_KEY}=${refreshToken}`,
);

expect(res.status).toBe(401);
Expand Down Expand Up @@ -298,7 +298,7 @@ describe("Auth API", () => {

expect(
cookieHeader.includes("Max-Age=0") ||
cookieHeader.includes("Expires=Thu, 01 Jan 1970")
cookieHeader.includes("Expires=Thu, 01 Jan 1970"),
).toBe(true);

expect(cookieHeader.includes("refreshToken=;")).toBeDefined();
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/modules/chat/chat.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ const getChatsController = async (req: AuthenticatedRequest, res: Response) => {

const getChatDetailsController = async (
req: AuthenticatedRequest,
res: Response
res: Response,
) => {
const { chatId } = req.params;
const { page, limit } = req.query;
const chatDetails = await getChatDetails(
req.user.id,
parseInt(chatId),
parseInt(page as string),
parseInt(limit as string)
parseInt(limit as string),
);
res.status(StatusCodes.OK).json({ chatDetails });
};
Expand Down
18 changes: 9 additions & 9 deletions apps/backend/src/modules/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const getChats = async (userId: number) => {
db
.select()
.from(chatParticipants)
.where(eq(chatParticipants.userId, users.id))
)
.where(eq(chatParticipants.userId, users.id)),
),
);

return await Promise.all(
Expand Down Expand Up @@ -47,31 +47,31 @@ const getChats = async (userId: number) => {
.where(
and(
eq(messageReadReceipts.chatId, chat.id),
eq(messageReadReceipts.userId, userId)
)
)
)
eq(messageReadReceipts.userId, userId),
),
),
),
);

return {
...chat,
latestMessage,
unreadMessagesCount,
};
})
}),
);
};

const getChatDetails = async (
userId: number,
chatId: number,
page: number,
limit: number
limit: number,
) => {
const isParticipant = await db.query.chatParticipants.findFirst({
where: and(
eq(chatParticipants.userId, userId),
eq(chatParticipants.chatId, chatId)
eq(chatParticipants.chatId, chatId),
),
});
if (!isParticipant)
Expand Down
10 changes: 5 additions & 5 deletions apps/backend/src/modules/friends/friends.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import {

const getFriendsController = async (
req: AuthenticatedRequest,
res: Response
res: Response,
) => {
const friends = await getFriends(req.user.id);
res.status(StatusCodes.OK).json({ friends });
};

const addFriendController = async (
req: AuthenticatedRequest,
res: Response
res: Response,
) => {
const { friendId } = req.params;
await addFriend(req.user.id, parseInt(friendId));
Expand All @@ -30,7 +30,7 @@ const addFriendController = async (

const deleteFriendController = async (
req: AuthenticatedRequest,
res: Response
res: Response,
) => {
const { friendId } = req.params;
await deleteFriend(req.user.id, parseInt(friendId));
Expand All @@ -39,7 +39,7 @@ const deleteFriendController = async (

const acceptFriendRequestController = async (
req: AuthenticatedRequest,
res: Response
res: Response,
) => {
const { friendId } = req.params;
await acceptFriendRequest(req.user.id, parseInt(friendId));
Expand All @@ -48,7 +48,7 @@ const acceptFriendRequestController = async (

const denyFriendRequestController = async (
req: AuthenticatedRequest,
res: Response
res: Response,
) => {
const { friendId } = req.params;
await denyFriendRequest(req.user.id, parseInt(friendId));
Expand Down
16 changes: 6 additions & 10 deletions apps/backend/src/modules/friends/friends.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,32 @@ friendsRouter.get("/", (req, res) => {
getFriendsController(req as AuthenticatedRequest, res as Response);
});

friendsRouter.post(
"/:friendId",
validateHandler(friendsSchema),
(req, res) => {
addFriendController(req as AuthenticatedRequest, res as Response);
}
);
friendsRouter.post("/:friendId", validateHandler(friendsSchema), (req, res) => {
addFriendController(req as AuthenticatedRequest, res as Response);
});

friendsRouter.delete(
"/:friendId",
validateHandler(friendsSchema),
(req, res) => {
deleteFriendController(req as AuthenticatedRequest, res as Response);
}
},
);

friendsRouter.post(
"/:friendId/accept",
validateHandler(friendsSchema),
(req, res) => {
acceptFriendRequestController(req as AuthenticatedRequest, res as Response);
}
},
);

friendsRouter.post(
"/:friendId/deny",
validateHandler(friendsSchema),
(req, res) => {
denyFriendRequestController(req as AuthenticatedRequest, res as Response);
}
},
);

export default friendsRouter;
22 changes: 11 additions & 11 deletions apps/backend/src/modules/friends/friends.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ const getFriends = async (userId: number) => {
users,
and(
eq(friends.status, "accepted"),
or(eq(friends.userA, userId), eq(friends.userB, userId))
)
or(eq(friends.userA, userId), eq(friends.userB, userId)),
),
)
.where(
and(
not(eq(users.id, userId)) // Exclude self from results
)
not(eq(users.id, userId)), // Exclude self from results
),
);

const friendsRequestsSent = await db
Expand Down Expand Up @@ -67,7 +67,7 @@ const addFriend = async (userId: number, friendId: number) => {
const friendship = await db.query.friends.findFirst({
where: or(
and(eq(friends.userA, userId), eq(friends.userB, friendId)),
and(eq(friends.userB, userId), eq(friends.userA, friendId))
and(eq(friends.userB, userId), eq(friends.userA, friendId)),
),
with: {
userA: true,
Expand Down Expand Up @@ -98,8 +98,8 @@ const deleteFriend = async (userId: number, friendId: number) => {
.where(
or(
and(eq(friends.userA, userId), eq(friends.userB, friendId)),
and(eq(friends.userB, userId), eq(friends.userA, friendId))
)
and(eq(friends.userB, userId), eq(friends.userA, friendId)),
),
)
.returning();

Expand All @@ -115,8 +115,8 @@ const acceptFriendRequest = async (userId: number, friendId: number) => {
and(
eq(friends.userA, userId),
eq(friends.userB, friendId),
eq(friends.status, "pending")
)
eq(friends.status, "pending"),
),
)
.returning();

Expand All @@ -132,8 +132,8 @@ const denyFriendRequest = async (userId: number, friendId: number) => {
and(
eq(friends.userA, userId),
eq(friends.userB, friendId),
eq(friends.status, "pending")
)
eq(friends.status, "pending"),
),
)
.returning();

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const createServer = (): Express => {
rateLimit({
windowMs: process.env.WINDOW_SIZE_IN_MINUTES * 60 * 1000,
max: process.env.MAX_NUMBER_OF_REQUESTS_PER_WINDOW_SIZE,
})
}),
)
.get("/healthcheck", (_req, res) => {
res.json({
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ServerError extends GenericError {
super(
ReasonPhrases.INTERNAL_SERVER_ERROR,
StatusCodes.INTERNAL_SERVER_ERROR,
message
message,
);
}
}
Expand All @@ -40,7 +40,7 @@ export class RateLimitError extends GenericError {
super(
ReasonPhrases.TOO_MANY_REQUESTS,
StatusCodes.TOO_MANY_REQUESTS,
message
message,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/database/src/schema/friendships.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const friends = pgTable(
status: friendStatusEnum().notNull().default("pending"),
...timeStamps(false),
},
(table) => [primaryKey({ columns: [table.userA, table.userB] })]
(table) => [primaryKey({ columns: [table.userA, table.userB] })],
);

export const blockedUsers = pgTable("blocked_users", {
Expand Down
6 changes: 3 additions & 3 deletions packages/database/src/schema/realtions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const userPrivacySettingsRelations = relations(
fields: [userPrivacySettings.userId],
references: [users.id],
}),
})
}),
);

export const friendsRealtions = relations(friends, ({ one }) => ({
Expand Down Expand Up @@ -64,7 +64,7 @@ export const chatParticipantsRelations = relations(
fields: [chatParticipants.chatId],
references: [chats.id],
}),
})
}),
);

export const messagesRelations = relations(messages, ({ one }) => ({
Expand Down Expand Up @@ -94,5 +94,5 @@ export const messageReadReceiptsRelations = relations(
fields: [messageReadReceipts.userId],
references: [users.id],
}),
})
}),
);
2 changes: 1 addition & 1 deletion packages/eslint-config/next.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ export const config = [
// React scope no longer necessary with new JSX transform.
"react/react-in-jsx-scope": "off",
},
}
},
];
Loading
Loading