Skip to content

Commit ea33ec0

Browse files
authored
Merge pull request #5 from BIC-DevSphere/feat/controllers
feat: update Dockerfile and refactor routine processing logic to stre…
2 parents 21f7e31 + 1329593 commit ea33ec0

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ RUN npm install
1515
# Step 5: Copy the rest of the application files to the container
1616
COPY . .
1717

18-
# Step 6: Expose the port on which your app runs
18+
# Step 6: Generate Prisma client before starting the app
19+
RUN npx prisma generate
20+
21+
# Step 7: Expose the port on which your app runs
1922
EXPOSE 3000
2023

21-
# Step 7: Define the command to run the app
24+
# Step 8: Define the command to run the app
2225
CMD ["npx", "nodemon", "src/index.ts"]

src/controllers/routineController.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ const getRoutineData = asyncHandler(async (req: Request, res: Response) => {
2525
include: {
2626
timeTables: {
2727
include: {
28-
subject: true,
29-
teacher: true
28+
subject: true
3029
}
3130
}
3231
}

src/lib/amqpListener.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ interface RoutineData {
5656

5757
async function processRoutineData(routineData: RoutineData) {
5858
try {
59+
// Create or update the routine
5960
const routine = await prisma.routine.upsert({
6061
where: {
6162
id: routineData.timeTables.length > 0 ? routineData.timeTables[0].newRoutineId : 0,
@@ -72,23 +73,27 @@ async function processRoutineData(routineData: RoutineData) {
7273
});
7374

7475
for (const timeTableData of routineData.timeTables) {
76+
// Find or create the teacher based on email
77+
const teacherId = Math.floor(Math.random() * 100000); // Generate a random ID
7578
const teacher = await prisma.teacher.upsert({
76-
where: { id: parseInt(timeTableData.newRoutineId.toString() + timeTableData.lecturerEmail.length, 10) % 1000000000 },
79+
where: { id: teacherId }, // Use the generated ID
7780
update: {
7881
email: timeTableData.lecturerEmail,
7982
name: timeTableData.lecturerEmail.split('@')[0],
8083
},
8184
create: {
82-
id: parseInt(timeTableData.newRoutineId.toString() + timeTableData.lecturerEmail.length, 10) % 1000000000,
85+
id: teacherId,
8386
name: timeTableData.lecturerEmail.split('@')[0],
8487
email: timeTableData.lecturerEmail,
8588
},
8689
});
8790

91+
// Extract subject name and code from the subject string
8892
const subjectParts = timeTableData.subject.split(' ');
8993
const subjectCode = subjectParts[0];
9094
const subjectName = subjectParts.slice(1).join(' ');
9195

96+
// Find or create the subject
9297
const subject = await prisma.subject.upsert({
9398
where: {
9499
id: parseInt(subjectCode.replace(/\D/g, ''), 10) || Math.floor(Math.random() * 100000)
@@ -103,6 +108,7 @@ async function processRoutineData(routineData: RoutineData) {
103108
},
104109
});
105110

111+
// Create or update the time table entry
106112
await prisma.timeTable.upsert({
107113
where: {
108114
id: parseInt(timeTableData.newRoutineId.toString() + timeTableData.day, 10) % 1000000000

0 commit comments

Comments
 (0)