Skip to content

Commit e16e29d

Browse files
authored
Merge branch 'develop' into feat/user-status-sync
2 parents beac0a5 + a4551b1 commit e16e29d

File tree

17 files changed

+359
-56
lines changed

17 files changed

+359
-56
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ yarn install --frozen-lockfile
5151

5252
This command should be successful, before moving to development.
5353

54+
5455
```shell
5556
yarn validate-setup
5657
```

constants/logs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const logType = {
1212
EXTERNAL_SERVICE: "EXTERNAL_SERVICE",
1313
EXTENSION_REQUESTS: "extensionRequests",
1414
TASK: "task",
15+
TASK_REQUESTS: "taskRequests",
1516
...REQUEST_LOG_TYPE,
1617
};
1718

controllers/auth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const githubAuthCallback = (req, res, next) => {
8080
github_created_at: Number(new Date(user._json.created_at).getTime()),
8181
github_user_id: user.id,
8282
created_at: Date.now(),
83-
updated_at: Date.now(),
83+
updated_at: null,
8484
};
8585

8686
const { userId, incompleteUserDetails, role } = await users.addOrUpdate(userData);

controllers/staging.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const updateRoles = async (req, res) => {
1515
...userData.roles,
1616
...req.body,
1717
},
18+
updated_at: Date.now(),
1819
},
1920
userId
2021
);
@@ -48,6 +49,7 @@ const removePrivileges = async (req, res) => {
4849
...member.roles,
4950
member: false,
5051
},
52+
updated_at: Date.now(),
5153
},
5254
member.id
5355
)
@@ -61,6 +63,7 @@ const removePrivileges = async (req, res) => {
6163
...superUser.roles,
6264
super_user: false,
6365
},
66+
updated_at: Date.now(),
6467
},
6568
superUser.id
6669
)

middlewares/validators/task-requests.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const postTaskRequests = async (req, res, next) => {
2020
proposedStartDate: joi.number().required(),
2121
proposedDeadline: joi.number().required(),
2222
description: joi.string().optional(),
23+
markdownEnabled: joi.boolean().optional(),
2324
});
2425

2526
const taskCreationSchema = joi
@@ -33,6 +34,7 @@ const postTaskRequests = async (req, res, next) => {
3334
proposedStartDate: joi.number().required(),
3435
proposedDeadline: joi.number().required(),
3536
description: joi.string().optional(),
37+
markdownEnabled: joi.boolean().optional(),
3638
});
3739
const schema = joi.alternatives().try(taskAssignmentSchema, taskCreationSchema);
3840

models/logs.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ const admin = require("firebase-admin");
55
const { logType, ERROR_WHILE_FETCHING_LOGS } = require("../constants/logs");
66
const { INTERNAL_SERVER_ERROR } = require("../constants/errorMessages");
77
const { getFullName } = require("../utils/users");
8-
const { getUsersListFromLogs, formatLogsForFeed, mapify, convertTimestamp } = require("../utils/logs");
8+
const {
9+
getUsersListFromLogs,
10+
formatLogsForFeed,
11+
mapify,
12+
convertTimestamp,
13+
getTasksFromLogs,
14+
} = require("../utils/logs");
915
const SIZE = 25;
1016

