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
1 change: 1 addition & 0 deletions apps/backend/src/jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jest.mock("@repo/database", () => {
});

beforeAll(async () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const { apply } = await pushSchema(schema, db as any);
await apply();
});
Expand Down
5 changes: 2 additions & 3 deletions apps/backend/src/middlewares/error.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Request, Response, NextFunction, ErrorRequestHandler } from "express";
import { Request, Response, ErrorRequestHandler } from "express";
import { ReasonPhrases, StatusCodes } from "http-status-codes";
import { GenericError } from "@repo/backend/utils/errors";

const errorHandler: ErrorRequestHandler = (
error: unknown,
req: Request,
res: Response,
next: NextFunction
res: Response
) => {
console.error(error);

Expand Down
6 changes: 4 additions & 2 deletions apps/backend/src/middlewares/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import { Request, Response, NextFunction } from "express";
import { z, ZodError } from "zod";
import { BadRequestError } from "@repo/backend/utils/errors";

const validateHandler = (schema: z.ZodObject<any, any>) => {
const validateHandler = (schema: z.ZodSchema) => {
return (req: Request, res: Response, next: NextFunction) => {
try {
schema.parse(req);
next();
} catch (error) {
if (error instanceof ZodError) {
const errorMessages = error.errors
.map((issue: any) => `${issue.path.join(".")} is ${issue.message}`)
.map(
(issue: z.ZodIssue) => `${issue.path.join(".")} is ${issue.message}`
)
.join(", ");
throw new BadRequestError(errorMessages);
} else {
Expand Down
1 change: 0 additions & 1 deletion apps/backend/src/modules/auth/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ describe("Auth API", () => {
.returning();

const refreshToken = jwtSignRefreshToken({ userId: user[0].id });
const hashedToken = await argon2.hash(refreshToken);
await db.insert(refreshTokens).values({
userId: user[0].id,
token: "invalidToken",
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/modules/chat/chat.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { and, asc, count, desc, eq, exists, notExists } from "drizzle-orm";
import { and, count, desc, eq, exists, notExists } from "drizzle-orm";
import { db } from "@repo/database";
import {
chatParticipants,
Expand Down
1 change: 1 addition & 0 deletions apps/backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"lib": ["ES2015"],
"outDir": "./dist",
"target": "es2017",
"paths": {
"@repo/backend/*": ["./src/*"]
}
Expand Down
10 changes: 5 additions & 5 deletions packages/database/drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ export default defineConfig({
schema: "./src/schema/*.ts",
dialect: "postgresql",
dbCredentials: {
host: process.env.POSTGRES_HOST,
port: process.env.POSTGRES_PORT,
database: process.env.POSTGRES_DATABASE,
user: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
host: process.env.POSTGRES_HOST!,
port: Number(process.env.POSTGRES_PORT!),
database: process.env.POSTGRES_DATABASE!,
user: process.env.POSTGRES_USER!,
password: process.env.POSTGRES_PASSWORD!,
},
});
20 changes: 10 additions & 10 deletions packages/database/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Pool } from "pg";
import { drizzle } from "drizzle-orm/node-postgres";
import * as schema from "./schema";

const db = drizzle({
schema: schema,
connection: {
host: process.env.POSTGRES_HOST,
port: process.env.POSTGRES_PORT,
database: process.env.POSTGRES_DATABASE,
user: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
ssl: true,
},
const pool = new Pool({
host: process.env.POSTGRES_HOST,
port: Number(process.env.POSTGRES_PORT!),
database: process.env.POSTGRES_DATABASE,
user: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
ssl: true,
});

const db = drizzle(pool, { schema });

const dbTestConnection = async () => {
try {
const result = await db.execute("SELECT NOW()");
Expand Down
1 change: 0 additions & 1 deletion packages/database/src/schema/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { sql } from "drizzle-orm";
import { timestamp } from "drizzle-orm/pg-core";

const timeStamps = (softDelete = false) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/database/src/schema/messages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pgTable, integer, text, timestamp, uuid } from "drizzle-orm/pg-core";
import { pgTable, integer, text, timestamp } from "drizzle-orm/pg-core";
import { timeStamps } from "./base";
import { chats } from "./chats";
import { users } from "./users";
Expand Down
39 changes: 18 additions & 21 deletions packages/database/src/schema/realtions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export const usersRealtions = relations(users, ({ one, many }) => ({

export const userPrivacySettingsRelations = relations(
userPrivacySettings,
({ one, many }) => ({
({ one }) => ({
user: one(users, {
fields: [userPrivacySettings.userId],
references: [users.id],
}),
})
);

export const friendsRealtions = relations(friends, ({ one, many }) => ({
export const friendsRealtions = relations(friends, ({ one }) => ({
userA: one(users, {
fields: [friends.userA],
references: [users.id],
Expand All @@ -35,30 +35,27 @@ export const friendsRealtions = relations(friends, ({ one, many }) => ({
}),
}));

export const blockedUsersRelations = relations(
blockedUsers,
({ one, many }) => ({
blocker: one(users, {
fields: [blockedUsers.blockerId],
references: [users.id],
relationName: "blocker",
}),
blocked: one(users, {
fields: [blockedUsers.blockedId],
references: [users.id],
relationName: "blocked",
}),
})
);
export const blockedUsersRelations = relations(blockedUsers, ({ one }) => ({
blocker: one(users, {
fields: [blockedUsers.blockerId],
references: [users.id],
relationName: "blocker",
}),
blocked: one(users, {
fields: [blockedUsers.blockedId],
references: [users.id],
relationName: "blocked",
}),
}));

export const chatsRelations = relations(chats, ({ one, many }) => ({
export const chatsRelations = relations(chats, ({ many }) => ({
chatParticipants: many(chatParticipants),
messages: many(messages),
}));

export const chatParticipantsRelations = relations(
chatParticipants,
({ one, many }) => ({
({ one }) => ({
user: one(users, {
fields: [chatParticipants.userId],
references: [users.id],
Expand All @@ -70,7 +67,7 @@ export const chatParticipantsRelations = relations(
})
);

export const messagesRelations = relations(messages, ({ one, many }) => ({
export const messagesRelations = relations(messages, ({ one }) => ({
sender: one(users, {
fields: [messages.senderId],
references: [users.id],
Expand All @@ -84,7 +81,7 @@ export const messagesRelations = relations(messages, ({ one, many }) => ({

export const messageReadReceiptsRelations = relations(
messageReadReceipts,
({ one, many }) => ({
({ one }) => ({
chat: one(chats, {
fields: [messageReadReceipts.chatId],
references: [chats.id],
Expand Down
Loading