Skip to content
This repository was archived by the owner on Jun 12, 2025. It is now read-only.

Commit 6fd480f

Browse files
authored
Merge pull request #7 from EVOGD-Project:dev
Dev
2 parents 4fa85cf + 03211bd commit 6fd480f

9 files changed

Lines changed: 526 additions & 9 deletions

File tree

bun.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@elysiajs/swagger": "^1.3.0",
2222
"elysia": "^1.3.3",
2323
"mongoose": "^8.15.1",
24+
"nanoid": "^5.1.5",
2425
"prom-client": "^15.1.3",
2526
"tslib": "^2.8.1",
2627
"uuid": "^11.1.0"

src/classes/MainServer.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import swagger from '@elysiajs/swagger';
44
import Elysia from 'elysia';
55
import { authLoginRoute } from '../routes/auth/login';
66
import { authRegisterRoute } from '../routes/auth/register';
7+
import { classroomRoute } from '../routes/classroom';
78
import { userRoute } from '../routes/user';
9+
import { classroomActivitiesRoute } from '../routes/classroom/activities';
810

911
export class MainServer {
1012
app: Elysia;
@@ -16,7 +18,14 @@ export class MainServer {
1618
}
1719

1820
public setup() {
19-
this.app.use(cors()).use(staticPlugin()).use(authLoginRoute).use(authRegisterRoute).use(userRoute);
21+
this.app
22+
.use(cors())
23+
.use(staticPlugin())
24+
.use(authLoginRoute)
25+
.use(authRegisterRoute)
26+
.use(userRoute)
27+
.use(classroomRoute)
28+
.use(classroomActivitiesRoute);
2029

2130
if (process.env['ENABLE_SWAGGER'] === 'true') {
2231
console.log('Swagger enabled.');

src/models/ActivityModel.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { Schema, model } from 'mongoose';
2+
import { SchemaUtil } from '../classes/SchemaUtil';
3+
4+
export interface IActivity {
5+
id: string;
6+
title: string;
7+
description: string;
8+
classroomId: string;
9+
owner: string;
10+
dueDate?: string;
11+
createdAt: string;
12+
type: 'assignment' | 'material';
13+
content: {
14+
instructions?: string;
15+
resources?: Array<{
16+
type: 'link' | 'file';
17+
name: string;
18+
url: string;
19+
}>;
20+
};
21+
}
22+
23+
const resourceSchema = new Schema(
24+
{
25+
type: {
26+
type: String,
27+
enum: ['link', 'file'],
28+
required: true
29+
},
30+
name: {
31+
type: String,
32+
required: true
33+
},
34+
url: {
35+
type: String,
36+
required: true
37+
}
38+
},
39+
{ _id: false }
40+
);
41+
42+
const activitySchema = new Schema<IActivity>(
43+
{
44+
title: {
45+
type: String,
46+
required: true
47+
},
48+
description: {
49+
type: String,
50+
required: true
51+
},
52+
classroomId: {
53+
type: String,
54+
required: true
55+
},
56+
owner: {
57+
type: String,
58+
required: true
59+
},
60+
dueDate: {
61+
type: String,
62+
required: false
63+
},
64+
type: {
65+
type: String,
66+
enum: ['assignment', 'material'],
67+
required: true
68+
},
69+
content: {
70+
instructions: {
71+
type: String,
72+
required: false
73+
},
74+
resources: {
75+
type: [resourceSchema],
76+
required: false,
77+
default: []
78+
}
79+
}
80+
},
81+
{
82+
timestamps: true
83+
}
84+
);
85+
86+
activitySchema.set('toJSON', {
87+
transform: SchemaUtil.transformSchemaToJSON
88+
});
89+
90+
export const ActivityModel = model<IActivity>('Activity', activitySchema);

src/models/ClassroomModel.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Schema, model } from 'mongoose';
2+
import { SchemaUtil } from '../classes/SchemaUtil';
3+
4+
export interface IClassroom {
5+
id: string;
6+
name: string;
7+
description: string;
8+
thumbnailId: number;
9+
code: string;
10+
owner: string;
11+
}
12+
13+
const schema = new Schema<IClassroom>(
14+
{
15+
name: {
16+
type: String,
17+
required: true
18+
},
19+
description: {
20+
type: String,
21+
required: true
22+
},
23+
thumbnailId: {
24+
type: Number,
25+
required: true
26+
},
27+
code: {
28+
type: String,
29+
required: true,
30+
unique: true,
31+
index: true
32+
},
33+
owner: {
34+
type: String,
35+
required: true,
36+
index: true
37+
}
38+
},
39+
{
40+
timestamps: true
41+
}
42+
);
43+
44+
schema.set('toJSON', {
45+
transform: SchemaUtil.transformSchemaToJSON
46+
});
47+
48+
export const ClassroomModel = model<IClassroom>('Classroom', schema);

src/models/UserModel.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,17 @@ const schema = new Schema(
1818
trim: true
1919
},
2020
password: { type: String, required: true },
21-
avatar: { type: String, required: false, trim: true }
21+
avatar: { type: String, required: false, trim: true },
22+
classroomIds: {
23+
type: [String],
24+
required: false,
25+
default: []
26+
}
2227
},
2328
{
2429
statics: {
2530
async verifyPassword(password: string, hash: string) {
2631
return Bun.password.verify(password, hash);
27-
},
28-
async findByToken(id: string, auth: string) {
29-
const targetUser = await this.findById(id);
30-
31-
if (!targetUser?.token || targetUser.token !== auth) return null;
32-
33-
return targetUser;
3432
}
3533
}
3634
}

0 commit comments

Comments
 (0)