Skip to content

Commit aa56ae0

Browse files
committed
add attendance detail and reponse score insertion
1 parent 748365b commit aa56ae0

33 files changed

+967
-42
lines changed

.env

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
55
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
66

7-
DATABASE_URL_SANDBOX="mysql://root:12345678@34.128.67.12:3306/asco"
8-
DATABASE_URL_LOCAL="mysql://admin:12345678@localhost:3306/asco"
7+
DATABASE_URL="mysql://admin:12345678@localhost:3306/asco"
98
PORT=7892
109
TESTING_PORT=8889
1110
HOST=127.0.0.1
1211
JWT_SECRET="^[Nk&S,!;5;N9sUFt#,GBlsWdKB,YPaMyTY]zv4SCkNd}aioJ#"
1312
ISSUER=api.jj
1413
GCP_PUB_SUB_PROJECTID="asco-app"
1514
GCP_PUB_SUB_TOPICID="publish-card-sync-meeting"
16-
GCP_PUB_SUB_SUBSCRIPTIONID="pull-card-meeting"
15+
GCP_PUB_SUB_SUBSCRIPTIONID="pull-card-meeting"
16+
KAFKA_HOST=localhost:9092
17+
DATABASE_HOST=localhost
18+
DATABASE_PORT=3306
19+
DATABASE_USER=admin
20+
DATABASE_PASSWORD=12345678
21+
DATABASE_NAME=asco

.env.dev

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Environment variables declared in this file are automatically made available to Prisma.
2+
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
3+
4+
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
5+
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
6+
7+
DATABASE_URL="mysql://admin:12345678@localhost:3306/asco"
8+
PORT=7892
9+
TESTING_PORT=8889
10+
HOST=127.0.0.1
11+
JWT_SECRET="^[Nk&S,!;5;N9sUFt#,GBlsWdKB,YPaMyTY]zv4SCkNd}aioJ#"
12+
ISSUER=api.jj
13+
GCP_PUB_SUB_PROJECTID="asco-app"
14+
GCP_PUB_SUB_TOPICID="publish-card-sync-meeting"
15+
GCP_PUB_SUB_SUBSCRIPTIONID="pull-card-meeting"
16+
KAFKA_HOST=localhost:9092
17+
DATABASE_HOST=localhost
18+
DATABASE_PORT=3306
19+
DATABASE_USER=admin
20+
DATABASE_PASSWORD=12345678
21+
DATABASE_NAME=asco
22+
NODE_ENV=development

.env.sandbox

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Environment variables declared in this file are automatically made available to Prisma.
2+
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
3+
4+
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
5+
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
6+
7+
DATABASE_URL="mysql://root:12345678@34.128.67.12:3306/asco"
8+
PORT=7892
9+
TESTING_PORT=8889
10+
HOST=127.0.0.1
11+
JWT_SECRET="^[Nk&S,!;5;N9sUFt#,GBlsWdKB,YPaMyTY]zv4SCkNd}aioJ#"
12+
ISSUER=api.jj
13+
GCP_PUB_SUB_PROJECTID="asco-app"
14+
GCP_PUB_SUB_TOPICID="publish-card-sync-meeting"
15+
GCP_PUB_SUB_SUBSCRIPTIONID="pull-card-meeting"
16+
NODE_ENV=sandbox

package-lock.json

+40-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+11-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
"main": "index.js",
66
"scripts": {
77
"migrate": "prisma migrate dev --name ",
8-
"start::dev": "nodemon ./src/index.ts",
8+
"start::dev": "cp .env.dev .env && prisma generate && nodemon ./src/index.ts",
9+
"start::sandbox": "cp .env.sandbox .env && prisma generate && nodemon ./src/index.ts",
910
"build": "rimraf ./dist && tsc",
1011
"start": "node ./dist/index.js ",
11-
"run-script": "ts-node",
12-
"test": "echo \"Error: no test specified\" && exit 1"
12+
"start-worker": "ts-node ./src/worker/group_card_sync.worker.ts",
13+
"test": "echo \"Error: no test specified\" && exit 1",
14+
"studio::dev": "cp .env.dev .env && prisma generate && prisma studio",
15+
"studio::sandbox": "cp .env.sandbox .env && prisma generate && prisma studio",
16+
"dbpush::dev": "cp .env.dev .env && prisma db push",
17+
"dbpush::sandbox": "cp .env.sandbox .env && prisma db push"
1318
},
1419
"devDependencies": {
1520
"@types/bcryptjs": "^2.4.6",
@@ -18,6 +23,7 @@
1823
"@types/express": "^4.17.17",
1924
"@types/jsonwebtoken": "^9.0.6",
2025
"@types/multer": "^1.4.11",
26+
"@types/mysql": "^2.15.26",
2127
"@types/node": "^18.15.13",
2228
"@types/uuid": "^9.0.1",
2329
"nodemon": "^3.1.0",
@@ -36,10 +42,11 @@
3642
"express": "^4.18.2",
3743
"joi": "^17.13.3",
3844
"jsonwebtoken": "^9.0.2",
45+
"kafkajs": "^2.2.4",
3946
"multer": "^1.4.5-lts.1",
4047
"mysql": "^2.18.1",
4148
"rimraf": "^5.0.7",
42-
"uuid": "^9.0.0"
49+
"uuid": "^9.0.1"
4350
},
4451
"keywords": [],
4552
"author": "",

