Skip to content

Commit cae90c7

Browse files
authored
Merge branch 'develop' into bugfix/issue957
2 parents d20932d + 303fdc7 commit cae90c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4025
-1516
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
jobs:
1212
build:
1313
runs-on: ubuntu-latest
14+
timeout-minutes: 5
1415

1516
strategy:
1617
matrix:

CONTRIBUTING.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,19 @@ The following project structure should be followed:
101101
- Authorization header: `Authorization: Bearer <token>`
102102
103103
## Production login:
104-
https://github.com/login/oauth/authorize?client_id=23c78f66ab7964e5ef97
104+
105+
https://api.realdevsquad.com/auth/github/login
105106
106107
### Production login - Cookie:
108+
107109
rds-session
108110
109111
## Staging login:
110-
https://github.com/login/oauth/authorize?client_id=ebb301661e883a85bf9a
111112
112-
### Staging login - Cookie:
113+
https://staging-api.realdevsquad.com/auth/github/login
114+
115+
### Staging login - Cookie:
116+
113117
rds-session-staging
114118
115119
## Testing Guidelines
@@ -155,3 +159,16 @@ export FIRESTORE_EMULATOR_HOST="localhost:<Firebase emulator PORT>"
155159
- Every pull request should have associated issue(s) on our [issue tracker](https://github.com/Real-Dev-Squad/website-backend/issues).
156160
- For any non-trivial fixes and features, unit and integration tests must be added. The PR reviewer should not approve/merge PR(s) that lack these.
157161
- The PR(s) should be merged only after the CI passes.
162+
163+
## Certain issues you may face while running the tests:
164+
165+
- Java version is not above 11
166+
- When we run yarn test, it runs both the unit and integration tests (in this order). So after the unit tests are done, the java process is not killed automatically and when our integration test run it gives error.
167+
- Error: connect ECONNREFUSED ::1:8081
168+
169+
## Possible solutions for above issues (in particular order):
170+
171+
- Java version above 11 is needed for firebase tool version >= 11
172+
- Either manually kill the java process after unit tests are done or run both the tests separately by running the test commands.
173+
- Add 'host : 0.0.0.0' to both firestore and ui object in firebase.json file if it is not added.
174+
for more info refer this : https://github.com/Real-Dev-Squad/website-backend/issues/918

config/default.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ module.exports = {
4646
authRedirection: "/goto",
4747
},
4848
},
49+
discordBot: {
50+
baseUrl: "<DISCORD_BOT_BASE_URL>",
51+
},
4952
},
5053

5154
cors: {

constants/monitor.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const RESOURCE_CREATED_SUCCESSFULLY = "Resource created successfully.";
2+
const RESOURCE_UPDATED_SUCCESSFULLY = "Resource updated successfully.";
3+
const RESOURCE_RETRIEVED_SUCCESSFULLY = "Resource retrieved successfully.";
4+
const RESOURCE_NOT_FOUND = "Resource not found.";
5+
const RESOURCE_ALREADY_TRACKED = "Resource is already being tracked.";
6+
7+
const RESPONSE_MESSAGES = {
8+
RESOURCE_CREATED_SUCCESSFULLY,
9+
RESOURCE_UPDATED_SUCCESSFULLY,
10+
RESOURCE_RETRIEVED_SUCCESSFULLY,
11+
RESOURCE_NOT_FOUND,
12+
RESOURCE_ALREADY_TRACKED,
13+
};
14+
15+
module.exports = { RESPONSE_MESSAGES };

constants/progresses.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const PROGRESS_DOCUMENT_RETRIEVAL_SUCCEEDED = "Progress document retrieved succe
33
const PROGRESS_DOCUMENT_NOT_FOUND = "No progress records found.";
44
const PROGRESS_ALREADY_CREATED = "Progress for the day has already been created.";
55
const MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000;
6+
const INTERNAL_SERVER_ERROR_MESSAGE =
7+
"The server has encountered an unexpected error. Please contact the administrator for more information.";
68

79
const RESPONSE_MESSAGES = {
810
PROGRESS_DOCUMENT_CREATED_SUCCEEDED,
@@ -11,4 +13,17 @@ const RESPONSE_MESSAGES = {
1113
PROGRESS_ALREADY_CREATED,
1214
};
1315

14-
module.exports = { RESPONSE_MESSAGES, MILLISECONDS_IN_DAY };
16+
const TYPE_MAP = {
17+
user: "userId",
18+
task: "taskId",
19+
};
20+
21+
const VALID_PROGRESS_TYPES = ["task", "user"];
22+
23+
module.exports = {
24+
RESPONSE_MESSAGES,
25+
MILLISECONDS_IN_DAY,
26+
INTERNAL_SERVER_ERROR_MESSAGE,
27+
TYPE_MAP,
28+
VALID_PROGRESS_TYPES,
29+
};

constants/rateLimiting.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const TOO_MANY_REQUESTS = {
2+
ERROR_TYPE: "Too Many Requests",
3+
STATUS_CODE: 429,
4+
};
5+
6+
module.exports = {
7+
TOO_MANY_REQUESTS,
8+
};

constants/roles.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const ROLES = {
44
APPOWNER: "app_owner",
55
MEMBER: "member",
66
ARCHIVED: "archived",
7+
INDISCORD: "in_discord",
78
};
89

910
module.exports = ROLES;

constants/tasks.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,11 @@ const TASK_TYPE = {
55
};
66

77
const TASK_STATUS = {
8-
// old task workflow
9-
ACTIVE: "IN_PROGRESS",
10-
"HIGH PRIORITY": "HIGH PRIORITY",
11-
PENDING: "IN_PROGRESS",
8+
AVAILABLE: "AVAILABLE",
129
ASSIGNED: "ASSIGNED",
13-
BLOCKED: "BLOCKED",
1410
COMPLETED: "COMPLETED",
15-
16-
// new task workflow
1711
IN_PROGRESS: "IN_PROGRESS",
18-
UNASSIGNED: "AVAILABLE",
19-
AVAILABLE: "AVAILABLE",
12+
BLOCKED: "BLOCKED",
2013
SMOKE_TESTING: "SMOKE_TESTING",
2114
NEEDS_REVIEW: "NEEDS_REVIEW",
2215
IN_REVIEW: "IN_REVIEW",
@@ -26,8 +19,10 @@ const TASK_STATUS = {
2619
REGRESSION_CHECK: "REGRESSION_CHECK",
2720
RELEASED: "RELEASED",
2821
VERIFIED: "VERIFIED",
22+
DONE: "DONE",
2923
};
3024

25+
// TODO: convert this to new task status
3126
const TASK_STATUS_OLD = {
3227
OLD_ACTIVE: "active",
3328
OLD_BLOCKED: "blocked",

constants/users.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const USER_STATUS = {
1313
const ALLOWED_FILTER_PARAMS = {
1414
ITEM_TAG: ["levelId", "levelName", "levelValue", "tagId"],
1515
USER_STATE: ["state"],
16+
ROLE: ["role"],
1617
};
1718

1819
module.exports = { profileStatus, USER_STATUS, ALLOWED_FILTER_PARAMS };

controllers/monitor.js

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
const { Conflict, NotFound } = require("http-errors");
2+
const { INTERNAL_SERVER_ERROR_MESSAGE } = require("../constants/progresses");
3+
const {
4+
createTrackedProgressDocument,
5+
updateTrackedProgressDocument,
6+
getTrackedProgressDocuments,
7+
} = require("../models/monitor");
8+
const { RESPONSE_MESSAGES } = require("../constants/monitor");
9+
const { RESOURCE_CREATED_SUCCESSFULLY, RESOURCE_UPDATED_SUCCESSFULLY, RESOURCE_RETRIEVED_SUCCESSFULLY } =
10+
RESPONSE_MESSAGES;
11+
/**
12+
* @typedef {Object} TrackedProgressRequestBody
13+
* @property {string} type - The type of tracked progress ("user" or "task").
14+
* @property {string} [userId] - The user ID (required if type is "user").
15+
* @property {string} [taskId] - The task ID (required if type is "task").
16+
* @property {boolean} monitored - Indicates if the progress is currently being tracked.
17+
* @property {number} [frequency=1] - The frequency of tracking.By default 1 if not specified
18+
*/
19+
20+
/**
21+
* @typedef {Object} TrackedProgressResponseData
22+
* @property {string} id - The ID of the tracked progress document.
23+
* @property {string} type - The type of tracked progress ("user" or "task").
24+
* @property {string} userId - The user ID.
25+
* @property {boolean} monitored - Indicates if the progress is currently being tracked.
26+
* @property {number} frequency - The frequency of tracking.
27+
* @property {string} createdAt - The timestamp when the document was created.
28+
* @property {string} updatedAt - The timestamp when the document was last updated.
29+
*/
30+
31+
/**
32+
* @typedef {Object} TrackedProgressResponse
33+
* @property {TrackedProgressResponseData} data - The data of the tracked progress document.
34+
* @property {string} message - The success message.
35+
*/
36+
37+
/**
38+
* Controller function for creating a tracked progress document.
39+
*
40+
* @param {Express.Request} req - The Express request object.
41+
* @param {TrackedProgressRequestBody} req.body - The Request body object.
42+
* @param {Express.Response} res - The Express response object.
43+
* @returns {Promise<void>} - A Promise that resolves when the response has been sent.
44+
*/
45+
46+
const createTrackedProgressController = async (req, res) => {
47+
try {
48+
const data = await createTrackedProgressDocument({ ...req.body });
49+
return res.status(201).json({
50+
message: RESOURCE_CREATED_SUCCESSFULLY,
51+
data,
52+
});
53+
} catch (error) {
54+
if (error instanceof Conflict) {
55+
return res.status(409).json({
56+
message: error.message,
57+
});
58+
} else if (error instanceof NotFound) {
59+
return res.status(404).json({
60+
message: error.message,
61+
});
62+
}
63+
return res.status(500).json({
64+
message: INTERNAL_SERVER_ERROR_MESSAGE,
65+
});
66+
}
67+
};
68+
69+
/**
70+
* @typedef {Object} UpdateTrackedProgressRequestParams
71+
* @property {string} type - The type of tracked progress ("user" or "task").
72+
* @property {string} id - The ID of the tracked progress document.
73+
*/
74+
75+
/**
76+
* @typedef {Object} UpdateTrackedProgressRequestBody
77+
* @property {number} frequency - The frequency of tracking.
78+
* @property {boolean} monitored - Indicates if the progress is currently being tracked.
79+
*/
80+
81+
/**
82+
* @typedef {Object} UpdateTrackedProgressResponseData
83+
* @property {string} id - The ID of the tracked progress document.
84+
* @property {string} createdAt - The timestamp when the document was created.
85+
* @property {string} type - The type of tracked progress ("user" or "task").
86+
* @property {string} userId - The user ID.
87+
* @property {number} frequency - The frequency of tracking.
88+
* @property {boolean} monitored - Indicates if the progress is currently being tracked.
89+
* @property {string} updatedAt - The timestamp when the document was last updated.
90+
*/
91+
92+
/**
93+
* @typedef {Object} UpdateTrackedProgressResponse
94+
* @property {UpdateTrackedProgressResponseData} data - The data of the tracked progress document.
95+
* @property {string} message - The success message.
96+
*/
97+
98+
/**
99+
* Controller function for updating a tracked progress document.
100+
*
101+
* @param {Express.Request} req - The Express request object.
102+
* @param {UpdateTrackedProgressRequestParams} req.params - The request path parameters.
103+
* @param {UpdateTrackedProgressRequestBody} req.body - The request body object.
104+
* @param {Express.Response} res - The Express response object.
105+
* @returns {Promise<void>} - A Promise that resolves when the response has been sent.
106+
*/
107+
108+
const updateTrackedProgressController = async (req, res) => {
109+
try {
110+
const data = await updateTrackedProgressDocument({ ...req });
111+
return res.status(200).json({
112+
data,
113+
message: RESOURCE_UPDATED_SUCCESSFULLY,
114+
});
115+
} catch (error) {
116+
if (error instanceof NotFound) {
117+
return res.status(404).json({
118+
message: error.message,
119+
});
120+
}
121+
return res.status(500).json({
122+
message: INTERNAL_SERVER_ERROR_MESSAGE,
123+
});
124+
}
125+
};
126+
127+
/**
128+
* @typedef {Object} GetTrackedProgressRequestParams
129+
* @property {string} [type] - The type of tracked progress ("user" or "task").
130+
* @property {string} [monitored] - Indicates if the progress is currently being tracked.
131+
* @property {string} [userId] - The ID of the User who is currently being tracked.
132+
* @property {string} [taskId] - The ID of the task which is currently being tracked.
133+
*/
134+
135+
/**
136+
* @typedef {Object} TrackedProgressData
137+
* @property {string} id - The ID of the tracked progress document.
138+
* @property {boolean} monitored - Indicates if the progress is currently being tracked.
139+
* @property {string} createdAt - The timestamp when the document was created.
140+
* @property {string} type - The type of tracked progress ("user" or "task").
141+
* @property {string} [userId] - The user ID.
142+
* @property {string} [taskId] - The task ID.
143+
* @property {number} frequency - The frequency of tracking.
144+
* @property {string} updatedAt - The timestamp when the document was last updated.
145+
*/
146+
147+
/**
148+
* @typedef {Object} GetTrackedProgressResponse
149+
* @property {string} message - The success message.
150+
* @property {TrackedProgressData | TrackedProgressData[]} data - The data of the tracked progress document(s).
151+
*/
152+
153+
/**
154+
* Controller function for retrieving tracked progress documents.
155+
*
156+
* @param {Express.Request} req - The Express request object.
157+
* @param {Express.Response} res - The Express response object.
158+
* @returns {Promise<void>} A Promise that resolves when the response has been sent.
159+
*/
160+
161+
const getTrackedProgressController = async (req, res) => {
162+
try {
163+
const data = await getTrackedProgressDocuments({ ...req.query });
164+
return res.status(200).json({
165+
message: RESOURCE_RETRIEVED_SUCCESSFULLY,
166+
data,
167+
});
168+
} catch (error) {
169+
if (error instanceof NotFound) {
170+
const response = {
171+
message: error.message,
172+
};
173+
if (req.query.type) {
174+
response.data = [];
175+
}
176+
return res.status(404).json(response);
177+
}
178+
return res.status(500).json({
179+
message: INTERNAL_SERVER_ERROR_MESSAGE,
180+
});
181+
}
182+
};
183+
184+
module.exports = {
185+
createTrackedProgressController,
186+
updateTrackedProgressController,
187+
getTrackedProgressController,
188+
};

0 commit comments

Comments
 (0)