Skip to content

Commit 2cc080f

Browse files
authored
Merge pull request #33 from azeddine-hmd/dev
Major change
2 parents 080e299 + 96c2f81 commit 2cc080f

File tree

111 files changed

+3052
-1016
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+3052
-1016
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.env
22
.postgres
3+
.cache

backend/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,5 @@ dist
132132

133133
# upload
134134
uploads/
135+
136+
.cache

backend/Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:18
1+
FROM node:20.11.0
22

33
RUN mkdir /usr/src/app
44
WORKDIR /usr/src/app
@@ -11,10 +11,8 @@ else \
1111
npm ci; \
1212
fi
1313

14-
COPY prisma ./prisma
15-
RUN npx prisma generate
16-
1714
COPY . ./
15+
RUN npm install -g prisma
1816

1917
RUN chmod +x ./scripts/entrypoint.sh
2018
CMD ["./scripts/entrypoint.sh"]

backend/package-lock.json

Lines changed: 200 additions & 121 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"author": "Azeddine Hamdaoui",
2121
"license": "ISC",
2222
"dependencies": {
23-
"@prisma/client": "^5.4.2",
23+
"@prisma/client": "^5.8.1",
2424
"@socket.io/postgres-adapter": "^0.3.1",
2525
"bcrypt": "^5.1.0",
2626
"body-parser": "^1.20.2",
@@ -32,18 +32,16 @@
3232
"express": "^5.0.0-beta.1",
3333
"express-session": "^1.17.3",
3434
"helmet": "^7.0.0",
35-
"mailgun.js": "^9.2.0",
3635
"multer": "^1.4.5-lts.1",
37-
"node-request-interceptor": "^0.6.3",
3836
"nodemailer": "^6.9.4",
3937
"passport": "^0.6.0",
4038
"passport-jwt": "^4.0.1",
4139
"pg": "^8.11.3",
40+
"redis": "^4.6.12",
4241
"socket.io": "^4.7.2",
4342
"swagger-jsdoc": "^6.2.8",
4443
"swagger-ui-express": "^5.0.0",
45-
"ts-node": "^10.9.1",
46-
"typescript": "^5.1.6"
44+
"uuid": "^9.0.1"
4745
},
4846
"devDependencies": {
4947
"@types/bcrypt": "^5.0.0",
@@ -62,6 +60,7 @@
6260
"@types/supertest": "^2.0.15",
6361
"@types/swagger-jsdoc": "^6.0.4",
6462
"@types/swagger-ui-express": "^4.1.6",
63+
"@types/uuid": "^9.0.8",
6564
"@typescript-eslint/eslint-plugin": "^5.62.0",
6665
"eslint": "^8.44.0",
6766
"eslint-config-prettier": "^8.8.0",
@@ -74,10 +73,12 @@
7473
"jest-mock-extended": "^3.0.5",
7574
"npm-run-all": "^4.1.5",
7675
"prettier": "^3.0.0",
77-
"prisma": "^5.4.2",
76+
"prisma": "^5.8.1",
7877
"socket.io-client": "^4.7.2",
7978
"supertest": "^6.3.3",
80-
"ts-jest": "^29.1.1"
79+
"ts-jest": "^29.1.1",
80+
"ts-node": "^10.9.2",
81+
"typescript": "^5.3.3"
8182
},
8283
"optionalDependencies": {
8384
"bufferutil": "^4.0.8",
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
-- CreateEnum
2+
CREATE TYPE "DMType" AS ENUM ('SINGLE', 'GROUP');
3+
4+
-- CreateTable
5+
CREATE TABLE "DM" (
6+
"id" TEXT NOT NULL,
7+
"createAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
8+
"type" "DMType" NOT NULL,
9+
10+
CONSTRAINT "DM_pkey" PRIMARY KEY ("id")
11+
);
12+
13+
-- CreateTable
14+
CREATE TABLE "UserDm" (
15+
"id" SERIAL NOT NULL,
16+
"userId" INTEGER NOT NULL,
17+
"dmId" TEXT NOT NULL,
18+
19+
CONSTRAINT "UserDm_pkey" PRIMARY KEY ("id")
20+
);
21+
22+
-- CreateTable
23+
CREATE TABLE "Message" (
24+
"id" SERIAL NOT NULL,
25+
"createAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
26+
"dmId" TEXT NOT NULL,
27+
"replyId" INTEGER,
28+
29+
CONSTRAINT "Message_pkey" PRIMARY KEY ("id")
30+
);
31+
32+
-- CreateIndex
33+
CREATE UNIQUE INDEX "UserDm_userId_dmId_key" ON "UserDm"("userId", "dmId");
34+
35+
-- CreateIndex
36+
CREATE UNIQUE INDEX "Message_replyId_key" ON "Message"("replyId");
37+
38+
-- AddForeignKey
39+
ALTER TABLE "UserDm" ADD CONSTRAINT "UserDm_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
40+
41+
-- AddForeignKey
42+
ALTER TABLE "UserDm" ADD CONSTRAINT "UserDm_dmId_fkey" FOREIGN KEY ("dmId") REFERENCES "DM"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
43+
44+
-- AddForeignKey
45+
ALTER TABLE "Message" ADD CONSTRAINT "Message_dmId_fkey" FOREIGN KEY ("dmId") REFERENCES "DM"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
46+
47+
-- AddForeignKey
48+
ALTER TABLE "Message" ADD CONSTRAINT "Message_replyId_fkey" FOREIGN KEY ("replyId") REFERENCES "Message"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
Warnings:
3+
4+
- Added the required column `entersAt` to the `DM` table without a default value. This is not possible if the table is not empty.
5+
6+
*/
7+
-- AlterTable
8+
ALTER TABLE "DM" ADD COLUMN "entersAt" TIMESTAMP(3) NOT NULL;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `createAt` on the `DM` table. All the data in the column will be lost.
5+
6+
*/
7+
-- AlterTable
8+
ALTER TABLE "DM" DROP COLUMN "createAt",
9+
ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Warnings:
3+
4+
- Added the required column `messageContentId` to the `Message` table without a default value. This is not possible if the table is not empty.
5+
6+
*/
7+
-- CreateEnum
8+
CREATE TYPE "MessageContentType" AS ENUM ('TEXT', 'IMAGE');
9+
10+
-- AlterTable
11+
ALTER TABLE "Message" ADD COLUMN "messageContentId" INTEGER NOT NULL;
12+
13+
-- CreateTable
14+
CREATE TABLE "MessageContent" (
15+
"id" SERIAL NOT NULL,
16+
"type" "MessageContentType" NOT NULL,
17+
"contentText" TEXT,
18+
"fileId" INTEGER,
19+
20+
CONSTRAINT "MessageContent_pkey" PRIMARY KEY ("id")
21+
);
22+
23+
-- AddForeignKey
24+
ALTER TABLE "Message" ADD CONSTRAINT "Message_messageContentId_fkey" FOREIGN KEY ("messageContentId") REFERENCES "MessageContent"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
25+
26+
-- AddForeignKey
27+
ALTER TABLE "MessageContent" ADD CONSTRAINT "MessageContent_fileId_fkey" FOREIGN KEY ("fileId") REFERENCES "File"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- DropForeignKey
2+
ALTER TABLE "UserDm" DROP CONSTRAINT "UserDm_dmId_fkey";
3+
4+
-- DropForeignKey
5+
ALTER TABLE "UserDm" DROP CONSTRAINT "UserDm_userId_fkey";
6+
7+
-- AddForeignKey
8+
ALTER TABLE "UserDm" ADD CONSTRAINT "UserDm_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
9+
10+
-- AddForeignKey
11+
ALTER TABLE "UserDm" ADD CONSTRAINT "UserDm_dmId_fkey" FOREIGN KEY ("dmId") REFERENCES "DM"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `messageContentId` on the `Message` table. All the data in the column will be lost.
5+
- A unique constraint covering the columns `[messageId]` on the table `MessageContent` will be added. If there are existing duplicate values, this will fail.
6+
- Added the required column `messageId` to the `MessageContent` table without a default value. This is not possible if the table is not empty.
7+
8+
*/
9+
-- DropForeignKey
10+
ALTER TABLE "Message" DROP CONSTRAINT "Message_messageContentId_fkey";
11+
12+
-- DropForeignKey
13+
ALTER TABLE "MessageContent" DROP CONSTRAINT "MessageContent_fileId_fkey";
14+
15+
-- AlterTable
16+
ALTER TABLE "Message" DROP COLUMN "messageContentId";
17+
18+
-- AlterTable
19+
ALTER TABLE "MessageContent" ADD COLUMN "messageId" INTEGER NOT NULL;
20+
21+
-- CreateIndex
22+
CREATE UNIQUE INDEX "MessageContent_messageId_key" ON "MessageContent"("messageId");
23+
24+
-- AddForeignKey
25+
ALTER TABLE "MessageContent" ADD CONSTRAINT "MessageContent_fileId_fkey" FOREIGN KEY ("fileId") REFERENCES "File"("id") ON DELETE CASCADE ON UPDATE CASCADE;
26+
27+
-- AddForeignKey
28+
ALTER TABLE "MessageContent" ADD CONSTRAINT "MessageContent_messageId_fkey" FOREIGN KEY ("messageId") REFERENCES "Message"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- DropForeignKey
2+
ALTER TABLE "Message" DROP CONSTRAINT "Message_dmId_fkey";
3+
4+
-- AlterTable
5+
ALTER TABLE "Message" ALTER COLUMN "dmId" DROP NOT NULL;
6+
7+
-- AddForeignKey
8+
ALTER TABLE "Message" ADD CONSTRAINT "Message_dmId_fkey" FOREIGN KEY ("dmId") REFERENCES "DM"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- DropForeignKey
2+
ALTER TABLE "MessageContent" DROP CONSTRAINT "MessageContent_messageId_fkey";
3+
4+
-- AddForeignKey
5+
ALTER TABLE "MessageContent" ADD CONSTRAINT "MessageContent_messageId_fkey" FOREIGN KEY ("messageId") REFERENCES "Message"("id") ON DELETE CASCADE ON UPDATE CASCADE;

backend/prisma/schema.prisma

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ enum UserStatus {
1616
OFFLINE
1717
}
1818

19+
enum DMType {
20+
SINGLE
21+
GROUP
22+
}
23+
1924
model User {
2025
id Int @id @default(autoincrement())
2126
displayName String
@@ -28,6 +33,7 @@ model User {
2833
avatar File?
2934
Codes Codes[]
3035
sockets UserSockets[]
36+
userDms UserDm[]
3137
3238
Friend1 Friendship[] @relation("Friend1")
3339
Friend2 Friendship[] @relation("Friend2")
@@ -108,5 +114,53 @@ model File {
108114
createdAt DateTime @default(now())
109115
updatedAt DateTime @updatedAt
110116
111-
uploadedBy User @relation(fields: [uploadedById], references: [id], onDelete: Cascade)
117+
uploadedBy User @relation(fields: [uploadedById], references: [id], onDelete: Cascade)
118+
MessageContent MessageContent[]
119+
}
120+
121+
model DM {
122+
id String @id
123+
createdAt DateTime @default(now())
124+
entersAt DateTime
125+
type DMType
126+
Message Message[]
127+
userDms UserDm[]
128+
}
129+
130+
model UserDm {
131+
id Int @id @default(autoincrement())
132+
userId Int
133+
dmId String
134+
135+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
136+
dm DM @relation(fields: [dmId], references: [id], onDelete: Cascade)
137+
138+
@@unique([userId, dmId])
139+
}
140+
141+
model Message {
142+
id Int @id @default(autoincrement())
143+
createAt DateTime @default(now())
144+
dmId String?
145+
replyId Int? @unique
146+
messageContent MessageContent?
147+
148+
dm DM? @relation(fields: [dmId], references: [id])
149+
reply Message? @relation("replyMessage", fields: [replyId], references: [id])
150+
repliedTo Message? @relation("replyMessage")
151+
}
152+
153+
enum MessageContentType {
154+
TEXT
155+
IMAGE
156+
}
157+
158+
model MessageContent {
159+
id Int @id @default(autoincrement())
160+
type MessageContentType
161+
contentText String?
162+
contentFile File? @relation(fields: [fileId], references: [id], onDelete: Cascade)
163+
message Message @relation(fields: [messageId], references: [id], onDelete: Cascade)
164+
messageId Int @unique
165+
fileId Int?
112166
}

backend/scripts/entrypoint.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
npx prisma studio &
44
npx prisma db push
5-
mkdir uploads/
5+
npx prisma generate
6+
mkdir uploads/ 2> /dev/null
67

78
if [ "$NODE_ENV" == "production" ]; then
89
npx prisma migrate deploy
910
npm run build
1011
npm run start
1112
else
12-
npx prisma generate --watch &
13-
npx prisma migrate dev
13+
prisma generate --watch &
14+
prisma migrate dev
15+
npx prisma db seed
1416
npm run dev
1517
fi

backend/src/api/dm/dm-mapper.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { mapToPublicProfile } from '../users/users-mapper';
2+
import { SingleDm } from './types/single-dm';
3+
4+
export function mapToPublicDm(singleDm: SingleDm) {
5+
return {
6+
id: singleDm.id,
7+
type: singleDm.type,
8+
other: mapToPublicProfile(singleDm.other),
9+
};
10+
}

backend/src/api/dm/message-mapper.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Message } from '@prisma/client';
2+
3+
// type MessageMapper = {
4+
// id: number;
5+
// renderType: 'short' | 'normal';
6+
// content: /*TODO */
7+
// };
8+
9+
export function mapToMessage(message: Message) {
10+
return {
11+
id: message.id,
12+
};
13+
}

0 commit comments

Comments
 (0)