Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend Changes for Trophy functionality #1180

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/controllers/dashBoardController.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import userProfile from 'models/userProfile';
import actionItem from 'models/actionItem';

/* eslint-disable quotes */
const path = require("path");
const fs = require("fs/promises");
Expand All @@ -7,6 +10,7 @@ const emailSender = require("../utilities/emailSender");
const AIPrompt = require("../models/weeklySummaryAIPrompt");
const User = require("../models/userProfile");


const dashboardcontroller = function () {
const dashboardhelper = dashboardHelperClosure();
const dashboarddata = function (req, res) {
Expand Down Expand Up @@ -137,6 +141,26 @@ const dashboardcontroller = function () {
.catch(error => res.status(400).send(error));
};

//6th month and yearly anniversaries
const postTrophyIcon = function (req, res) {
console.log("API called with params:", req.params);
const userId = mongoose.Types.ObjectId(req.params.userId);

userProfile.findById(userId, (err, record) => {
if (err || !record) {
res.status(404).send('No valid records found');
return;
}
record.trophyFollowedUp = req.params.trophyFollowedUp;

record.save()
.then((results) => {
res.status(200).send(results);
})
.catch((error) => res.status(404).send(error));
});
};

const orgData = function (req, res) {
const fullOrgData = dashboardhelper.getOrgData();

Expand Down Expand Up @@ -330,6 +354,7 @@ const dashboardcontroller = function () {
}
};


return {
dashboarddata,
getAIPrompt,
Expand All @@ -344,6 +369,7 @@ const dashboardcontroller = function () {
sendMakeSuggestion,
updateCopiedPrompt,
getPromptCopiedDate,
postTrophyIcon,
};
};

Expand Down
9 changes: 8 additions & 1 deletion src/helpers/dashboardhelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ const dashboardhelper = function () {
timeOffFrom: 1,
timeOffTill: 1,
endDate: 1,
createdDate: 1,
trophyFollowedUp: 1,
}

);
Expand All @@ -220,7 +222,8 @@ const dashboardhelper = function () {
timeOffFrom: 1,
timeOffTill: 1,
endDate: 1,

createdDate: 1,
trophyFollowedUp: 1,
},
);
}
Expand Down Expand Up @@ -286,6 +289,8 @@ const dashboardhelper = function () {
timeOffFrom: teamMember.timeOffFrom || null,
timeOffTill: teamMember.timeOffTill || null,
endDate: teamMember.endDate || null,
createdDate: teamMember.createdDate || null,
trophyFollowedUp: teamMember.trophyFollowedUp || false,
};
leaderBoardData.push(obj);
});
Expand Down Expand Up @@ -601,6 +606,8 @@ const dashboardhelper = function () {
personId: userId,
role: user.role,
isVisible: user.isVisible,
createdDate: user.createdDate,
trophyFollowedUp: user.trophyFollowedUp,
hasSummary: user.weeklySummaries[0].summary !== '',
weeklycommittedHours: user.weeklycommittedHours,
name: `${user.firstName} ${user.lastName}`,
Expand Down
1 change: 1 addition & 0 deletions src/helpers/reporthelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const reporthelper = function () {
weeklySummaryOption: 1,
adminLinks: 1,
bioPosted: 1,
toggleTrophyIcon: 1,
badgeCollection: {
$filter: {
input: "$badgeCollection",
Expand Down
1 change: 1 addition & 0 deletions src/models/userProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ const userProfileSchema = new Schema({
isVisible: { type: Boolean, default: true },
weeklySummaryOption: { type: String },
bioPosted: { type: String, default: 'default' },
trophyFollowedUp: { type: Boolean, default: false },
isFirstTimelog: { type: Boolean, default: true },
badgeCount: { type: Number, default: 0 },
teamCode: {
Expand Down
3 changes: 3 additions & 0 deletions src/routes/dashboardRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const route = function () {
Dashboardrouter.route('/dashboard/leaderboard/org/data')
.get(controller.orgData);

Dashboardrouter.route('/dashboard/leaderboard/trophyIcon/:userId/:trophyFollowedUp')
.post(controller.postTrophyIcon);

Dashboardrouter.route('/dashboard/suggestionoption/:userId')
.get(controller.getSuggestionOption);

Expand Down