prisma/schema.prisma

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ generator client {
77

88
datasource db {
99
provider = "mysql"
10-
url = env("DATABASE_URL_SANDBOX")
10+
url = env("DATABASE_URL")
1111
}
1212

1313
model User {
@@ -128,6 +128,7 @@ model Attendance {
128128
practicum Practicum @relation(fields: [practicumId], references: [id], onDelete: Cascade, onUpdate: Cascade)
129129
practicumId String
130130
131+
@@unique([meetingId, profileId])
131132
@@map("attendances")
132133
}
133134

src/api/attendance/handler/AttendanceHandler.ts

+14
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,22 @@ import { NextFunction, Request, Response } from "express";
33
export abstract class AttendanceHandler {
44
constructor() {
55
this.deleteAttendance = this.deleteAttendance.bind(this);
6+
this.putAttendance = this.putAttendance.bind(this);
7+
this.getAttendance = this.getAttendance.bind(this);
68
}
79

10+
abstract getAttendance(
11+
req: Request,
12+
res: Response,
13+
next: NextFunction
14+
): Promise<any>;
15+
16+
abstract putAttendance(
17+
req: Request,
18+
res: Response,
19+
next: NextFunction
20+
): Promise<any>;
21+
822
abstract deleteAttendance(
923
req: Request,
1024
res: Response,

src/api/attendance/handler/AttendanceHandlerImpl.ts

+52-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import {
55
getTokenPayload,
66
} from "../../../utils";
77
import { SchemaValidator } from "../../../utils/validator/SchemaValidator";
8-
import { ParamsDictionary } from "express-serve-static-core";
9-
import { ParsedQs } from "qs";
108
import { AttendanceService } from "../../../services/attendance/AttendanceService";
119
import { AttendanceHandler } from "./AttendanceHandler";
10+
import { IPutAttendancePayload } from "../../../utils/interfaces/request/IPutAttendancePayload";
11+
import { MeetingAttendancePutPayloadSchema } from "../../../utils/validator/attendance/Joi/MeetingAttendancePutPayloadSchema";
12+
import { AttendanceDTO } from "../../../utils/dto/attendances/IAttendanceDTO";
1213

1314
export class AttendanceHandlerImpl extends AttendanceHandler {
1415
private attendanceService: AttendanceService;
@@ -25,6 +26,55 @@ export class AttendanceHandlerImpl extends AttendanceHandler {
2526
this.schemaValidator = schemaValidator;
2627
}
2728

29+
async getAttendance(
30+
req: Request,
31+
res: Response,
32+
next: NextFunction
33+
): Promise<any> {
34+
const { id } = req.params;
35+
try {
36+
const attendance = await this.attendanceService.getAttendanceById(id);
37+
38+
return res
39+
.status(200)
40+
.json(
41+
createResponse(RESPONSE_MESSAGE.SUCCESS, AttendanceDTO(attendance))
42+
);
43+
} catch (error) {
44+
return next(error);
45+
}
46+
}
47+
48+
async putAttendance(
49+
req: Request,
50+
res: Response,
51+
next: NextFunction
52+
): Promise<any> {
53+
const { id } = req.params;
54+
const payload: IPutAttendancePayload = req.body;
55+
const { profileId } = getTokenPayload(res);
56+
57+
try {
58+
this.schemaValidator.validate({
59+
schema: MeetingAttendancePutPayloadSchema,
60+
payload,
61+
});
62+
63+
await this.attendanceService.updateAttendanceById(id, payload, profileId);
64+
65+
return res
66+
.status(200)
67+
.json(
68+
createResponse(
69+
RESPONSE_MESSAGE.SUCCESS,
70+
"successfully update attendance"
71+
)
72+
);
73+
} catch (error) {
74+
return next(error);
75+
}
76+
}
77+
2878
async deleteAttendance(
2979
req: Request,
3080
res: Response,

src/api/attendance/router/AttendanceRouterImpl.ts

+15
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ export class AttendanceRouter extends BaseRouter {
2727
USER_ROLE.ASSISTANT,
2828
]),
2929
this.handler.deleteAttendance
30+
)
31+
.put(
32+
this.authorizationMiddlware.authorize([
33+
USER_ROLE.ADMIN,
34+
USER_ROLE.ASSISTANT,
35+
]),
36+
this.handler.putAttendance
37+
)
38+
.get(
39+
this.authorizationMiddlware.authorize([
40+
USER_ROLE.ADMIN,
41+
USER_ROLE.ASSISTANT,
42+
USER_ROLE.STUDENT,
43+
]),
44+
this.handler.getAttendance
3045
);
3146

3247
return this.router;

src/api/meeting/handler/MeetingHandler.ts

+7
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ export abstract class MeetingHandler {
88
this.postMeetingAttendance = this.postMeetingAttendance.bind(this);
99
this.getMeetingAttendances = this.getMeetingAttendances.bind(this);
1010
this.postMeetingAttendances = this.postMeetingAttendances.bind(this);
11+
this.postMeetingResponseScore = this.postMeetingResponseScore.bind(this);
1112
}
1213

14+
abstract postMeetingResponseScore(
15+
req: Request,
16+
res: Response,
17+
next: NextFunction
18+
): Promise<any>;
19+
1320
abstract postMeetingAttendances(
1421
req: Request,
1522
res: Response,

0 commit comments

Comments
 (0)