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
7fb6e5cb
Commit
7fb6e5cb
authored
Aug 24, 2023
by
janithGamage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: update
Desc : user progress backend config
parent
f15726d6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
125 additions
and
0 deletions
+125
-0
Project/Backend/Server_Node/controllers/userProgress.controller.js
...ackend/Server_Node/controllers/userProgress.controller.js
+46
-0
Project/Backend/Server_Node/models/curriculum.model.js
Project/Backend/Server_Node/models/curriculum.model.js
+14
-0
Project/Backend/Server_Node/models/tutorial.model.js
Project/Backend/Server_Node/models/tutorial.model.js
+14
-0
Project/Backend/Server_Node/models/userProgress.model.js
Project/Backend/Server_Node/models/userProgress.model.js
+34
-0
Project/Backend/Server_Node/routes/userProgress.routes.js
Project/Backend/Server_Node/routes/userProgress.routes.js
+9
-0
Project/Backend/Server_Node/server.js
Project/Backend/Server_Node/server.js
+8
-0
No files found.
Project/Backend/Server_Node/controllers/userProgress.controller.js
0 → 100644
View file @
7fb6e5cb
import
UserProgress
from
'
../models/userProgress.model.js
'
;
export
const
getUserProgress
=
async
(
req
,
res
)
=>
{
const
userId
=
req
.
params
.
userId
;
try
{
const
userProgress
=
await
UserProgress
.
findOne
({
userId
}).
populate
(
'
curriculumId tutorialProgress.tutorialId
'
);
res
.
status
(
200
).
json
(
userProgress
);
}
catch
(
error
)
{
res
.
status
(
500
).
json
({
message
:
error
.
message
});
}
}
export
const
updateUserProgress
=
async
(
req
,
res
)
=>
{
const
userId
=
req
.
params
.
userId
;
const
{
curriculumId
,
tutorialId
,
completed
,
marks
}
=
req
.
body
;
try
{
let
userProgress
=
await
UserProgress
.
findOne
({
userId
});
if
(
!
userProgress
)
{
userProgress
=
new
UserProgress
({
userId
});
}
const
curriculumProgress
=
userProgress
.
curriculumId
.
find
(
prog
=>
prog
.
curriculumId
.
equals
(
curriculumId
));
if
(
!
curriculumProgress
)
{
userProgress
.
curriculumId
.
push
({
curriculumId
});
}
const
tutorialProgress
=
curriculumProgress
.
tutorialProgress
.
find
(
prog
=>
prog
.
tutorialId
.
equals
(
tutorialId
));
if
(
!
tutorialProgress
)
{
curriculumProgress
.
tutorialProgress
.
push
({
tutorialId
,
completed
});
}
else
{
tutorialProgress
.
completed
=
completed
;
}
userProgress
.
marks
=
marks
;
await
userProgress
.
save
();
res
.
status
(
200
).
json
(
userProgress
);
}
catch
(
error
)
{
res
.
status
(
500
).
json
({
message
:
error
.
message
});
}
}
Project/Backend/Server_Node/models/curriculum.model.js
View file @
7fb6e5cb
...
...
@@ -14,6 +14,20 @@ const curriculumSchema = new mongoose.Schema({
curriculumImage
:
String
,
tutorials
:
[
tutorialSchema
],
// Embed tutorials as subdocuments
// Additional fields for curriculum details
status
:
{
type
:
Number
,
default
:
1
,
// Default status as active (1)
},
createdBy
:
String
,
updatedBy
:
String
,
createdAt
:
{
type
:
Date
,
default
:
new
Date
(),
},
updatedAt
:
{
type
:
Date
,
default
:
new
Date
(),
},
});
const
Curriculum
=
mongoose
.
model
(
"
Curriculum
"
,
curriculumSchema
);
...
...
Project/Backend/Server_Node/models/tutorial.model.js
View file @
7fb6e5cb
...
...
@@ -15,6 +15,20 @@ const tutorialSchema = new mongoose.Schema({
tutorialImage
:
String
,
taskItems
:
[
taskItemSchema
],
// Embed task items as subdocuments
// Additional fields for tutorial details
status
:
{
type
:
Number
,
default
:
1
,
// Default status as active (1)
},
createdBy
:
String
,
updatedBy
:
String
,
createdAt
:
{
type
:
Date
,
default
:
new
Date
(),
},
updatedAt
:
{
type
:
Date
,
default
:
new
Date
(),
},
});
const
Tutorial
=
mongoose
.
model
(
"
Tutorial
"
,
tutorialSchema
);
...
...
Project/Backend/Server_Node/models/userProgress.model.js
0 → 100644
View file @
7fb6e5cb
import
mongoose
from
"
mongoose
"
;
const
userProgressSchema
=
new
mongoose
.
Schema
({
userId
:
{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
required
:
true
,
ref
:
'
User
'
// Reference to the User model
},
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
:
{
type
:
Number
,
default
:
0
}
});
const
UserProgress
=
mongoose
.
model
(
"
UserProgress
"
,
userProgressSchema
);
export
default
UserProgress
;
Project/Backend/Server_Node/routes/userProgress.routes.js
0 → 100644
View file @
7fb6e5cb
import
express
from
"
express
"
;
import
{
getUserProgress
,
updateUserProgress
}
from
"
../controllers/userProgress.controller.js
"
;
const
router
=
express
.
Router
();
router
.
get
(
'
/:userId
'
,
getUserProgress
);
router
.
post
(
'
/:userId
'
,
updateUserProgress
);
export
default
router
;
Project/Backend/Server_Node/server.js
View file @
7fb6e5cb
...
...
@@ -5,8 +5,11 @@ import express from "express";
import
mongoose
from
"
mongoose
"
;
//import routes
import
curriculumRoutes
from
"
./routes/curriculum.routes.js
"
;
import
translateRoutes
from
"
./routes/translate.routes.js
"
;
import
tutorialRoutes
from
"
./routes/tutorial.routes.js
"
;
import
userRoutes
from
"
./routes/user.routes.js
"
;
import
userProgressRoutes
from
"
./routes/userProgress.routes.js
"
;
dotenv
.
config
();
const
app
=
express
();
...
...
@@ -23,6 +26,11 @@ app.get("/", (req, res) => {
//implement routes
app
.
use
(
"
/rest_node/ssl
"
,
translateRoutes
);
app
.
use
(
"
/rest_node/user
"
,
userRoutes
);
app
.
use
(
"
/rest_node/curriculum
"
,
curriculumRoutes
);
app
.
use
(
"
/rest_node/tutorial
"
,
tutorialRoutes
);
app
.
use
(
"
/rest_node/user-progress
"
,
userProgressRoutes
);
const
CONNECTION_URL
=
`mongodb+srv://
${
process
.
env
.
DB_USERNAME
}
:
${
process
.
env
.
DB_PASSWORD
}
@researchmanagement-appl.vzhn4.mongodb.net/?retryWrites=true&w=majority`
;
const
PORT
=
process
.
env
.
PORT
||
5000
;
...
...
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