Skip to content

Commit fa33c79

Browse files
Merge pull request #17 from CUSW-chula/dev
Dev to main v0.1.0
2 parents c71ba70 + fd47b9b commit fa33c79

31 files changed

+3199
-111
lines changed

.github/workflows/deploy.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,15 @@ jobs:
7272
run: |
7373
bun --version # Check if Bun is installed correctly
7474
75+
- name: Bun installation
76+
run: |
77+
bun install # Check if Bun is installed correctly
78+
7579
- name: Lint code
7680
run: |
7781
echo "Running lint checks..."
7882
bun run lint # Run lint using Bun
7983
- name: Unit test
80-
run: /
84+
run: |
8185
echo "Running unit test..."
82-
bun run test
86+
bun test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ yarn-error.log*
3333

3434
# vercel
3535
.vercel
36+
bun.lockb
3637
.env
3738

3839
**/*.trace

.husky/pre-commit

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
bun run lint:fix
2-
bun run format:fix
2+
bun run format:fix
3+
bun test

Dockerfile

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
1-
FROM oven/bun
1+
# Use a specific version of the Bun image
2+
FROM oven/bun:1.1.30
23

4+
# Set the working directory
35
WORKDIR /app
46

5-
COPY package.json .
6-
COPY bun.lockb .
7+
# Copy the Prisma schema and other initial files for better caching
8+
COPY package.json ./
9+
COPY tsconfig.json ./
10+
COPY prisma ./prisma
711

8-
RUN bun install --production
12+
# Install dependencies (will only re-run if package.json or lock files change)
13+
RUN bun install
914

10-
COPY src src
11-
COPY tsconfig.json .
12-
# COPY public public
15+
# Generate Prisma client
16+
RUN bunx prisma generate
1317

14-
ENV NODE_ENV production
15-
CMD ["bun", "src/index.ts"]
18+
# Install OpenSSL (required by some libraries)
19+
RUN apt-get update && apt-get install -y openssl && rm -rf /var/lib/apt/lists/*
1620

17-
EXPOSE 4000
21+
# Copy the rest of the application files
22+
COPY src ./src
23+
24+
# Uncomment if you have public assets to include
25+
# COPY public ./public
26+
27+
# Expose the application port
28+
EXPOSE 4000
29+
30+
# Command to run the application
31+
CMD ["bun", "run", "src/index.ts"]

docker-compose.yml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
11
version: "3.8"
22

33
services:
4-
app:
5-
build:
6-
context: . # The current directory where your Dockerfile is located
7-
dockerfile: Dockerfile
8-
container_name: app
9-
restart: always
10-
env_file:
11-
- .env # Environment variables for your app (make sure it includes DB, Redis, MinIO configs)
12-
depends_on:
13-
- postgres
14-
- redis
15-
- minio
16-
ports:
17-
- "4000:4000" # Your app runs on port 4000
18-
volumes:
19-
- .:/app # Mount your current directory for live reloading (optional during dev)
20-
command: ["bun", "src/index.ts"] # Start your Bun app
21-
224
postgres:
235
image: postgres:latest
246
container_name: postgres

package.json

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"dev": "bun run --watch src/index.ts",
77
"db:push": "bunx prisma db push",
88
"db:studio": "bunx prisma studio",
9-
"postinstall": "bunx prisma generate",
109
"prepare": "husky",
1110
"commit": "git-cz",
1211
"lint": "bunx biome lint ./src",
@@ -15,26 +14,31 @@
1514
"format:fix": "bunx biome format --write ./src"
1615
},
1716
"dependencies": {
18-
"@elysiajs/swagger": "^1.1.1",
17+
"@elysiajs/cors": "^1.1.1",
18+
"@elysiajs/jwt": "^1.1.1",
19+
"@elysiajs/stream": "^1.1.0",
20+
"@elysiajs/swagger": "^1.1.5",
1921
"@prisma/client": "5.20.0",
2022
"elysia": "latest",
2123
"ioredis": "^5.4.1",
22-
"minio": "^8.0.1",
24+
"minio": "^8.0.2",
2325
"ws": "^8.18.0"
2426
},
2527
"devDependencies": {
26-
"@biomejs/biome": "^1.9.2",
28+
"@biomejs/biome": "^1.9.4",
2729
"@commitlint/cli": "^19.5.0",
2830
"@commitlint/config-conventional": "^19.5.0",
31+
"@types/mime-types": "^2.1.4",
2932
"bun-types": "latest",
3033
"cz-conventional-changelog": "^3.3.0",
31-
"cz-git": "^1.10.0",
32-
"eslint": "^9.11.1",
33-
"globals": "^15.9.0",
34+
"cz-git": "^1.10.1",
35+
"eslint": "^9.14.0",
36+
"globals": "^15.11.0",
3437
"husky": "^9.1.6",
3538
"lint-staged": "^15.2.10",
36-
"prisma": "^5.20.0",
37-
"typescript-eslint": "^8.7.0"
39+
"mime-types": "^2.1.35",
40+
"prisma": "^5.21.1",
41+
"typescript-eslint": "^8.12.2"
3842
},
3943
"config": {
4044
"commitizen": {
@@ -43,4 +47,4 @@
4347
},
4448
"module": "src/index.js",
4549
"type": "module"
46-
}
50+
}

pm2.config.cjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
name: "elysia-app",
3+
script: "src/index.ts",
4+
interpreter: "bun",
5+
env: {
6+
// biome-ignore lint/style/useNamingConvention: <explanation>
7+
NODE_ENV: "production",
8+
},
9+
};

prisma/schema.prisma

Lines changed: 69 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
generator client {
2-
provider = "prisma-client-js"
2+
provider = "prisma-client-js"
33
}
44

55
datasource db {
@@ -11,16 +11,30 @@ model User {
1111
id String @id @default(cuid())
1212
name String
1313
email String @unique
14-
projectRoles ProjectRole[] // Roles of users in various projects
15-
assignedTasks TaskAssignment[] // Tasks assigned to the user
14+
projectRoles ProjectRole[]
15+
assignedTasks TaskAssignment[]
1616
createdTasks Task[] @relation("CreatedTasks")
17-
uploadedFiles File[] @relation("UploadedFiles") // Files uploaded by the user
17+
uploadedFiles File[] @relation("UploadedFiles")
1818
comments Comment[]
19-
activities Activity[]
19+
activities Activity[]
20+
emojiTaskUsers EmojiTaskUser[] // Added relation field for EmojiTaskUser
21+
2022
2123
@@map("users")
2224
}
2325

26+
model EmojiTaskUser {
27+
id String @id @default(cuid())
28+
emoji String
29+
userId String
30+
taskId String
31+
32+
user User @relation(fields: [userId], references: [id])
33+
task Task @relation(fields: [taskId], references: [id])
34+
35+
@@map("emoji_task_users")
36+
}
37+
2438
model Project {
2539
id String @id @default(cuid())
2640
title String
@@ -30,9 +44,9 @@ model Project {
3044
usedBudget Float
3145
startDate DateTime
3246
endDate DateTime
33-
projectRoles ProjectRole[] // Roles of users in the project
34-
tasks Task[] @relation("ProjectTasks") // Tasks in the project
35-
files File[] @relation("ProjectFiles") // Files associated with the project
47+
projectRoles ProjectRole[]
48+
tasks Task[] @relation("ProjectTasks")
49+
files File[] @relation("ProjectFiles")
3650
3751
@@map("projects")
3852
}
@@ -51,27 +65,29 @@ model ProjectRole {
5165
}
5266

5367
model Task {
54-
id String @id @default(cuid())
68+
id String @id @default(cuid())
5569
title String
5670
description String
5771
status TaskStatus
58-
projectId String // Link to the Project
59-
project Project @relation("ProjectTasks", fields: [projectId], references: [id]) // Relation to the Project model
60-
tags Tag[] @relation("TaskTags") // Many-to-many relation with Tag
72+
projectId String
73+
project Project @relation("ProjectTasks", fields: [projectId], references: [id])
6174
subTasks Task[] @relation("SubTasks")
6275
parentTask Task? @relation("SubTasks", fields: [parentTaskId], references: [id])
63-
parentTaskId String?
64-
expectedBudget Float
65-
realBudget Float
66-
usedBudget Float
76+
parentTaskId String?
77+
statusBudgets BudgetStatus
78+
budget Float
79+
advance Float
80+
expense Float
6781
startDate DateTime?
6882
endDate DateTime?
69-
assignedUsers TaskAssignment[] // Many-to-many relation with users
83+
assignedUsers TaskAssignment[]
7084
createdById String?
71-
createdBy User? @relation("CreatedTasks", fields: [createdById], references: [id])
85+
createdBy User? @relation("CreatedTasks", fields: [createdById], references: [id])
7286
comments Comment[]
7387
activities Activity[]
74-
files File[] @relation("TaskFiles") // Files associated with the task
88+
files File[] @relation("TaskFiles")
89+
tags TaskTag[]
90+
emojiTaskUsers EmojiTaskUser[] // Added relation field for EmojiTaskUser
7591
7692
@@map("tasks")
7793
}
@@ -91,7 +107,7 @@ model TaskAssignment {
91107
model Tag {
92108
id String @id @default(cuid())
93109
name String @unique
94-
tasks Task[] @relation("TaskTags") // Many-to-many relation with Task
110+
tasks TaskTag[]
95111
96112
@@map("tags")
97113
}
@@ -101,7 +117,9 @@ model Comment {
101117
content String
102118
taskId String
103119
authorId String
104-
createdAt DateTime @default(now()) // Automatically set timestamp when comment is created
120+
createdAt DateTime @default(now())
121+
isDelete Boolean @default(false)
122+
editTime DateTime?
105123
106124
task Task @relation(fields: [taskId], references: [id])
107125
author User @relation(fields: [authorId], references: [id])
@@ -115,7 +133,7 @@ model Activity {
115133
detail String?
116134
taskId String?
117135
userId String
118-
createdAt DateTime @default(now()) // Automatically set timestamp when activity is logged
136+
createdAt DateTime @default(now())
119137
120138
task Task? @relation(fields: [taskId], references: [id])
121139
user User @relation(fields: [userId], references: [id])
@@ -126,12 +144,12 @@ model Activity {
126144
model File {
127145
id String @id @default(cuid())
128146
filePath String
129-
fileSize Float // File size in bytes
147+
fileSize Float
130148
taskId String?
149+
fileName String
131150
projectId String?
132151
uploadedBy String
133-
uploadedAt DateTime @default(now()) // Automatically set timestamp when file is uploaded
134-
createdAt DateTime @default(now()) // Automatically set timestamp when file is created
152+
createdAt DateTime @default(now())
135153
136154
task Task? @relation("TaskFiles", fields: [taskId], references: [id])
137155
project Project? @relation("ProjectFiles", fields: [projectId], references: [id])
@@ -140,24 +158,46 @@ model File {
140158
@@map("files")
141159
}
142160

161+
// Join table for many-to-many relationship between Task and Tag
162+
model TaskTag {
163+
id String @id @default(cuid())
164+
taskId String
165+
tagId String
166+
167+
task Task @relation(fields: [taskId], references: [id])
168+
tag Tag @relation(fields: [tagId], references: [id])
169+
170+
@@map("task_tags")
171+
}
172+
143173
enum Role {
144174
Admin
145175
Director
146176
ProjectOwner
147177
Member
148178
}
149179

150-
enum TaskStatus {
180+
enum TaskStatus {
151181
Unassigned
152182
Assigned
153183
UnderReview
154184
InRecheck
155185
Done
156186
}
157187

188+
enum BudgetStatus {
189+
Initial
190+
Added
191+
SubTasksAdded
192+
ParentTaskAdded
193+
}
194+
158195
enum ActivityAction {
159-
CREATE
196+
CREATED
160197
ASSIGNED
161-
DELETE
162-
UPLOAD
198+
DELETED
199+
UPLOADED
200+
UNASSIGNED
201+
ADDED
202+
REMOVED
163203
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Elysia } from "elysia";
2+
import { ActivityService } from "../services/activity-logs.service";
3+
import { type Context } from "../shared/interfaces.shared";
4+
import { WebSocket } from "../shared/utils/websocket.utils";
5+
6+
export const ActivityController = new Elysia({ prefix: "/activities" }).get(
7+
"/:id",
8+
async ({
9+
params: { id },
10+
db,
11+
redis,
12+
}: Context & { params: { id: string } }) => {
13+
const activityService = new ActivityService(db, redis);
14+
try {
15+
const activities = await activityService.getActivityById(id);
16+
if (!activities) {
17+
return Response.json("Activity not found", { status: 404 });
18+
}
19+
WebSocket.broadcast("activity", activities);
20+
return activities;
21+
} catch (_error) {
22+
const error = _error as Error;
23+
return Response.json(error.message, { status: 500 });
24+
}
25+
},
26+
);

0 commit comments

Comments
 (0)