Skip to content

Commit d346d59

Browse files
changes after randhir review
1 parent 8657ae4 commit d346d59

File tree

4 files changed

+32
-25
lines changed

4 files changed

+32
-25
lines changed

controllers/users.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const chaincodeQuery = require("../models/chaincodes");
22
const userQuery = require("../models/users");
3+
const userStatusModel = require("../models/userStatus");
34
const profileDiffsQuery = require("../models/profileDiffs");
45
const logsQuery = require("../models/logs");
56
const imageService = require("../services/imageService");
@@ -389,7 +390,7 @@ const addUserIntro = async (req, res) => {
389390
};
390391

391392
if (rawData.numberOfHours) {
392-
await userQuery.updateMonthlyHours(rawData.numberOfHours, req.userData.id);
393+
await userStatusModel.updateMonthlyHours(4 * rawData.numberOfHours, req.userData.id);
393394
}
394395

395396
await userQuery.addJoinData(data);

models/userStatus.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,27 @@ const updateUserStatus = async (userId, newStatusData) => {
136136
}
137137
};
138138

139+
/**
140+
* Sets the monthlyHours field of passed UserId to numberOfHours
141+
*
142+
* @param monthlyHours { integer }: numberOfHours
143+
* @param userId { string }: User id
144+
*/
145+
146+
const updateMonthlyHours = async (numberOfHours, userId) => {
147+
const userStatusDocs = await userStatusModel.where("userId", "==", userId).limit(1).get();
148+
const [userStatusDoc] = userStatusDocs.docs;
149+
if (userStatusDoc) {
150+
const docId = userStatusDoc.id;
151+
return userStatusModel.doc(docId).update({
152+
monthlyHours: {
153+
committed: numberOfHours,
154+
},
155+
});
156+
}
157+
return {};
158+
};
159+
139160
/**
140161
* @param userId { String }: Id of the User
141162
* @param newStatusData { Object }: Data to be Updated
@@ -193,4 +214,11 @@ const updateAllUserStatus = async () => {
193214
}
194215
};
195216

196-
module.exports = { deleteUserStatus, getUserStatus, getAllUserStatus, updateUserStatus, updateAllUserStatus };
217+
module.exports = {
218+
deleteUserStatus,
219+
getUserStatus,
220+
getAllUserStatus,
221+
updateUserStatus,
222+
updateMonthlyHours,
223+
updateAllUserStatus,
224+
};

models/users.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -312,27 +312,6 @@ const updateUserPicture = async (image, userId) => {
312312
}
313313
};
314314

315-
/**
316-
* Sets the monthlyHours field of passed UserId to userNumberOfHours
317-
*
318-
* @param monthlyHours { integer }: userNumberOfHours
319-
* @param userId { string }: User id
320-
*/
321-
322-
const updateMonthlyHours = async (userNumberOfHours, userId) => {
323-
const userStatusDocs = await userStatusModel.where("userId", "==", userId).limit(1).get();
324-
const [userStatusDoc] = userStatusDocs.docs;
325-
if (userStatusDoc) {
326-
const docId = userStatusDoc.id;
327-
return userStatusModel.doc(docId).update({
328-
monthlyHours: {
329-
committed: 4 * userNumberOfHours,
330-
},
331-
});
332-
}
333-
return {};
334-
};
335-
336315
/**
337316
* fetch the users image by passing array of users
338317
*
@@ -445,7 +424,6 @@ module.exports = {
445424
setIncompleteUserDetails,
446425
initializeUser,
447426
updateUserPicture,
448-
updateMonthlyHours,
449427
fetchUserImage,
450428
addJoinData,
451429
getJoinData,

test/integration/userStatus.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ describe("UserStatus", function () {
398398
expect(res).to.have.status(400);
399399
expect(res.body).to.be.an("object");
400400
expect(res.body.error).to.equal(`Bad Request`);
401-
expect(res.body.message).to.equal(`Invalid State. State must be either IDLE, ACTIVE or OOO`);
401+
expect(res.body.message).to.equal(`Invalid State. State must be either IDLE, ACTIVE, OOO, or ONBOARDING`);
402402
return done();
403403
});
404404
});

0 commit comments

Comments
 (0)