Skip to content

Commit

Permalink
Merge branch 'develop' into feat/add-backlog-orphan-tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
MehulKChaudhari committed Apr 2, 2024
2 parents e5117ec + a4551b1 commit df1368c
Show file tree
Hide file tree
Showing 17 changed files with 359 additions and 56 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ yarn install --frozen-lockfile

This command should be successful, before moving to development.


```shell
yarn validate-setup
```
Expand Down
1 change: 1 addition & 0 deletions constants/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const logType = {
EXTERNAL_SERVICE: "EXTERNAL_SERVICE",
EXTENSION_REQUESTS: "extensionRequests",
TASK: "task",
TASK_REQUESTS: "taskRequests",
...REQUEST_LOG_TYPE,
};

Expand Down
2 changes: 1 addition & 1 deletion controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const githubAuthCallback = (req, res, next) => {
github_created_at: Number(new Date(user._json.created_at).getTime()),
github_user_id: user.id,
created_at: Date.now(),
updated_at: Date.now(),
updated_at: null,
};

const { userId, incompleteUserDetails, role } = await users.addOrUpdate(userData);
Expand Down
3 changes: 3 additions & 0 deletions controllers/staging.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const updateRoles = async (req, res) => {
...userData.roles,
...req.body,
},
updated_at: Date.now(),
},
userId
);
Expand Down Expand Up @@ -48,6 +49,7 @@ const removePrivileges = async (req, res) => {
...member.roles,
member: false,
},
updated_at: Date.now(),
},
member.id
)
Expand All @@ -61,6 +63,7 @@ const removePrivileges = async (req, res) => {
...superUser.roles,
super_user: false,
},
updated_at: Date.now(),
},
superUser.id
)
Expand Down
2 changes: 2 additions & 0 deletions middlewares/validators/task-requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const postTaskRequests = async (req, res, next) => {
proposedStartDate: joi.number().required(),
proposedDeadline: joi.number().required(),
description: joi.string().optional(),
markdownEnabled: joi.boolean().optional(),
});

const taskCreationSchema = joi
Expand All @@ -33,6 +34,7 @@ const postTaskRequests = async (req, res, next) => {
proposedStartDate: joi.number().required(),
proposedDeadline: joi.number().required(),
description: joi.string().optional(),
markdownEnabled: joi.boolean().optional(),
});
const schema = joi.alternatives().try(taskAssignmentSchema, taskCreationSchema);

Expand Down
24 changes: 18 additions & 6 deletions models/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ const admin = require("firebase-admin");
const { logType, ERROR_WHILE_FETCHING_LOGS } = require("../constants/logs");
const { INTERNAL_SERVER_ERROR } = require("../constants/errorMessages");
const { getFullName } = require("../utils/users");
const { getUsersListFromLogs, formatLogsForFeed, mapify, convertTimestamp } = require("../utils/logs");
const {
getUsersListFromLogs,
formatLogsForFeed,
mapify,
convertTimestamp,
getTasksFromLogs,
} = require("../utils/logs");
const SIZE = 25;

