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
3a2f0111
Commit
3a2f0111
authored
Aug 24, 2023
by
janithGamage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat : update
Desc : leadboard and feedback backend config
parent
7fb6e5cb
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
113 additions
and
2 deletions
+113
-2
.vscode/settings.json
.vscode/settings.json
+1
-0
Project/Backend/Server_Node/controllers/feedback.controller.js
...ct/Backend/Server_Node/controllers/feedback.controller.js
+31
-0
Project/Backend/Server_Node/controllers/leaderboard.controller.js
...Backend/Server_Node/controllers/leaderboard.controller.js
+33
-0
Project/Backend/Server_Node/models/feedback.model.js
Project/Backend/Server_Node/models/feedback.model.js
+27
-0
Project/Backend/Server_Node/routes/feedback.routes.js
Project/Backend/Server_Node/routes/feedback.routes.js
+9
-0
Project/Backend/Server_Node/routes/leaderboard.routes.js
Project/Backend/Server_Node/routes/leaderboard.routes.js
+8
-0
Project/Backend/Server_Node/server.js
Project/Backend/Server_Node/server.js
+4
-2
No files found.
.vscode/settings.json
View file @
3a2f0111
{
"cSpell.words"
:
[
"Janith"
,
"leaderboard"
,
"SLIIT"
]
}
\ No newline at end of file
Project/Backend/Server_Node/controllers/feedback.controller.js
0 → 100644
View file @
3a2f0111
import
Feedback
from
'
../models/feedback.model.js
'
;
export
const
createFeedback
=
async
(
req
,
res
)
=>
{
const
{
userId
,
entityId
,
rating
,
comment
}
=
req
.
body
;
try
{
const
feedback
=
new
Feedback
({
userId
,
entityId
,
rating
,
comment
});
await
feedback
.
save
();
res
.
status
(
201
).
json
({
code
:
'
01
'
,
message
:
'
Feedback submitted successfully
'
});
}
catch
(
error
)
{
res
.
status
(
500
).
json
({
code
:
'
00
'
,
message
:
'
Error submitting feedback
'
});
}
}
export
const
getFeedbackForEntity
=
async
(
req
,
res
)
=>
{
const
entityId
=
req
.
params
.
entityId
;
try
{
const
feedback
=
await
Feedback
.
find
({
entityId
}).
populate
(
'
userId
'
,
'
firstName lastName
'
);
res
.
status
(
200
).
json
(
feedback
);
}
catch
(
error
)
{
res
.
status
(
500
).
json
({
code
:
'
00
'
,
message
:
'
Error fetching feedback
'
});
}
}
Project/Backend/Server_Node/controllers/leaderboard.controller.js
0 → 100644
View file @
3a2f0111
import
UserProgress
from
'
../models/userProgress.model.js
'
;
export
const
getGlobalLeaderboard
=
async
(
req
,
res
)
=>
{
try
{
const
userProgressList
=
await
UserProgress
.
find
({},
'
userId curriculumId tutorialProgress.marks
'
).
populate
(
'
userId
'
,
'
firstName lastName
'
);
// Aggregate user progress data to calculate total marks and progress
const
leaderboard
=
userProgressList
.
map
(
userProgress
=>
{
const
totalMarks
=
userProgress
.
curriculumId
.
reduce
((
total
,
curriculum
)
=>
{
return
total
+
curriculum
.
tutorialProgress
.
reduce
((
totalTutMarks
,
tutorial
)
=>
{
return
totalTutMarks
+
(
tutorial
.
completed
?
tutorial
.
marks
:
0
);
},
0
);
},
0
);
const
totalTutorials
=
userProgress
.
curriculumId
.
reduce
((
totalTut
,
curriculum
)
=>
{
return
totalTut
+
curriculum
.
tutorialProgress
.
length
;
},
0
);
return
{
user
:
userProgress
.
userId
,
totalMarks
,
totalTutorials
};
});
// Sort leaderboard based on total marks
leaderboard
.
sort
((
a
,
b
)
=>
b
.
totalMarks
-
a
.
totalMarks
);
res
.
status
(
200
).
json
(
leaderboard
);
}
catch
(
error
)
{
res
.
status
(
500
).
json
({
message
:
'
Error fetching global leaderboard
'
});
}
}
Project/Backend/Server_Node/models/feedback.model.js
0 → 100644
View file @
3a2f0111
import
mongoose
from
'
mongoose
'
;
const
feedbackSchema
=
new
mongoose
.
Schema
({
userId
:
{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
required
:
true
,
ref
:
'
User
'
// Reference to the User model
},
entityId
:
{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
required
:
true
,
// This could be the tutorial or curriculum ID
ref
:
'
Tutorial
'
// Reference to the Tutorial model (or Curriculum model)
},
rating
:
{
type
:
Number
,
required
:
true
},
comment
:
String
,
createdAt
:
{
type
:
Date
,
default
:
new
Date
()
}
});
const
Feedback
=
mongoose
.
model
(
'
Feedback
'
,
feedbackSchema
);
export
default
Feedback
;
Project/Backend/Server_Node/routes/feedback.routes.js
0 → 100644
View file @
3a2f0111
import
express
from
'
express
'
;
import
{
createFeedback
,
getFeedbackForEntity
}
from
'
../controllers/feedback.controller.js
'
;
const
router
=
express
.
Router
();
router
.
post
(
'
/
'
,
createFeedback
);
router
.
get
(
'
/:entityId
'
,
getFeedbackForEntity
);
export
default
router
;
Project/Backend/Server_Node/routes/leaderboard.routes.js
0 → 100644
View file @
3a2f0111
import
express
from
'
express
'
;
import
{
getGlobalLeaderboard
}
from
'
../controllers/leaderboard.controller.js
'
;
const
router
=
express
.
Router
();
router
.
get
(
'
/global
'
,
getGlobalLeaderboard
);
export
default
router
;
Project/Backend/Server_Node/server.js
View file @
3a2f0111
...
...
@@ -6,6 +6,8 @@ import mongoose from "mongoose";
//import routes
import
curriculumRoutes
from
"
./routes/curriculum.routes.js
"
;
import
feedbackRoutes
from
"
./routes/feedback.routes.js
"
;
import
leaderboardRoutes
from
"
./routes/leaderboard.routes.js
"
;
import
translateRoutes
from
"
./routes/translate.routes.js
"
;
import
tutorialRoutes
from
"
./routes/tutorial.routes.js
"
;
import
userRoutes
from
"
./routes/user.routes.js
"
;
...
...
@@ -29,8 +31,8 @@ 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
);
app
.
use
(
"
/rest_node/feedback
"
,
feedbackRoutes
);
app
.
use
(
"
/rest_node/leaderboard
"
,
leaderboardRoutes
);
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