Skip to content

Commit 30276ee

Browse files
Merge pull request #1656 from Real-Dev-Squad/develop
Dev to main sync
2 parents 7b2d558 + 1e56e72 commit 30276ee

26 files changed

+618
-332
lines changed

config/custom-environment-variables.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ module.exports = {
4545
},
4646
},
4747

48+
goalAPI: {
49+
baseUrl: "GOALS_BASE_URL",
50+
secretKey: "GOALS_SECRET_KEY",
51+
},
52+
4853
discordBot: {
4954
baseUrl: "DISCORD_BASE_URL",
5055
},

config/default.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ module.exports = {
4848
authRedirection: "/goto",
4949
},
5050
goalAPI: {
51-
baseUrl: "",
52-
secretKey: "",
53-
cookieName: "",
51+
baseUrl: "https://goal-api.realdevsquad.com",
52+
secretKey: "<goalSecretKey>",
53+
cookieName: `goals-session-${NODE_ENV}`,
5454
},
5555
},
5656
discordBot: {

config/development.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ module.exports = {
2424
},
2525

2626
goalAPI: {
27-
baseUrl: "",
28-
secretKey: "",
29-
cookieName: "",
27+
baseUrl: "https://backend-goals-production.up.railway.app",
28+
secretKey: "123456789",
3029
},
3130
},
3231

config/staging.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ module.exports = {
1818
baseUrl: "https://staging-api.realdevsquad.com",
1919
},
2020
goalAPI: {
21-
baseUrl: "",
22-
secretKey: "",
23-
cookieName: "",
21+
baseUrl: "https://backend-goals-production.up.railway.app",
22+
secretKey: "123456789",
2423
},
2524
},
2625

config/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ module.exports = {
3636
baseUrl: "DISCORD_BASE_URL",
3737
},
3838
goalAPI: {
39-
baseUrl: "https://goals-api.realdevsquad.com",
40-
secretKey: "123456789",
41-
cookieName: "goals_session",
39+
baseUrl: "<goalBaseUrl>",
40+
secretKey: "<goalSecretKey>",
41+
cookieName: `goals-session-test`,
4242
},
4343
},
4444

controllers/events.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,15 @@ const kickoutPeer = async (req, res) => {
296296
};
297297