/**
Expand Down Expand Up @@ -205,16 +211,22 @@ const fetchAllLogs = async (query) => {
allLogs.push({ ...doc.data() });
});
}
const userList = await getUsersListFromLogs(allLogs);
const usersMap = mapify(userList, "id");

if (allLogs.length === 0) {
return [];
return {
allLogs: [],
prev: null,
next: null,
page: page ? page + 1 : null,
};
}
if (format === "feed") {
let logsData = [];
const userList = await getUsersListFromLogs(allLogs);
const taskIdList = await getTasksFromLogs(allLogs);
const usersMap = mapify(userList, "id");
const tasksMap = mapify(taskIdList, "id");
logsData = allLogs.map((data) => {
const formattedLogs = formatLogsForFeed(data, usersMap);
const formattedLogs = formatLogsForFeed(data, usersMap, tasksMap);
if (!Object.keys(formattedLogs).length) return null;
return { ...formattedLogs, type: data.type, timestamp: convertTimestamp(data.timestamp) };
});
Expand Down
2 changes: 2 additions & 0 deletions models/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const moveToMembers = async (userId) => {
const roles = user.roles ? { ...user.roles, member: true } : { member: true };
await userModel.doc(userId).update({
roles,
updated_at: Date.now(),
});
return { isAlreadyMember: false, movedToMember: true };
} catch (err) {
Expand Down Expand Up @@ -101,6 +102,7 @@ const addArchiveRoleToMembers = async (userId) => {
const roles = { ...user.roles, [ROLES.ARCHIVED]: true };
await userModel.doc(userId).update({
roles,
updated_at: Date.now(),
});
return { isArchived: false };
} catch (err) {
Expand Down
2 changes: 2 additions & 0 deletions models/taskRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ const fetchTaskRequestById = async (taskRequestId) => {
* @param {string} data.proposedDeadline - The proposed deadline for the task.
* @param {string} data.proposedStartDate - The proposed start date for the task.
* @param {string} data.description - The description of the task request.
* @param {string} data.markdownEnabled - If markdown is enabled in task request's description.
* @param {string} data.taskTitle - The title of the task.
* @param {string} data.taskId - The ID of the task (optional).
* @param {string} data.externalIssueUrl - The external issue URL (optional).
Expand Down Expand Up @@ -239,6 +240,7 @@ const createRequest = async (data, authorUserId) => {
proposedDeadline: data.proposedDeadline,
proposedStartDate: data.proposedStartDate,
description: data.description,
markdownEnabled: data?.markdownEnabled ?? false,
status: TASK_REQUEST_STATUS.PENDING,
};
if (!userRequest.description) delete userRequest.description;
Expand Down
8 changes: 5 additions & 3 deletions models/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const addOrUpdate = async (userData, userId = null) => {
user = await userModel.where("github_id", "==", userData.github_id).limit(1).get();
}
if (user && !user.empty && user.docs !== null) {
await userModel.doc(user.docs[0].id).set(userData, { merge: true });
await userModel.doc(user.docs[0].id).set({ ...userData, updated_at: Date.now() }, { merge: true });
const data = user.docs[0].data();
return {
isNewUser: false,
Expand Down Expand Up @@ -308,6 +308,7 @@ const setIncompleteUserDetails = async (userId) => {
if (doc.exists) {
return userRef.update({
incompleteUserDetails: false,
updated_at: Date.now(),
});
}
return {};
Expand Down Expand Up @@ -423,6 +424,7 @@ const updateUserPicture = async (image, userId) => {
const userDoc = userModel.doc(userId);
await userDoc.update({
picture: image,
updated_at: Date.now(),
});
} catch (err) {
logger.error("Error updating user picture data", err);
Expand Down Expand Up @@ -788,7 +790,7 @@ const updateUsersInBatch = async (usersData) => {
usersData.forEach((user) => {
const id = user.id;
delete user.id;
bulkWriter.update(userModel.doc(id), user);
bulkWriter.update(userModel.doc(id), { ...user, updated_at: Date.now() });
});

await bulkWriter.close();
Expand Down Expand Up @@ -913,7 +915,7 @@ const addGithubUserId = async (page, size) => {
})
.then((data) => {
const githubUserId = data.id;
batchWrite.update(userDoc.ref, { github_user_id: `${githubUserId}` });
batchWrite.update(userDoc.ref, { github_user_id: `${githubUserId}`, updated_at: Date.now() });
countUserFound++;
})
.catch((error) => {
Expand Down
1 change: 0 additions & 1 deletion routes/discordactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ router.put(
router.post(
"/nicknames/sync",
authorizeAndAuthenticate([ROLES.SUPERUSER], [Services.CRON_JOB_HANDLER]),
checkIsVerifiedDiscord,
updateDiscordNicknames
);
router.post("/nickname/status", verifyCronJob, validateUpdateUsersNicknameStatusBody, updateUsersNicknameStatus);
Expand Down
1 change: 1 addition & 0 deletions services/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const archiveUsers = async (usersData) => {
...user.roles,
archived: true,
},
updated_at: Date.now(),
};
batch.update(userModel.doc(id), updatedUserData);
usersBatch.push({ id, firstName, lastName });
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/task-requests/task-requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const taskRequestData = {
requestType: TASK_REQUEST_TYPE.CREATION,
externalIssueUrl: "https://api.github.com/repos/Real-Dev-Squad/website-backend/issues/1599",
externalIssueHtmlUrl: "https://github.com/Real-Dev-Squad/website-backend/issues/1599",
markdownEnabled: false,
};
const existingTaskRequest = {
requestors: ["user123"],
Expand All @@ -49,6 +50,7 @@ const existingTaskRequest = {
users: [
{
userId: "user123",
markdownEnabled: false,
proposedDeadline: 1697452226789,
proposedStartDate: 1697452226789,
description: "Task description",
Expand Down
8 changes: 5 additions & 3 deletions test/integration/logs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ describe("/logs", function () {
expect(res.body.message).to.equal("All Logs fetched successfully");
expect(res.body.data).to.lengthOf(7);
expect(res.body.data[0]).to.contain({
user: "joygupta",
username: "joygupta",
taskTitle: "Untitled Task",
taskId: "mZB0akqPUa1GQQdrgsx7",
extensionRequestId: "y79PXir0s82qNAzeIn8S",
status: "PENDING",
Expand Down Expand Up @@ -170,7 +171,7 @@ describe("/logs", function () {
});
});

it("should return 204, if no logs are present", function (done) {
it("if no logs are present, should return valid response", function (done) {
chai
.request(app)
.get("/logs?type=REQUEST_CREATED1&dev=true")
Expand All @@ -179,7 +180,8 @@ describe("/logs", function () {
if (err) {
return done(err);
}
expect(res).to.have.status(204);
expect(res).to.have.status(200);
expect(res.body.data).to.have.lengthOf(0);
return done();
});
});
Expand Down
8 changes: 7 additions & 1 deletion test/unit/models/logs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const cookieName = config.get("userToken.cookieName");
const authService = require("../../../services/authService");
const { extensionRequestLogs } = require("../../fixtures/logs/extensionRequests");
const { LOGS_FETCHED_SUCCESSFULLY } = require("../../../constants/logs");
const tasks = require("../../../models/tasks");
const tasksData = require("../../fixtures/tasks/tasks")();
chai.use(chaiHttp);
const superUser = userData[4];
const userToBeMadeMember = userData[1];
Expand Down Expand Up @@ -133,6 +135,10 @@ describe("Logs", function () {
describe("GET /logs", function () {
before(async function () {
await addLogs();
const tasksPromise = tasksData.map(async (task) => {
await tasks.updateTask(task);
});
await Promise.all(tasksPromise);
});

after(async function () {
Expand Down Expand Up @@ -195,7 +201,7 @@ describe("Logs", function () {
it("Should return null if no logs are presnet the logs for specific types", async function () {
await cleanDb();
const result = await logsQuery.fetchAllLogs({});
expect(result).to.lengthOf(0);
expect(result.allLogs).to.lengthOf(0);
});

it("should throw an error and log it", async function () {
Expand Down
4 changes: 4 additions & 0 deletions test/unit/models/task-requests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe("Task requests | models", function () {
proposedStartDate: requestData.proposedStartDate,
status: TASK_REQUEST_STATUS.PENDING,
description: requestData.description,
markdownEnabled: requestData.markdownEnabled,
},
]);
expect(addedTaskRequest.createdBy).to.equal(authenticatedUsername);
Expand Down Expand Up @@ -89,6 +90,7 @@ describe("Task requests | models", function () {
proposedStartDate: requestData.proposedStartDate,
status: TASK_REQUEST_STATUS.PENDING,
description: requestData.description,
markdownEnabled: requestData.markdownEnabled,
},
]);
expect(addedTaskRequest.createdBy).to.equal(mockData.existingTaskRequest.createdBy);
Expand Down Expand Up @@ -124,6 +126,7 @@ describe("Task requests | models", function () {
proposedStartDate: requestData.proposedStartDate,
status: TASK_REQUEST_STATUS.PENDING,
description: requestData.description,
markdownEnabled: requestData.markdownEnabled,
},
]);
expect(addedTaskRequest.createdBy).to.equal(authenticatedUsername);
Expand Down Expand Up @@ -163,6 +166,7 @@ describe("Task requests | models", function () {
proposedStartDate: requestData.proposedStartDate,
status: TASK_REQUEST_STATUS.PENDING,
description: requestData.description,
markdownEnabled: requestData.markdownEnabled,
},
]);
expect(addedTaskRequest.createdBy).to.equal(mockData.existingTaskRequest.createdBy);
Expand Down
Loading

0 comments on commit df1368c

Please sign in to comment.