Skip to content
Merged
Show file tree
Hide file tree
Changes from 130 commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
8dffd72
api created
ivinayakg May 13, 2023
2c63ca5
done suggested changes
ivinayakg May 13, 2023
aa1702e
added one more check
ivinayakg May 13, 2023
2ca0068
changes in the update task api
ivinayakg May 13, 2023
786097f
initial commit
manish591 Jul 21, 2023
5881d16
test/added integration tests for route /update-archived
manish591 Jul 22, 2023
02004d4
test/added tests for function archiveUserIfNotInDiscord
manish591 Jul 22, 2023
8872d02
refactor: overdue and extension requests APIs
ivinayakg Jul 22, 2023
6cc53cc
feat/added route controller and model function
manish591 Jul 22, 2023
23b4799
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
manish591 Jul 22, 2023
44e0702
remove redundant code
manish591 Jul 22, 2023
ca735c5
removed redundant code
manish591 Jul 22, 2023
d225c0f
FIX: resolved comments
manish591 Jul 25, 2023
2d95d97
Merge branch 'develop' into feat/archive-user-if-not-in-discord
manish591 Jul 25, 2023
db54d13
FIX: merge conflicts
manish591 Jul 25, 2023
ca2e1f6
FIX: resolved comments
manish591 Jul 26, 2023
40b60c5
TEST: updated tests
manish591 Jul 26, 2023
2378f7d
REFACTOR: updated variable names
manish591 Jul 26, 2023
3bb006a
TEST: assert total users made archived
manish591 Jul 26, 2023
b5caca6
REFACTOR: updated route
manish591 Jul 26, 2023
da99471
TEST: updated route
manish591 Jul 26, 2023
9b2946a
FEAT: handles batch updates more that 500
manish591 Jul 27, 2023
8e06bc8
TEST: updated tests
manish591 Jul 27, 2023
aab3d73
TEST: assert for failed operation added
manish591 Jul 27, 2023
3c2ae54
FIX: added error handling for failed batch updates
manish591 Jul 27, 2023
56ed770
REFACTOR: removed redundant changes
manish591 Jul 27, 2023
65a1a0c
TEST: fetched only users relavant in testing
manish591 Jul 29, 2023
768ee5c
TEST: updated users integration tests
manish591 Jul 29, 2023
c4ebcd5
Merge branch 'develop' into feat/archive-user-if-not-in-discord
manish591 Jul 29, 2023
fc31550
TEST: added tests for archiver user function
manish591 Jul 29, 2023
5e58cfa
reolved comments
manish591 Jul 29, 2023
ef6a4ca
Merge branch 'feat/archive-user-if-not-in-discord' of https://github.…
manish591 Jul 29, 2023
6d91874
feat: added test cases for tasks validators
ivinayakg Jul 30, 2023
137ba54
REFACTOR: to remove circular dependency
manish591 Jul 30, 2023
d8a8a4a
added onBoarding status of user more than 31 days
Pratiyushkumar Aug 1, 2023
2326828
finally finalized the route of the onboarding state
Pratiyushkumar Aug 2, 2023
97c7fee
FEAT: added common route /users
manish591 Aug 2, 2023
2b05f0e
TEST: updated tests
manish591 Aug 2, 2023
5336d29
TEST: fix failed tests
manish591 Aug 2, 2023
35b52cb
REFACTOR: changed param to query
manish591 Aug 2, 2023
157160e
Merge branch 'develop' into feature/current-overdue-tasks-api
ivinayakg Aug 2, 2023
2e651f2
add: github created at key in db for new joiner
ravikumar1002 Aug 3, 2023
d7c0908
refactor: requested changes for overdue tasks API
ivinayakg Aug 3, 2023
c55fea9
Merge branch 'develop' of https://github.com/ravikumar1002/website-ba…
ravikumar1002 Aug 3, 2023
8d18645
fix: convert date type into unix timestamp
ravikumar1002 Aug 4, 2023
ce27208
Merge branch 'develop' of https://github.com/ravikumar1002/website-ba…
ravikumar1002 Aug 4, 2023
605ad92
TEST: added model error test case
manish591 Aug 4, 2023
763f359
REFACTOR: added payload validator middleware
manish591 Aug 4, 2023
1367c18
REFACTOR: added error & success states constants
manish591 Aug 4, 2023
081639a
FEAT: added failed users details in response
manish591 Aug 4, 2023
a873faf
REFACTOR: resolved comments
manish591 Aug 4, 2023
29f0843
Merge branch 'develop' into feat/archive-user-if-not-in-discord
manish591 Aug 4, 2023
49bd0d4
REFACTOR: fix lint issues
manish591 Aug 4, 2023
0404f05
TEST: updated user service test
manish591 Aug 4, 2023
613e466
changed the variables name
Pratiyushkumar Aug 5, 2023
1bb76e3
(#1367) added fix for api response
isVivek99 Aug 5, 2023
510dd1d
(#1367) updated tests for the code
isVivek99 Aug 5, 2023
dc52cc9
(#1367) address failing test for validator
isVivek99 Aug 5, 2023
afa09b5
(#1367) address failing validator test
isVivek99 Aug 5, 2023
c14d25d
refactor: changed the flow for overdue tasks API
ivinayakg Aug 5, 2023
183dc48
removed the filter utility function
Pratiyushkumar Aug 6, 2023
b1abccb
fix: Unix Timestamp method
ravikumar1002 Aug 6, 2023
aef3ea3
Merge branch 'develop' of https://github.com/ravikumar1002/website-ba…
ravikumar1002 Aug 6, 2023
36edb24
feat: test for github_created_at fields
ravikumar1002 Aug 6, 2023
1b745bf
remove: extra fixtures data
ravikumar1002 Aug 7, 2023
3488b2c
added integration test case
Pratiyushkumar Aug 8, 2023
b0b54d2
commiting unit testing
Pratiyushkumar Aug 8, 2023
2e27027
unit testing is done
Pratiyushkumar Aug 9, 2023
9949dc9
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
isVivek99 Aug 10, 2023
37297d5
Merge branch 'develop' into feat/archive-user-if-not-in-discord
manish591 Aug 11, 2023
dcfc76a
resolved conflicts
manish591 Aug 11, 2023
f412ba5
TEST: fix failing test
manish591 Aug 11, 2023
5a78410
Merge branch 'develop' into feat/archive-user-if-not-in-discord
manish591 Aug 11, 2023
5bded43
refactor: made the overdue tasks API behind the feature flag
ivinayakg Aug 11, 2023
89838a5
refactor: overdue and extension requests APIs
ivinayakg Jul 22, 2023
94d51d8
feat: added test cases for tasks validators
ivinayakg Jul 30, 2023
f3ce39e
refactor: requested changes for overdue tasks API
ivinayakg Aug 3, 2023
eac8ed8
refactor: changed the flow for overdue tasks API
ivinayakg Aug 5, 2023
98dfd8c
refactor: made the overdue tasks API behind the feature flag
ivinayakg Aug 11, 2023
8e41cd2
Merge branch 'feature/current-overdue-tasks-api' of https://github.co…
ivinayakg Aug 11, 2023
f3034f9
Merge branch 'develop' into feat/archive-user-if-not-in-discord
manish591 Aug 12, 2023
f0df584
(#1367) added dataAccessLayer to fetch user
isVivek99 Aug 12, 2023
9803654
(#1368) updated model tests
isVivek99 Aug 12, 2023
b1e0d54
refactor: overdue and extension requests APIs
ivinayakg Jul 22, 2023
b6f2124
feat: added test cases for tasks validators
ivinayakg Jul 30, 2023
6c81de8
refactor: requested changes for overdue tasks API
ivinayakg Aug 3, 2023
074de65
refactor: changed the flow for overdue tasks API
ivinayakg Aug 5, 2023
e52ccfc
refactor: made the overdue tasks API behind the feature flag
ivinayakg Aug 11, 2023
9433039
api created
ivinayakg May 13, 2023
0e6e8c4
done suggested changes
ivinayakg May 13, 2023
20bb7c2
added one more check
ivinayakg May 13, 2023
224b2c9
refactor: overdue and extension requests APIs
ivinayakg Jul 22, 2023
2fba8cd
feat: added test cases for tasks validators
ivinayakg Jul 30, 2023
fc8101e
refactor: requested changes for overdue tasks API
ivinayakg Aug 3, 2023
3432d30
refactor: changed the flow for overdue tasks API
ivinayakg Aug 5, 2023
55604db
Merge branch 'feature/current-overdue-tasks-api' of https://github.co…
ivinayakg Aug 12, 2023
267815b
Merge pull request #1362 from ravikumar1002/feat/github-created-at
iamitprakash Aug 12, 2023
5d6a15e
Merge pull request #1311 from manish591/feat/archive-user-if-not-in-d…
iamitprakash Aug 12, 2023
eeb0dff
changed the function working and made the getUsersBasedOnFilter generic
Pratiyushkumar Aug 13, 2023
c525366
Merge branch 'develop' into fix/onBoarding31
Pratiyushkumar Aug 13, 2023
7c8c560
completed validation of verify status
shreya-mishra11 Aug 10, 2023
82addc6
tests for model and middleware
lakshayman Aug 11, 2023
c589152
resolved the comments
shreya-mishra11 Aug 11, 2023
a3d4e35
completed validation of verify status
shreya-mishra11 Aug 10, 2023
c00c825
resolved the comments
shreya-mishra11 Aug 11, 2023
3a4e95b
sync with develop
shreya-mishra11 Aug 12, 2023
f46faeb
resolved the comments and added generateUniqueToken action
shreya-mishra11 Aug 12, 2023
228ca27
fixed failing tests
lakshayman Aug 13, 2023
967acea
Validation after authentication
lakshayman Aug 13, 2023
62eedaf
fixing code
lakshayman Aug 13, 2023
e9be5ba
Merge pull request #1400 from Real-Dev-Squad/verifyStatusValidation1
iamitprakash Aug 13, 2023
5826e2a
Refactor: keeping body optional in archiving details in the archiving…
gauravsinhaweb Aug 13, 2023
de9f909
update error message
isVivek99 Aug 14, 2023
0ab4c07
Merge pull request #1402 from Real-Dev-Squad/feature/current-overdue-…
iamitprakash Aug 14, 2023
c17832a
Merge branch 'develop' of https://github.com/Real-Dev-Squad/website-b…
isVivek99 Aug 14, 2023
9266ba4
Merge pull request #1368 from Real-Dev-Squad/fix/qr-code-auth-post
iamitprakash Aug 14, 2023
3dfe137
added onBoarding condition
Pratiyushkumar Aug 15, 2023
5c9d3d2
Merge branch 'fix/onBoarding31' of https://github.com/Real-Dev-Squad/…
Pratiyushkumar Aug 15, 2023
8d6b972
fixed prettier error and added logical and
Pratiyushkumar Aug 15, 2023
a6ef992
Merge pull request #1414 from gauravsinhaweb/develop
iamitprakash Aug 15, 2023
965ef9a
validator test cases added and corrected spelling mistake
Pratiyushkumar Aug 16, 2023
6fd6414
fix the staging for archived users (#1421)
RitikJaiswal75 Aug 16, 2023
d38bf93
Merge pull request #1356 from Real-Dev-Squad/fix/onBoarding31
iamitprakash Aug 17, 2023
5a2ade7
removing one time script - remove tokens
fakhruddinkw Aug 17, 2023
cf38384
forgot to remove tests
fakhruddinkw Aug 17, 2023
852cbbb
Merge pull request #1423 from Real-Dev-Squad/removal/token-script
ankushdharkar Aug 19, 2023
ff04020
API endpoint to update Discord usernames for backend users (#1378)
kotesh-arya Aug 22, 2023
1105c7b
Revert "Revert "Dev to Main Sync""
prakashchoudhary07 Aug 22, 2023
24b9eed
Merge branch 'main' into resolve-merge-conflicts
prakashchoudhary07 Aug 22, 2023
75033a6
Merge pull request #1438 from Real-Dev-Squad/resolve-merge-conflicts
prakashchoudhary07 Aug 22, 2023
b316327
FEATURE: Filter task based assignee and task title (#1392)
sahsisunny Aug 22, 2023
eb5e9a5
FIX: Overdue tasks query issue (#1441)
sahsisunny Aug 22, 2023
3477da6
Add isMember Field to API Response for Group Membership (#1413)
bksh05 Aug 23, 2023
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
1 change: 1 addition & 0 deletions constants/errorMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ module.exports = {
BAD_REQUEST: "BAD_REQUEST",
INVALID_QUERY_PARAM: "Invalid Query Parameters Passed",
FILE_TOO_LARGE: (size) => `File too large, max accepted size is ${size} MB`,
USER_DOES_NOT_EXIST_ERROR: "User does not exist!",
};
1 change: 1 addition & 0 deletions constants/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const TASK_STATUS = {
RELEASED: "RELEASED",
VERIFIED: "VERIFIED",
DONE: "DONE",
OVERDUE: "OVERDUE",
};

// TODO: convert this to new task status
Expand Down
21 changes: 21 additions & 0 deletions constants/userDataLevels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const ACCESS_LEVEL = {
PUBLIC: "public",
INTERNAL: "internal",
PRIVATE: "private",
CONFIDENTIAL: "confidential",
};

const ROLE_LEVEL = {
private: ["super_user"],
internal: ["super_user"],
confidential: ["super_user"],
};

const KEYS_NOT_ALLOWED = {
public: ["email", "phone", "chaincode"],
internal: ["phone", "chaincode"],
private: ["chaincode"],
confidential: [],
};

module.exports = { ACCESS_LEVEL, KEYS_NOT_ALLOWED, ROLE_LEVEL };
29 changes: 26 additions & 3 deletions constants/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const profileStatus = {
NOT_APPROVED: "NOT APPROVED",
};

const USER_SENSITIVE_DATA = ["phone", "email", "chaincode", "tokens"];

const USER_STATUS = {
OOO: "ooo",
IDLE: "idle",
Expand All @@ -19,9 +17,34 @@ const ALLOWED_FILTER_PARAMS = {
ROLE: ["role"],
};

const DOCUMENT_WRITE_SIZE = 500;

const USERS_PATCH_HANDLER_ACTIONS = {
ARCHIVE_USERS: "archiveUsers",
NON_VERFIED_DISCORD_USERS: "nonVerifiedDiscordUsers",
};

const USERS_PATCH_HANDLER_ERROR_MESSAGES = {
VALIDATE_PAYLOAD: "Invalid Payload",
ARCHIVE_USERS: {
NO_USERS_DATA_TO_UPDATE: "Couldn't find any users currently inactive in Discord but not archived.",
BATCH_DATA_UPDATED_FAILED: "Firebase batch operation failed",
},
};

const USERS_PATCH_HANDLER_SUCCESS_MESSAGES = {
ARCHIVE_USERS: {
SUCCESSFULLY_UPDATED_DATA: "Successfully updated users archived role to true if in_discord role is false",
SUCCESSFULLY_COMPLETED_BATCH_UPDATES: "Successfully completed batch updates",
},
};

module.exports = {
profileStatus,
USER_STATUS,
ALLOWED_FILTER_PARAMS,
USER_SENSITIVE_DATA,
DOCUMENT_WRITE_SIZE,
USERS_PATCH_HANDLER_ACTIONS,
USERS_PATCH_HANDLER_ERROR_MESSAGES,
USERS_PATCH_HANDLER_SUCCESS_MESSAGES,
};
48 changes: 37 additions & 11 deletions controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ const passport = require("passport");
const users = require("../models/users");
const QrCodeAuthModel = require("../models/qrCodeAuth");
const authService = require("../services/authService");
const { SOMETHING_WENT_WRONG, DATA_ADDED_SUCCESSFULLY, BAD_REQUEST } = require("../constants/errorMessages");
const dataAccess = require("../services/dataAccessLayer");
const {
SOMETHING_WENT_WRONG,
DATA_ADDED_SUCCESSFULLY,
USER_DOES_NOT_EXIST_ERROR,
} = require("../constants/errorMessages");
const { generateUniqueToken } = require("../utils/generateUniqueToken");

/**
* Makes authentication call to GitHub statergy
Expand Down Expand Up @@ -49,11 +55,10 @@ const githubAuthCallback = (req, res, next) => {
logger.error(err);
return res.boom.unauthorized("User cannot be authenticated");
}

userData = {
github_id: user.username,
github_display_name: user.displayName,
// github_account_created_at: user.created_at,
github_created_at: Number(new Date(user._json.created_at).getTime()),
created_at: Date.now(),
updated_at: Date.now(),
};
Expand Down Expand Up @@ -111,13 +116,12 @@ const storeUserDeviceInfo = async (req, res) => {
authorization_status: "NOT_INIT",
};

const userInfo = await QrCodeAuthModel.storeUserDeviceInfo(userJson);
const userInfoData = await dataAccess.retrieveUsers({ id: userJson.user_id });

if (!userInfo) {
return res.status(404).json({
message: BAD_REQUEST,
});
if (!userInfoData.userExists) {
return res.boom.notFound(USER_DOES_NOT_EXIST_ERROR);
}
const userInfo = await QrCodeAuthModel.storeUserDeviceInfo(userJson);

return res.status(201).json({
...userInfo,
Expand All @@ -133,7 +137,11 @@ const updateAuthStatus = async (req, res) => {
try {
const userId = req.userData.id;
const authStatus = req.params.authorization_status;
const result = await QrCodeAuthModel.updateStatus(userId, authStatus);
let token;
if (authStatus === "AUTHORIZED") {
token = await generateUniqueToken();
}
const result = await QrCodeAuthModel.updateStatus(userId, authStatus, token);

if (!result.userExists) {
return res.boom.notFound("Document not found!");
Expand All @@ -151,8 +159,8 @@ const updateAuthStatus = async (req, res) => {

const fetchUserDeviceInfo = async (req, res) => {
try {
const deviceId = req.query.device_id;
const userDeviceInfoData = await QrCodeAuthModel.retrieveUserDeviceInfo(deviceId);
const { device_id: deviceId } = req.query;
const userDeviceInfoData = await QrCodeAuthModel.retrieveUserDeviceInfo({ deviceId });
if (!userDeviceInfoData.userExists) {
return res.boom.notFound(`User with id ${deviceId} does not exist.`);
}
Expand All @@ -166,11 +174,29 @@ const fetchUserDeviceInfo = async (req, res) => {
}
};

const fetchDeviceDetails = async (req, res) => {
try {
const userId = req.userData.id;
const userDeviceInfoData = await QrCodeAuthModel.retrieveUserDeviceInfo({ userId });
if (!userDeviceInfoData.userExists) {
return res.boom.notFound(`User with id ${userId} does not exist.`);
}
return res.json({
message: "Authentication document Exists",
data: { device_info: userDeviceInfoData.data?.device_info },
});
} catch (error) {
logger.error(`Error while fetching user device info: ${error}`);
return res.boom.badImplementation(SOMETHING_WENT_WRONG);
}
};

module.exports = {
githubAuthLogin,
githubAuthCallback,
signout,
storeUserDeviceInfo,
updateAuthStatus,
fetchUserDeviceInfo,
fetchDeviceDetails,
};
19 changes: 18 additions & 1 deletion controllers/discordactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const admin = require("firebase-admin");
const config = require("config");
const jwt = require("jsonwebtoken");
const discordRolesModel = require("../models/discordactions");
const { retrieveUsers } = require("../services/dataAccessLayer");

/**
* Creates a role
Expand Down Expand Up @@ -66,9 +67,25 @@ const createGroupRole = async (req, res) => {
const getAllGroupRoles = async (req, res) => {
try {
const { groups } = await discordRolesModel.getAllGroupRoles();
const groupsWithMemberCount = await discordRolesModel.getNumberOfMemberForGroups(groups);
const groupCreatorIds = groupsWithMemberCount.reduce((ids, group) => {
ids.add(group.createdBy);
return ids;
}, new Set());
const groupCreatorsDetails = await retrieveUsers({ userIds: Array.from(groupCreatorIds) });
const groupsWithUserDetails = groupsWithMemberCount.map((group) => {
const groupCreator = groupCreatorsDetails[group.createdBy];
return {
...group,
firstName: groupCreator.first_name,
lastName: groupCreator.last_name,
image: groupCreator.picture?.url,
};
});

return res.json({
message: "Roles fetched successfully!",
groups,
groups: groupsWithUserDetails,
});
} catch (err) {
logger.error(`Error while getting roles: ${err}`);
Expand Down
74 changes: 71 additions & 3 deletions controllers/events.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* eslint-disable camelcase */
const { GET_ALL_EVENTS_LIMIT_MIN, UNWANTED_PROPERTIES_FROM_100MS } = require("../constants/events");
const { INTERNAL_SERVER_ERROR } = require("../constants/errorMessages");

const { EventTokenService, EventAPIService } = require("../services");
const { removeUnwantedProperties } = require("../utils/events");
const eventQuery = require("../models/events");

const logger = require("../utils/logger");
const { removeUnwantedProperties } = require("../utils/events");

const tokenService = new EventTokenService();
const apiService = new EventAPIService(tokenService);
Expand Down Expand Up @@ -100,7 +102,7 @@ const joinEvent = async (req, res) => {
});
} catch (error) {
logger.error({ error });
return res.status(500).send("Internal Server Error");
return res.boom.badImplementation(INTERNAL_SERVER_ERROR);
}
};

Expand Down Expand Up @@ -193,11 +195,77 @@ const endActiveEvent = async (req, res) => {
}
};

/**
* Adds a peer to an event.
*
* @async
* @function
* @param {Object} req - The Express request object.
* @param {Object} res - The Express response object.
* @returns {Promise<Object>} The JSON response with the added peer data and a success message.
* @throws {Object} The JSON response with an error message if an error occurred while adding the peer.
*/
const addPeerToEvent = async (req, res) => {
try {
const data = await eventQuery.addPeerToEvent({
peerId: req.body.peerId,
name: req.body.name,
role: req.body.role,
joinedAt: req.body.joinedAt,
eventId: req.params.id,
});
return res.status(200).json({
data,
message: `Selected Participant is added to the event.`,
});
} catch (error) {
logger.error({ error });
return res.status(500).json({
error: error.code,
message: "You can't add selected Participant. Please ask Admin or Host for help.",
});
}
};

/**
* Kicks out a peer from an event.
*
* @async
* @function
* @param {Object} req - The Express request object.
* @param {Object} res - The Express response object.
* @returns {Promise<Object>} The JSON response with a success message if the peer is successfully kicked out.
* @throws {Object} The JSON response with an error message if an error occurred while kicking out the peer.
*/
const kickoutPeer = async (req, res) => {
const { id } = req.params;
const payload = {
peer_id: req.body.peerId,
reason: req.body.reason,
};

try {
await apiService.post(`/active-rooms/${id}/remove-peers`, payload);
await eventQuery.kickoutPeer({ eventId: id, peerId: payload.peer_id, reason: req.body.reason });
return res.status(200).json({
message: `Selected Participant is removed from event.`,
});
} catch (error) {
logger.error({ error });
return res.status(500).json({
error: error.code,
message: "You can't remove selected Participant from Remove, Please ask Admin or Host for help.",
});
}
};

module.exports = {
createEvent,
getAllEvents,
joinEvent,
getEventById,
updateEvent,
endActiveEvent,
addPeerToEvent,
kickoutPeer,
};
17 changes: 14 additions & 3 deletions controllers/extensionRequests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const extensionRequestsQuery = require("../models/extensionRequests");
const { addLog } = require("../models/logs");
const tasks = require("../models/tasks");
const { getUsername } = require("../utils/users");
const { getUsername, getUsernameElseUndefined, getUserIdElseUndefined } = require("../utils/users");
const { EXTENSION_REQUEST_STATUS } = require("../constants/extensionRequests");
const { INTERNAL_SERVER_ERROR } = require("../constants/errorMessages");
/**
Expand All @@ -14,11 +14,22 @@ const createTaskExtensionRequest = async (req, res) => {
try {
const extensionBody = req.body;

let assigneeUsername = await getUsernameElseUndefined(extensionBody.assignee);
let assigneeId = extensionBody.assignee;
if (!assigneeUsername) {
assigneeId = await getUserIdElseUndefined(extensionBody.assignee);
assigneeUsername = extensionBody.assignee;
extensionBody.assignee = assigneeId;
}

if (!assigneeId) {
return res.boom.badRequest("User with this id or username doesn't exist.");
}

if (req.userData.id !== extensionBody.assignee && !req.userData.roles?.super_user) {
return res.boom.forbidden("Only Super User can create an extension request for this task.");
return res.boom.forbidden("Only assigned user and super user can create an extension request for this task.");
}

const assigneeUsername = await getUsername(extensionBody.assignee);
const { taskData: task } = await tasks.fetchTask(extensionBody.taskId);
if (!task) {
return res.boom.badRequest("Task with this id or taskid doesn't exist.");
Expand Down
21 changes: 19 additions & 2 deletions controllers/members.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const ROLES = require("../constants/roles");
const members = require("../models/members");
const tasks = require("../models/tasks");
const { SOMETHING_WENT_WRONG } = require("../constants/errorMessages");
const { SOMETHING_WENT_WRONG, INTERNAL_SERVER_ERROR } = require("../constants/errorMessages");
const dataAccess = require("../services/dataAccessLayer");
const { addLog } = require("../models/logs");
/**
* Fetches the data about our members
*
Expand Down Expand Up @@ -83,17 +84,33 @@ const archiveMembers = async (req, res) => {
try {
const { username } = req.params;
const user = await dataAccess.retrieveUsers({ username });
const superUserId = req.userData.id;
const { reason } = req.body;
const roles = req?.userData?.roles;
if (user?.userExists) {
const successObject = await members.addArchiveRoleToMembers(user.user.id);
if (successObject.isArchived) {
return res.boom.badRequest("User is already archived");
}
const body = {
reason: reason || "",
archived_user: {
user_id: user.user.id,
username: user.user.username,
},
archived_by: {
user_id: superUserId,
roles: roles,
},
};

addLog("archived-details", {}, body);
return res.status(204).send();
}
return res.boom.notFound("User doesn't exist");
} catch (err) {
logger.error(`Error while retriving contributions ${err}`);
return res.boom.badImplementation(SOMETHING_WENT_WRONG);
return res.boom.badImplementation(INTERNAL_SERVER_ERROR);
}
};

Expand Down
Loading