Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2023-029
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2023-029
2023-029
Commits
163c73e9
Commit
163c73e9
authored
Aug 31, 2023
by
janithgamage1.ed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: update
Desc : update project
parent
9d40242e
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
213 additions
and
50 deletions
+213
-50
Project/Backend/Server_Node/controllers/curriculum.controller.js
.../Backend/Server_Node/controllers/curriculum.controller.js
+22
-0
Project/Backend/Server_Node/controllers/tutorial.controller.js
...ct/Backend/Server_Node/controllers/tutorial.controller.js
+12
-2
Project/Backend/Server_Node/controllers/userProgress.controller.js
...ackend/Server_Node/controllers/userProgress.controller.js
+85
-22
Project/Backend/Server_Node/models/curriculum.model.js
Project/Backend/Server_Node/models/curriculum.model.js
+7
-3
Project/Backend/Server_Node/models/tutorial.model.js
Project/Backend/Server_Node/models/tutorial.model.js
+8
-0
Project/Backend/Server_Node/models/userProgress.model.js
Project/Backend/Server_Node/models/userProgress.model.js
+69
-20
Project/Backend/Server_Node/routes/userProgress.routes.js
Project/Backend/Server_Node/routes/userProgress.routes.js
+4
-3
Project/Frontend/SignConnectPlus/src/sections/learning-management/learning-curriculums/CurriculumCard.tsx
...arning-management/learning-curriculums/CurriculumCard.tsx
+6
-0
No files found.
Project/Backend/Server_Node/controllers/curriculum.controller.js
View file @
163c73e9
...
...
@@ -26,17 +26,39 @@ export const createCurriculum = async (req, res) => {
const
curriculumData
=
req
.
body
;
try
{
const
newCurriculum
=
new
Curriculum
(
curriculumData
);
// Calculate total tutorial mark
let
totalTutorialMark
=
0
;
for
(
const
tutorialId
of
curriculumData
.
tutorials
)
{
const
tutorial
=
await
Tutorial
.
findById
(
tutorialId
);
totalTutorialMark
+=
tutorial
.
tutorialMark
;
}
newCurriculum
.
curriculumMark
=
totalTutorialMark
;
await
newCurriculum
.
save
();
res
.
status
(
201
).
json
(
newCurriculum
);
}
catch
(
error
)
{
res
.
status
(
400
).
json
({
message
:
error
.
message
});
}
}
export
const
updateCurriculum
=
async
(
req
,
res
)
=>
{
const
{
id
}
=
req
.
params
;
const
updatedCurriculum
=
req
.
body
;
try
{
const
curriculum
=
await
Curriculum
.
findById
(
id
);
// Calculate total tutorial mark
let
totalTutorialMark
=
0
;
for
(
const
tutorialId
of
updatedCurriculum
.
tutorials
)
{
const
tutorial
=
await
Tutorial
.
findById
(
tutorialId
);
totalTutorialMark
+=
tutorial
.
tutorialMark
;
}
updatedCurriculum
.
curriculumMark
=
totalTutorialMark
;
const
result
=
await
Curriculum
.
findByIdAndUpdate
(
id
,
updatedCurriculum
,
{
new
:
true
});
res
.
status
(
200
).
json
(
result
);
}
catch
(
error
)
{
...
...
Project/Backend/Server_Node/controllers/tutorial.controller.js
View file @
163c73e9
...
...
@@ -21,6 +21,11 @@ export const getTutorialById = async (req, res) => {
export
const
createTutorial
=
async
(
req
,
res
)
=>
{
const
tutorialData
=
req
.
body
;
// Calculate total tutorial marks based on task item marks
const
totalTaskMarks
=
tutorialData
.
taskItems
.
reduce
((
total
,
task
)
=>
total
+
(
task
.
taskItemMark
||
0
),
0
);
tutorialData
.
tutorialMarks
=
totalTaskMarks
;
try
{
const
newTutorial
=
new
Tutorial
(
tutorialData
);
await
newTutorial
.
save
();
...
...
@@ -32,9 +37,14 @@ export const createTutorial = async (req, res) => {
export
const
updateTutorial
=
async
(
req
,
res
)
=>
{
const
{
id
}
=
req
.
params
;
const
updatedTutorial
=
req
.
body
;
const
updatedTutorialData
=
req
.
body
;
// Calculate total tutorial marks based on updated task item marks
const
totalTaskMarks
=
updatedTutorialData
.
taskItems
.
reduce
((
total
,
task
)
=>
total
+
(
task
.
taskItemMark
||
0
),
0
);
updatedTutorialData
.
tutorialMarks
=
totalTaskMarks
;
try
{
const
result
=
await
Tutorial
.
findByIdAndUpdate
(
id
,
updatedTutorial
,
{
new
:
true
});
const
result
=
await
Tutorial
.
findByIdAndUpdate
(
id
,
updatedTutorial
Data
,
{
new
:
true
});
res
.
status
(
200
).
json
(
result
);
}
catch
(
error
)
{
res
.
status
(
404
).
json
({
message
:
'
Tutorial not found
'
});
...
...
Project/Backend/Server_Node/controllers/userProgress.controller.js
View file @
163c73e9
import
UserProgress
from
'
../models/userProgress.model.js
'
;
import
UserProgress
from
"
../models/userProgress.model.js
"
;
export
const
getUser
Progres
s
=
async
(
req
,
res
)
=>
{
export
const
getUser
SubscribedCurriculum
s
=
async
(
req
,
res
)
=>
{
const
userId
=
req
.
params
.
userId
;
try
{
const
userProgress
=
await
UserProgress
.
findOne
({
userId
}).
populate
(
'
curriculumId tutorialProgress.tutorialId
'
);
const
userProgress
=
await
UserProgress
.
find
({
userId
})
.
populate
(
'
curriculumProgress.curriculumId
'
)
.
populate
(
'
curriculumProgress.tutorialProgress.tutorialId
'
)
.
populate
(
'
curriculumProgress.tutorialProgress.taskProgress.taskId
'
);
res
.
status
(
200
).
json
(
userProgress
);
}
catch
(
error
)
{
res
.
status
(
500
).
json
({
message
:
error
.
message
});
res
.
status
(
500
).
json
({
message
:
"
Error fetching user progress
"
,
error
});
}
}
}
;
export
const
updateUserProgress
=
async
(
req
,
res
)
=>
{
const
userId
=
req
.
params
.
userId
;
const
{
curriculumId
,
tutorialId
,
completed
,
marks
}
=
req
.
body
;
export
const
subscribeToCurriculum
=
async
(
req
,
res
)
=>
{
const
{
userId
,
curriculumId
}
=
req
.
body
;
try
{
let
userProgress
=
await
UserProgress
.
findOne
({
userId
});
if
(
!
userProgress
)
{
userProgress
=
new
UserProgress
({
userId
});
userProgress
=
new
UserProgress
({
userId
,
curriculumProgress
:
[],
totalMarks
:
0
});
}
const
curriculumProgress
=
userProgress
.
curriculumId
.
find
(
prog
=>
prog
.
curriculumId
.
equals
(
curriculumId
));
const
curriculumProgressIndex
=
userProgress
.
curriculumProgress
.
findIndex
(
progress
=>
progress
.
curriculumId
.
toString
()
===
curriculumId
);
if
(
!
curriculumProgress
)
{
userProgress
.
curriculumId
.
push
({
curriculumId
});
if
(
curriculumProgressIndex
===
-
1
)
{
userProgress
.
curriculumProgress
.
push
({
curriculumId
,
tutorialProgress
:
[]
});
}
const
tutorialProgress
=
curriculumProgress
.
tutorialProgress
.
find
(
prog
=>
prog
.
tutorialId
.
equals
(
tutorialId
));
if
(
!
tutorialProgress
)
{
curriculumProgress
.
tutorialProgress
.
push
({
tutorialId
,
completed
});
}
else
{
tutorialProgress
.
completed
=
completed
;
await
userProgress
.
save
();
res
.
status
(
201
).
json
({
message
:
"
User subscribed to curriculum
"
,
userProgress
});
}
catch
(
error
)
{
res
.
status
(
500
).
json
({
message
:
"
Error subscribing to curriculum
"
,
error
});
}
};
export
const
updateUserProgress
=
async
(
req
,
res
)
=>
{
const
{
userId
,
curriculumId
,
tutorialId
,
taskId
,
taskMarks
}
=
req
.
body
;
try
{
const
userProgress
=
await
UserProgress
.
findOne
({
userId
});
if
(
!
userProgress
)
{
return
res
.
status
(
404
).
json
({
message
:
"
User progress not found
"
});
}
userProgress
.
marks
=
marks
;
const
curriculumProgressIndex
=
userProgress
.
curriculumProgress
.
findIndex
(
progress
=>
progress
.
curriculumId
.
toString
()
===
curriculumId
);
if
(
curriculumProgressIndex
!==
-
1
)
{
const
curriculumProgress
=
userProgress
.
curriculumProgress
[
curriculumProgressIndex
];
const
tutorialProgressIndex
=
curriculumProgress
.
tutorialProgress
.
findIndex
(
tutorialProgress
=>
tutorialProgress
.
tutorialId
.
toString
()
===
tutorialId
);
if
(
tutorialProgressIndex
!==
-
1
)
{
const
tutorialProgress
=
curriculumProgress
.
tutorialProgress
[
tutorialProgressIndex
];
const
taskProgressIndex
=
tutorialProgress
.
taskProgress
.
findIndex
(
taskProgress
=>
taskProgress
.
taskId
.
toString
()
===
taskId
);
if
(
taskProgressIndex
!==
-
1
)
{
const
taskProgress
=
tutorialProgress
.
taskProgress
[
taskProgressIndex
];
taskProgress
.
completed
=
true
;
taskProgress
.
marks
=
taskMarks
;
// Update tutorial completion status
const
tutorialTotalMarks
=
tutorialProgress
.
tutorialId
.
totalTutorialMarks
;
// You'll need to populate this field
if
(
tutorialTotalMarks
>
0
)
{
tutorialProgress
.
completed
=
(
tutorialProgress
.
marks
/
tutorialTotalMarks
)
>
0.85
;
}
// Update curriculum completion status
const
curriculumTotalMarks
=
curriculumProgress
.
curriculumId
.
totalCurriculumMarks
;
// You'll need to populate this field
if
(
curriculumTotalMarks
>
0
)
{
curriculumProgress
.
completed
=
(
curriculumProgress
.
marks
/
curriculumTotalMarks
)
>
0.85
;
}
// Update user total marks
userProgress
.
totalMarks
=
userProgress
.
curriculumProgress
.
reduce
(
(
total
,
curriculumProgress
)
=>
total
+
curriculumProgress
.
marks
,
0
);
}
}
}
await
userProgress
.
save
();
res
.
status
(
200
).
json
(
userProgress
);
res
.
status
(
200
).
json
(
{
message
:
"
User progress updated
"
,
userProgress
}
);
}
catch
(
error
)
{
res
.
status
(
500
).
json
({
message
:
error
.
message
});
res
.
status
(
500
).
json
({
message
:
"
Error updating user progress
"
,
error
});
}
}
}
;
\ No newline at end of file
Project/Backend/Server_Node/models/curriculum.model.js
View file @
163c73e9
...
...
@@ -11,9 +11,9 @@ const commonFields = {
type
:
Date
,
default
:
new
Date
(),
},
};
const
curriculumSchema
=
new
mongoose
.
Schema
({
};
const
curriculumSchema
=
new
mongoose
.
Schema
({
curriculumCode
:
{
type
:
String
,
unique
:
true
,
// Ensures unique values for curriculumCode
...
...
@@ -22,6 +22,10 @@ const curriculumSchema = new mongoose.Schema({
curriculumTitle
:
String
,
curriculumDescription
:
String
,
curriculumImage
:
String
,
curriculumMark
:
{
type
:
Number
,
default
:
0
},
tutorials
:
[{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
ref
:
"
Tutorial
"
,
...
...
Project/Backend/Server_Node/models/tutorial.model.js
View file @
163c73e9
...
...
@@ -19,6 +19,10 @@ const taskItemSchema = new mongoose.Schema({
howToDo
:
String
,
referenceImage
:
String
,
referenceVideo
:
String
,
taskItemMark
:
{
type
:
Number
,
default
:
0
}
// Additional fields for task items
});
...
...
@@ -30,6 +34,10 @@ const tutorialSchema = new mongoose.Schema({
tutorialTitle
:
String
,
tutorialDescription
:
String
,
tutorialImage
:
String
,
tutorialMarks
:
{
type
:
Number
,
default
:
0
},
taskItems
:
[
taskItemSchema
],
// Embed task items as subdocuments
// Additional fields for tutorial details
status
:
{
...
...
Project/Backend/Server_Node/models/userProgress.model.js
View file @
163c73e9
import
mongoose
from
"
mongoose
"
;
const
userProgressSchema
=
new
mongoose
.
Schema
({
userId
:
{
const
commonFields
=
{
createdBy
:
String
,
updatedBy
:
String
,
createdAt
:
{
type
:
Date
,
default
:
new
Date
(),
},
updatedAt
:
{
type
:
Date
,
default
:
new
Date
(),
},
};
const
taskProgressSchema
=
new
mongoose
.
Schema
({
taskId
:
{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
required
:
true
,
ref
:
'
User
'
// Reference to the User model
ref
:
'
Task
'
},
completed
:
{
type
:
Boolean
,
default
:
false
},
taskMarkUser
:
{
type
:
Number
,
default
:
0
}
});
const
tutorialProgressSchema
=
new
mongoose
.
Schema
({
tutorialId
:
{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
ref
:
'
Tutorial
'
},
taskProgress
:
[
taskProgressSchema
],
completed
:
{
type
:
Boolean
,
default
:
false
},
tutorialMarkUser
:
{
type
:
Number
,
default
:
0
}
});
const
curriculumProgressSchema
=
new
mongoose
.
Schema
({
curriculumId
:
{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
required
:
true
,
ref
:
'
Curriculum
'
// Reference to the Curriculum model
},
tutorialProgress
:
[
{
tutorialId
:
{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
ref
:
'
Tutorial
'
// Reference to the Tutorial model
},
completed
:
{
type
:
Boolean
,
default
:
false
}
}
],
marks
:
{
ref
:
'
Curriculum
'
},
tutorialProgress
:
[
tutorialProgressSchema
],
completed
:
{
type
:
Boolean
,
default
:
false
},
curriculumMarkUser
:
{
type
:
Number
,
default
:
0
}
});
const
userProgressSchema
=
new
mongoose
.
Schema
({
userId
:
{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
required
:
true
,
ref
:
'
User
'
},
curriculumProgress
:
[
curriculumProgressSchema
],
totalCurriculumsMarks
:
{
type
:
Number
,
default
:
0
},
totalCurriculumsMarksUser
:
{
type
:
Number
,
default
:
0
},
...
commonFields
});
const
UserProgress
=
mongoose
.
model
(
"
UserProgress
"
,
userProgressSchema
);
export
default
UserProgress
;
Project/Backend/Server_Node/routes/userProgress.routes.js
View file @
163c73e9
import
express
from
"
express
"
;
import
{
getUser
Progress
,
updateUserProgress
}
from
"
../controllers/userProgress.controller.js
"
;
import
{
getUser
SubscribedCurriculums
,
subscribeToCurriculum
,
updateUserProgress
}
from
"
../controllers/userProgress.controller.js
"
;
const
router
=
express
.
Router
();
router
.
get
(
'
/:userId
'
,
getUserProgress
);
router
.
post
(
'
/:userId
'
,
updateUserProgress
);
router
.
get
(
'
/:userId
'
,
getUserSubscribedCurriculums
);
router
.
post
(
'
/:userId
'
,
subscribeToCurriculum
);
router
.
put
(
'
/:userId
'
,
updateUserProgress
);
export
default
router
;
Project/Frontend/SignConnectPlus/src/sections/learning-management/learning-curriculums/CurriculumCard.tsx
View file @
163c73e9
...
...
@@ -231,11 +231,17 @@ const CurriculumCard = ({ curriculum }: { curriculum: curriculumCardProps }) =>
<
Typography
variant=
"caption"
color=
"secondary"
>
Updated in
{
curriculum
.
createdAt
?.
toLocaleTimeString
()
}
</
Typography
>
<
Button
variant=
"outlined"
size=
"small"
onClick=
{
()
=>
{
handleClickOpen
()
}
}
>
Preview
</
Button
>
<
Button
variant=
"outlined"
size=
"small"
color=
'success'
onClick=
{
()
=>
{
// handleClickOpen()
}
}
>
Subscribe
</
Button
>
</
Stack
>
</
MainCard
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment