Skip to content

Commit c9cdd75

Browse files
Merge pull request #1786 from Real-Dev-Squad/develop
Dev to Main Sync
2 parents be557ce + 639ca1d commit c9cdd75

18 files changed

Lines changed: 834 additions & 34 deletions

File tree

config/default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = {
1414
discordUnverifiedRoleId: "<discordUnverifiedRoleId>",
1515
discordDeveloperRoleId: "<discordDeveloperRoleId>",
1616
discordMavenRoleId: "<discordMavenRoleId>",
17+
discordMissedUpdatesRoleId: "<discordMissedUpdatesRoleId>",
1718
githubApi: {
1819
baseUrl: "https://api.github.com",
1920
org: "Real-Dev-Squad",

config/production.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = {
66
discordUnverifiedRoleId: "1103047289330745386",
77
discordDeveloperRoleId: "915490782939582485",
88
discordMavenRoleId: "875564640438997043",
9+
discordMissedUpdatesRoleId: "1183553844811153458",
910
userToken: {
1011
cookieName: "rds-session",
1112
},

config/staging.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = {
66
discordUnverifiedRoleId: "1120875993771544687",
77
discordDeveloperRoleId: "1121445071213056071",
88
discordMavenRoleId: "1152361736456896586",
9+
discordMissedUpdatesRoleId: "1184201657404362772",
910
enableFileLogs: false,
1011
enableConsoleLogs: true,
1112

constants/constants.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
const DOCUMENT_WRITE_SIZE = 500;
2+
const daysOfWeek = {
3+
sun: 0,
4+
mon: 1,
5+
tue: 2,
6+
wed: 3,
7+
thu: 4,
8+
fri: 5,
9+
sat: 6,
10+
};
211

312
module.exports = {
4-
DOCUMENT_WRITE_SIZE,
13+
DOCUMENT_WRITE_SIZE,
14+
daysOfWeek,
515
};

constants/tasks.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ const MAPPED_TASK_STATUS = {
3737
UNASSIGNED: "AVAILABLE",
3838
};
3939

40+
const COMPLETED_TASK_STATUS = {
41+
VERIFIED: "VERIFIED",
42+
DONE: "DONE",
43+
COMPLETED: "COMPLETED",
44+
};
4045
const TASK_SIZE = 5;
4146

42-
module.exports = { TASK_TYPE, TASK_STATUS, TASK_STATUS_OLD, MAPPED_TASK_STATUS, TASK_SIZE, DEFAULT_TASK_PRIORITY };
47+
const tasksUsersStatus = {
48+
MISSED_UPDATES: "missed-updates",
49+
};
50+
51+
module.exports = {
52+
TASK_TYPE,
53+
TASK_STATUS,
54+
TASK_STATUS_OLD,
55+
MAPPED_TASK_STATUS,
56+
TASK_SIZE,
57+
DEFAULT_TASK_PRIORITY,
58+
COMPLETED_TASK_STATUS,
59+
tasksUsersStatus,
60+
};

controllers/tasks.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const tasks = require("../models/tasks");
2-
const { TASK_STATUS, TASK_STATUS_OLD } = require("../constants/tasks");
2+
const { TASK_STATUS, TASK_STATUS_OLD, tasksUsersStatus } = require("../constants/tasks");
33
const { addLog } = require("../models/logs");
44
const { USER_STATUS } = require("../constants/users");
55
const { addOrUpdate, getRdsUserInfoByGitHubUsername } = require("../models/users");
@@ -13,6 +13,9 @@ const { updateUserStatusOnTaskUpdate, updateStatusOnTaskCompletion } = require("
1313
const dataAccess = require("../services/dataAccessLayer");
1414
const { parseSearchQuery } = require("../utils/tasks");
1515
const { addTaskCreatedAtAndUpdatedAtFields } = require("../services/tasks");
16+
const { RQLQueryParser } = require("../utils/RQLParser");
17+
const { getMissedProgressUpdatesUsers } = require("../models/discordactions");
18+
const { daysOfWeek } = require("../constants/constants");
1619
/**
1720
* Creates new task
1821
*
@@ -475,6 +478,38 @@ const updateStatus = async (req, res) => {
475478
}
476479
};
477480

481+
const getUsersHandler = async (req, res) => {
482+
try {
483+
const { size, cursor, q: queryString } = req.query;
484+
const rqlParser = new RQLQueryParser(queryString);
485+
const { "days-count": daysGap, weekday, date, status } = rqlParser.getFilterQueries();
486+
if (!!status && status.length === 1 && status[0].value === tasksUsersStatus.MISSED_UPDATES) {
487+
if (daysGap && daysGap > 1) {
488+
return res.boom.badRequest("number of days gap provided cannot be greater than 1");
489+
}
490+
const response = await getMissedProgressUpdatesUsers({
491+
cursor: cursor,
492+
size: size && Number.parseInt(size),
493+
excludedDates: date?.map((date) => Number.parseInt(date.value)),
494+
excludedDays: weekday?.map((day) => daysOfWeek[day.value]),
495+
dateGap: !!daysGap && daysGap.length === 1 ? Number.parseInt(daysGap[0].value) : null,
496+
});
497+
498+
if (response.error) {
499+
return res.boom.badRequest(response.message);
500+
}
501+
return res
502+
.status(200)
503+
.json({ message: "Discord details of users with status missed updates fetched successfully", data: response });
504+
} else {
505+
return res.boom.badRequest("Unknown type and query");
506+
}
507+
} catch (error) {
508+
logger.error("Error in fetching users details of tasks", error);
509+
return res.boom.badImplementation(INTERNAL_SERVER_ERROR);
510+
}
511+
};
512+
478513
module.exports = {
479514
addNewTask,
480515
fetchTasks,
@@ -486,4 +521,5 @@ module.exports = {
486521
overdueTasks,
487522
assignTask,
488523
updateStatus,
524+
getUsersHandler,
489525
};

middlewares/validators/tasks.js

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
const joi = require("joi");
2+
const { BadRequest } = require("http-errors");
23
const { DINERO, NEELAM } = require("../../constants/wallets");
3-
const { TASK_STATUS, TASK_STATUS_OLD, MAPPED_TASK_STATUS } = require("../../constants/tasks");
4-
4+
const { TASK_STATUS, TASK_STATUS_OLD, MAPPED_TASK_STATUS, tasksUsersStatus } = require("../../constants/tasks");
5+
const { RQLQueryParser } = require("../../utils/RQLParser");
6+
const { Operators } = require("../../typeDefinitions/rqlParser");
7+
const { daysOfWeek } = require("../../constants/constants");
58
const TASK_STATUS_ENUM = Object.values(TASK_STATUS);
69
const MAPPED_TASK_STATUS_ENUM = Object.keys(MAPPED_TASK_STATUS);
710

@@ -116,22 +119,30 @@ const updateTask = async (req, res, next) => {
116119
};
117120

118121
const updateSelfTask = async (req, res, next) => {
122+
const validStatus = [...TASK_STATUS_ENUM, ...Object.values(TASK_STATUS_OLD)].filter(
123+
(item) => item !== TASK_STATUS.AVAILABLE
124+
);
119125
const schema = joi
120126
.object()
121127
.strict()
122128
.keys({
123129
status: joi
124130
.string()
125-
.valid(...TASK_STATUS_ENUM, ...Object.values(TASK_STATUS_OLD))
126-
.optional(),
131+
.valid(...validStatus)
132+
.optional()
133+
.error(new BadRequest(`The value for the 'status' field is invalid.`)),
127134
percentCompleted: joi.number().integer().min(0).max(100).optional(),
128135
});
129136
try {
130137
await schema.validateAsync(req.body);
131138
next();
132139
} catch (error) {
133140
logger.error(`Error validating updateSelfTask payload : ${error}`);
134-
res.boom.badRequest(error.details[0].message);
141+
if (error instanceof BadRequest) {
142+
res.boom.badRequest(error.message);
143+
} else {
144+
res.boom.badRequest(error.details[0].message);
145+
}
135146
}
136147
};
137148

@@ -190,10 +201,68 @@ const getTasksValidator = async (req, res, next) => {
190201
res.boom.badRequest(error.details[0].message);
191202
}
192203
};
204+
const getUsersValidator = async (req, res, next) => {
205+
const queryParamsSchema = joi.object().keys({
206+
cursor: joi.string().optional(),
207+
q: joi.string().optional(),
208+
size: joi.number().integer().min(1).max(2013),
209+
});
210+
const filtersSchema = joi.object().keys({
211+
status: joi
212+
.array()
213+
.items(
214+
joi.object().keys({
215+
value: joi.string().valid(...Object.values(tasksUsersStatus)),
216+
operator: joi.string().valid(Operators.INCLUDE),
217+
})
218+
)
219+
.required(),
220+
"days-count": joi
221+
.array()
222+
.items(
223+
joi.object().keys({
224+
value: joi.number().integer().min(1).max(10),
225+
operator: joi.string().valid(Operators.EXCLUDE),
226+
})
227+
)
228+
.optional(),
229+
weekday: joi
230+
.array()
231+
.items(
232+
joi.object().keys({
233+
value: joi.string().valid(...Object.keys(daysOfWeek)),
234+
operator: joi.string().valid(Operators.EXCLUDE),
235+
})
236+
)
237+
.optional(),
238+
date: joi
239+
.array()
240+
.items(
241+
joi.object().keys({
242+
value: joi.date().timestamp(),
243+
operator: joi.string().valid(Operators.EXCLUDE),
244+
})
245+
)
246+
.optional(),
247+
});
193248

249+
try {
250+
const { q: queryString } = req.query;
251+
const rqlQueryParser = new RQLQueryParser(queryString);
252+
await Promise.all([
253+
queryParamsSchema.validateAsync(req.query),
254+
filtersSchema.validateAsync(rqlQueryParser.getFilterQueries()),
255+
]);
256+
next();
257+
} catch (error) {
258+
logger.error(`Error validating get tasks for users query : ${error}`);
259+
res.boom.badRequest(error.details[0].message);
260+
}
261+
};
194262
module.exports = {
195263
createTask,
196264
updateTask,
197265
updateSelfTask,
198266
getTasksValidator,
267+
getUsersValidator,
199268
};

0 commit comments

Comments
 (0)