1117
/**
@@ -205,16 +211,22 @@ const fetchAllLogs = async (query) => {
205211
allLogs.push({ ...doc.data() });
206212
});
207213
}
208-
const userList = await getUsersListFromLogs(allLogs);
209-
const usersMap = mapify(userList, "id");
210-
211214
if (allLogs.length === 0) {
212-
return [];
215+
return {
216+
allLogs: [],
217+
prev: null,
218+
next: null,
219+
page: page ? page + 1 : null,
220+
};
213221
}
214222
if (format === "feed") {
215223
let logsData = [];
224+
const userList = await getUsersListFromLogs(allLogs);
225+
const taskIdList = await getTasksFromLogs(allLogs);
226+
const usersMap = mapify(userList, "id");
227+
const tasksMap = mapify(taskIdList, "id");
216228
logsData = allLogs.map((data) => {
217-
const formattedLogs = formatLogsForFeed(data, usersMap);
229+
const formattedLogs = formatLogsForFeed(data, usersMap, tasksMap);
218230
if (!Object.keys(formattedLogs).length) return null;
219231
return { ...formattedLogs, type: data.type, timestamp: convertTimestamp(data.timestamp) };
220232
});

models/members.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const moveToMembers = async (userId) => {
5454
const roles = user.roles ? { ...user.roles, member: true } : { member: true };
5555
await userModel.doc(userId).update({
5656
roles,
57+
updated_at: Date.now(),
5758
});
5859
return { isAlreadyMember: false, movedToMember: true };
5960
} catch (err) {
@@ -101,6 +102,7 @@ const addArchiveRoleToMembers = async (userId) => {
101102
const roles = { ...user.roles, [ROLES.ARCHIVED]: true };
102103
await userModel.doc(userId).update({
103104
roles,
105+
updated_at: Date.now(),
104106
});
105107
return { isArchived: false };
106108
} catch (err) {

models/taskRequests.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ const fetchTaskRequestById = async (taskRequestId) => {
196196
* @param {string} data.proposedDeadline - The proposed deadline for the task.
197197
* @param {string} data.proposedStartDate - The proposed start date for the task.
198198
* @param {string} data.description - The description of the task request.
199+
* @param {string} data.markdownEnabled - If markdown is enabled in task request's description.
199200
* @param {string} data.taskTitle - The title of the task.
200201
* @param {string} data.taskId - The ID of the task (optional).
201202
* @param {string} data.externalIssueUrl - The external issue URL (optional).
@@ -239,6 +240,7 @@ const createRequest = async (data, authorUserId) => {
239240
proposedDeadline: data.proposedDeadline,
240241
proposedStartDate: data.proposedStartDate,
241242
description: data.description,
243+
markdownEnabled: data?.markdownEnabled ?? false,
242244
status: TASK_REQUEST_STATUS.PENDING,
243245
};
244246
if (!userRequest.description) delete userRequest.description;

models/users.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const addOrUpdate = async (userData, userId = null) => {
6161
user = await userModel.where("github_id", "==", userData.github_id).limit(1).get();
6262
}
6363
if (user && !user.empty && user.docs !== null) {
64-
await userModel.doc(user.docs[0].id).set(userData, { merge: true });
64+
await userModel.doc(user.docs[0].id).set({ ...userData, updated_at: Date.now() }, { merge: true });
6565
const data = user.docs[0].data();
6666
return {
6767
isNewUser: false,
@@ -308,6 +308,7 @@ const setIncompleteUserDetails = async (userId) => {
308308
if (doc.exists) {
309309
return userRef.update({
310310
incompleteUserDetails: false,
311+
updated_at: Date.now(),
311312
});
312313
}
313314
return {};
@@ -423,6 +424,7 @@ const updateUserPicture = async (image, userId) => {
423424
const userDoc = userModel.doc(userId);
424425
await userDoc.update({
425426
picture: image,
427+
updated_at: Date.now(),
426428
});
427429
} catch (err) {
428430
logger.error("Error updating user picture data", err);
@@ -788,7 +790,7 @@ const updateUsersInBatch = async (usersData) => {
788790
usersData.forEach((user) => {
789791
const id = user.id;
790792
delete user.id;
791-
bulkWriter.update(userModel.doc(id), user);
793+
bulkWriter.update(userModel.doc(id), { ...user, updated_at: Date.now() });
792794
});
793795

794796
await bulkWriter.close();
@@ -913,7 +915,7 @@ const addGithubUserId = async (page, size) => {
913915
})
914916
.then((data) => {
915917
const githubUserId = data.id;
916-
batchWrite.update(userDoc.ref, { github_user_id: `${githubUserId}` });
918+
batchWrite.update(userDoc.ref, { github_user_id: `${githubUserId}`, updated_at: Date.now() });
917919
countUserFound++;
918920
})
919921
.catch((error) => {

routes/discordactions.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ router.put(
5959
router.post(
6060
"/nicknames/sync",
6161
authorizeAndAuthenticate([ROLES.SUPERUSER], [Services.CRON_JOB_HANDLER]),
62-
checkIsVerifiedDiscord,
6362
updateDiscordNicknames
6463
);
6564
router.post("/nickname/status", verifyCronJob, validateUpdateUsersNicknameStatusBody, updateUsersNicknameStatus);

0 commit comments

Comments
 (0)