298298
try {
299+
const peer = await eventQuery.getPeerById(payload.peer_id);
299300
await apiService.post(`/active-rooms/${id}/remove-peers`, payload);
300301
await eventQuery.kickoutPeer({ eventId: id, peerId: payload.peer_id, reason: req.body.reason });
301-
addLog(logType.EVENTS_REMOVE_PEER, { removed_by: req.userData.id }, payload);
302+
addLog(
303+
logType.EVENTS_REMOVE_PEER,
304+
{ removed_by_id: req.userData.id, removed_by_username: req.userData.username },
305+
{ ...payload, event_id: id, peer_name: peer.name }
306+
);
307+
302308
return res.status(200).json({
303309
message: `Selected Participant is removed from event.`,
304310
});

controllers/tasksRequests.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { INTERNAL_SERVER_ERROR, SOMETHING_WENT_WRONG } = require("../constants/errorMessages");
22
const { TASK_REQUEST_TYPE } = require("../constants/taskRequests");
3+
const { addLog } = require("../models/logs");
34
const taskRequestsModel = require("../models/taskRequests");
45
const tasksModel = require("../models/tasks.js");
56
const { updateUserStatusOnTaskUpdate } = require("../models/userStatus");
@@ -95,12 +96,28 @@ const addTaskRequests = async (req, res) => {
9596
}
9697
}
9798
const newTaskRequest = await taskRequestsModel.createRequest(taskRequestData, req.userData.username);
99+
98100
if (newTaskRequest.isCreationRequestApproved) {
99101
return res.boom.conflict("Task exists for the given issue.");
100102
}
101103
if (newTaskRequest.alreadyRequesting) {
102104
return res.boom.badRequest("Task was already requested");
103105
}
106+
107+
const taskRequestLog = {
108+
type: "taskRequests",
109+
meta: {
110+
taskRequestId: newTaskRequest.id,
111+
action: "create",
112+
createdBy: req.userData.username,
113+
createdAt: Date.now(),
114+
lastModifiedBy: req.userData.username,
115+
lastModifiedAt: Date.now(),
116+
},
117+
body: newTaskRequest.taskRequest,
118+
};
119+
await addLog(taskRequestLog.type, taskRequestLog.meta, taskRequestLog.body);
120+
104121
const statusCode = newTaskRequest.isCreate ? 201 : 200;
105122
return res.status(statusCode).json({
106123
message: "Task request successful.",
@@ -168,8 +185,24 @@ const approveTaskRequest = async (req, res) => {
168185
if (response.isTaskRequestInvalid) {
169186
return res.boom.badRequest("Task request was previously approved or rejected.");
170187
}
188+
171189
await updateUserStatusOnTaskUpdate(user.username);
172190

191+
const taskRequestLog = {
192+
type: "taskRequests",
193+
meta: {
194+
taskRequestId: taskRequestId,
195+
action: "update",
196+
subAction: "approve",
197+
createdBy: req.userData.username,
198+
createdAt: Date.now(),
199+
lastModifiedBy: req.userData.username,
200+
lastModifiedAt: Date.now(),
201+
},
202+
body: response.taskRequest,
203+
};
204+
await addLog(taskRequestLog.type, taskRequestLog.meta, taskRequestLog.body);
205+
173206
return res.status(200).json({
174207
message: `Task successfully assigned to user ${response.approvedTo}`,
175208
taskRequest: response.taskRequest,

controllers/users.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const { getPaginationLink, getUsernamesFromPRs, getRoleToUpdate } = require("../
1515
const { setInDiscordFalseScript, setUserDiscordNickname } = require("../services/discordService");
1616
const { generateDiscordProfileImageUrl } = require("../utils/discord-actions");
1717
const { addRoleToUser, getDiscordMembers } = require("../services/discordService");
18-
const { fetchAllUsers, fetchUser } = require("../models/users");
18+
const { fetchAllUsers } = require("../models/users");
1919
const { getOverdueTasks } = require("../models/tasks");
2020
const { getQualifiers } = require("../utils/helper");
2121
const { parseSearchQuery } = require("../utils/users");
@@ -174,33 +174,36 @@ const getUsers = async (req, res) => {
174174
if (transformedQuery?.filterBy === OVERDUE_TASKS) {
175175
try {
176176
const tasksData = await getOverdueTasks(days);
177+
if (!tasksData.length) {
178+
return res.json({
179+
message: "No users found",
180+
users: [],
181+
});
182+
}
177183
const userIds = new Set();
178184
const usersData = [];
179185

180186
tasksData.forEach((task) => {
181-
userIds.add(task.assignee);
187+
if (task.assignee) {
188+
userIds.add(task.assignee);
189+
}
182190
});
183191

184-
for (const userId of Array.from(userIds)) {
185-
const userInfo = await fetchUser({ userId });
186-
187-
if (userInfo) {
188-
const userTasks = tasksData.filter((task) => task.assignee === userId);
192+
const userInfo = await dataAccess.retrieveUsers({ userIds: Array.from(userIds) });
193+
userInfo.forEach((user) => {
194+
if (!user.roles.archived) {
195+
const userTasks = tasksData.filter((task) => task.assignee === user.id);
189196
const userData = {
190-
id: userId,
191-
discordId: userInfo.user.discordId,
192-
username: userInfo.user.username,
197+
id: user.id,
198+
discordId: user.discordId,
199+
username: user.username,
193200
};
194-
195201
if (dev) {
196202
userData.tasks = userTasks;
197203
}
198-
199-
if (userInfo.user.roles.in_discord) {
200-
usersData.push(userData);
201-
}
204+
usersData.push(userData);
202205
}
203-
}
206+
});
204207

205208
return res.json({
206209
message: "Users returned successfully!",

middlewares/validators/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const updateUser = async (req, res, next) => {
2222
.optional()
2323
.min(4)
2424
.max(20)
25-
.regex(/^[a-zA-Z0-9]+$/)
25+
.regex(/^[a-zA-Z0-9-]+$/)
2626
.message("Username must be between 4 and 20 characters long and contain only letters or numbers."),
2727
first_name: joi.string().optional(),
2828
last_name: joi.string().optional(),

models/discordactions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ const enrichGroupDataWithMembershipInfo = async (discordId, groups = []) => {
246246
const subscribedGroupIds = findSubscribedGroupIds(discordId, groupsToUserMappings);
247247

248248
return groups.map((group) => {
249-
const groupCreator = groupCreatorsDetails[group.createdBy];
249+
const groupCreator = groupCreatorsDetails.find((user) => user.id === group.createdBy);
250250
return {
251251
...group,
252252
firstName: groupCreator?.first_name,

0 commit comments

Comments
 (0)