Skip to content

Commit

Permalink
Merge branch 'develop' into feat/remove-unverified-role
Browse files Browse the repository at this point in the history
  • Loading branch information
prakashchoudhary07 authored Nov 2, 2024
2 parents 8604f61 + f8d76e1 commit e59507b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 36 deletions.
22 changes: 9 additions & 13 deletions controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,16 @@ const getUsers = async (req, res) => {
const profile = req.query.profile === "true";

if (profile) {
if (dev) {
if (!req.userData.id) {
return res.boom.badRequest("User ID not provided.");
}
if (!req.userData.id) {
return res.boom.badRequest("User ID not provided.");
}

try {
const result = await dataAccess.retrieveUsers({ id: req.userData.id });
return res.send(result.user);
} catch (error) {
logger.error(`Error while fetching user: ${error}`);
return res.boom.serverUnavailable(INTERNAL_SERVER_ERROR);
}
} else {
return res.boom.badRequest("Route not found");
try {
const result = await dataAccess.retrieveUsers({ id: req.userData.id });
return res.send(result.user);
} catch (error) {
logger.error(`Error while fetching user: ${error}`);
return res.boom.serverUnavailable(INTERNAL_SERVER_ERROR);
}
}

Expand Down
22 changes: 3 additions & 19 deletions test/integration/users.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -904,10 +904,10 @@ describe("Users", function () {
});
});

it("Should return the logged-in user's details when profile and dev is true", function (done) {
it("Should return the logged-in user's details when profile is true", function (done) {
chai
.request(app)
.get("/users?profile=true&dev=true")
.get("/users?profile=true")
.set("cookie", `${cookieName}=${jwt}`)
.end((err, res) => {
if (err) {
Expand All @@ -923,26 +923,10 @@ describe("Users", function () {
});
});

it("Should throw an error when there is no feature flag given", function (done) {
chai
.request(app)
.get("/users?profile=true")
.set("cookie", `${cookieName}=${jwt}`)
.end((err, res) => {
if (err) {
return done(err);
}
expect(res).to.have.status(400);
expect(res.body).to.be.an("object");
expect(res.body.message).to.equal("Route not found");
return done();
});
});

it("Should return 401 if not logged in", function (done) {
chai
.request(app)
.get("/users?profile=true&dev=true")
.get("/users?profile=true")
.set("cookie", `${cookieName}=invalid_token`)
.end((err, res) => {
if (err) {
Expand Down
8 changes: 4 additions & 4 deletions utils/task-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ const transformTaskRequests = async (taskRequestsList: TaskRequestType[]) => {
taskRequestsList.forEach((data) => {
data.users = data.users.map((userData) => {
const user = usersMap.get(userData.userId);
const username = user?.username || 'Undefined';
const firstName = user?.first_name || 'Undefined';
const lastName = user?.last_name || 'Undefined';
const picture = user?.picture || null;
const username = user?.username
const firstName = user?.first_name
const lastName = user?.last_name
const picture = user?.picture;

return { ...userData, username, first_name: firstName, last_name: lastName, picture };
});
Expand Down

0 comments on commit e59507b

Please sign in to comment.