Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PR) Demo 4 Version Of The Project #376

Merged
merged 138 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
138 commits
Select commit Hold shift + click to select a range
f288250
Added demo 3 stuff
MulisaMusehane Sep 26, 2024
9e3ed38
Create UserManualVersion4.md
MulisaMusehane Sep 26, 2024
59c2757
Create RequirementsSpecificationVersion4.md
MulisaMusehane Sep 26, 2024
6df3125
Create APISpecificationVersion4.md
MulisaMusehane Sep 26, 2024
1b4e02d
made the subscription dropdown adhere to the theme
ShamaKamina Sep 27, 2024
350a28e
made the more menu adhere to the dark theme
ShamaKamina Sep 27, 2024
6cfa189
Added orgs stuff
MulisaMusehane Sep 27, 2024
2ca027f
Delete documentation/specifications/documentation/specifications/APIS…
MulisaMusehane Sep 27, 2024
8245520
fixed some code
ShamaKamina Sep 27, 2024
9e88376
Comprehensive coding standards
MulisaMusehane Sep 27, 2024
b309461
fixed the dark theme on resolution modal
ShamaKamina Sep 27, 2024
f9b1b43
Added more examples fixed structure
MulisaMusehane Sep 27, 2024
be66716
fixed the message for forecasts
ShamaKamina Sep 27, 2024
632a00c
Made the search for "Resolved By " Dark
ShamaKamina Sep 27, 2024
8927f47
Coding standards and Requirement spec PDFs
MulisaMusehane Sep 27, 2024
f2423f6
Create ArchitecturalSpecificationVersion4.md
MulisaMusehane Sep 27, 2024
3b0dc67
Made the notifications adhere to dark mode
ShamaKamina Sep 27, 2024
f6f7ede
Changed "Reports" to "Statistics"
ShamaKamina Sep 27, 2024
da4bc58
changed the report icon and fixed tests
ShamaKamina Sep 27, 2024
6da7a96
okay fixed tests
ShamaKamina Sep 27, 2024
18b9549
Merge pull request #360 from COS301-SE-2024/feature/darkTheme
TebogoYungMercykay Sep 27, 2024
033cbce
Fixed dark mode in location modal
IRIA7 Sep 27, 2024
3942e8f
Merge pull request #361 from COS301-SE-2024/feature/dark_location
TebogoYungMercykay Sep 27, 2024
da0bbb8
Comprehensive arch doc
MulisaMusehane Sep 27, 2024
af83e2a
Arch pdf
MulisaMusehane Sep 27, 2024
9b90a1b
comprehension technical installation manual
MulisaMusehane Sep 27, 2024
4ad1708
Installation manual pdf
MulisaMusehane Sep 27, 2024
a043f8b
Added Timeout for Each fo the 4 Worker Processes
TebogoYungMercykay Sep 27, 2024
857153b
Implemented Logging for the Load Balancer
TebogoYungMercykay Sep 27, 2024
f9ff974
Moved the Imports Out The _main__
TebogoYungMercykay Sep 27, 2024
ee411e4
User manual pdf
MulisaMusehane Sep 27, 2024
ae3a0a5
Added org stuff
MulisaMusehane Sep 27, 2024
b3f4e6c
Dark Mode for Subscription Hover
TebogoYungMercykay Sep 27, 2024
b83c1e9
Loader for the Settings Page
TebogoYungMercykay Sep 27, 2024
85f6298
Fixed Loader On Settings Page.
TebogoYungMercykay Sep 27, 2024
7926449
Charts: Added Space Between Title and Chart
TebogoYungMercykay Sep 27, 2024
07233c5
Layout Updates for Charts, Overlapping Labels
TebogoYungMercykay Sep 27, 2024
0f7401f
Dark and Light Themes Mode for Charts
TebogoYungMercykay Sep 28, 2024
030e7d8
Theme: Added Theming for the BarChart
TebogoYungMercykay Sep 28, 2024
56b06a5
Theme: DonutChart Theming Done
TebogoYungMercykay Sep 28, 2024
4c3eb5a
Update: Changed The Colors For Dark Theme
TebogoYungMercykay Sep 28, 2024
32e7491
Theme: Added Theming for the LineChart
TebogoYungMercykay Sep 28, 2024
dabd555
Theme: Added Theming for the RadarChart
TebogoYungMercykay Sep 28, 2024
8a38a9d
Theme: Added Theming for the PoliticalChart
TebogoYungMercykay Sep 28, 2024
76b4440
Changed the Colors for the Light Theme
TebogoYungMercykay Sep 28, 2024
06d95fa
Implemented Theming for the StackendLine Chart
TebogoYungMercykay Sep 28, 2024
12a872d
Added Dark and Light thems for Transition Chart
TebogoYungMercykay Sep 28, 2024
a0f7b5f
Layout Update for the Charts
TebogoYungMercykay Sep 28, 2024
fe8510d
Integrating the Account Deletion With Backend
TebogoYungMercykay Sep 28, 2024
d131f7e
Updated The Tests for the Settings Page
TebogoYungMercykay Sep 28, 2024
f236e1e
Removed political chart (not working at the moment)
hlokomani Sep 28, 2024
e2d68c5
Changed from reports to statistics
hlokomani Sep 28, 2024
ca43f42
showing organizations and leaderboard for authenticated users only
hlokomani Sep 28, 2024
edf3c55
Fixed localhost redirection by making use of env variable
hlokomani Sep 28, 2024
e2d7ab1
Ensuring that cache only caches successful requests, not errors
hlokomani Sep 28, 2024
27a0624
Fixed Issue Posting Realtime Notification
TebogoYungMercykay Sep 28, 2024
8c3225d
Merge pull request #362 from COS301-SE-2024/feature/doc_update
TebogoYungMercykay Sep 28, 2024
3219483
Updated the Notifications Titles
TebogoYungMercykay Sep 29, 2024
4d912f4
Fixed the Expected Toast for Tests
TebogoYungMercykay Sep 29, 2024
e5204fb
Merge pull request #366 from COS301-SE-2024/feature/improvements
ShamaKamina Sep 29, 2024
6b601fe
added an image
ShamaKamina Sep 29, 2024
1266788
edited the text
ShamaKamina Sep 29, 2024
1e13c35
added the create organization section
ShamaKamina Sep 29, 2024
4083983
added the joining an org section
ShamaKamina Sep 29, 2024
74bc39f
added the managing org section
ShamaKamina Sep 29, 2024
3ee7998
moved the images
ShamaKamina Sep 29, 2024
06502e9
added the managing org section
ShamaKamina Sep 29, 2024
2405d65
changed image location
ShamaKamina Sep 29, 2024
c633b12
added the posting section
ShamaKamina Sep 29, 2024
cf47786
Added the activyt logs section
ShamaKamina Sep 29, 2024
8696da5
added the reports section
ShamaKamina Sep 29, 2024
f15fd7f
moved the images
ShamaKamina Sep 29, 2024
f251ffc
changed
ShamaKamina Sep 29, 2024
a941f7e
changesss
ShamaKamina Sep 29, 2024
c6b9562
fixed linksss
ShamaKamina Sep 29, 2024
6ed9945
fixed the images
ShamaKamina Sep 29, 2024
f5e0323
changed readMe links to the pdfs
ShamaKamina Sep 29, 2024
5cf744e
link to architectural markdown
ShamaKamina Sep 29, 2024
a37eb68
Merge pull request #367 from COS301-SE-2024/feature/helpmenu
MulisaMusehane Sep 30, 2024
d870d08
Caching visualization data
hlokomani Sep 30, 2024
f3b11f9
Decreased TTL for cache of visualization
hlokomani Sep 30, 2024
ec1f793
Integrated caching for comments
hlokomani Sep 30, 2024
abb470f
Implemented caching for organization controller
hlokomani Sep 30, 2024
bc054d5
Increased organization max to 10
hlokomani Sep 30, 2024
3e93855
Caching for subscriptions
hlokomani Sep 30, 2024
a088d79
Refining clearing of cache
hlokomani Sep 30, 2024
36e29e7
Made sure only one organization can be selected
hlokomani Sep 30, 2024
a97b26b
Adjusted size of org points in avatar
hlokomani Sep 30, 2024
95d4070
Prevented selecting multiple organizations
IRIA7 Sep 30, 2024
0f2052c
Updated for backend and frontend tests
hlokomani Sep 30, 2024
ffa2793
Fixed linting
hlokomani Sep 30, 2024
b47c9f6
Updated my section of readme
hlokomani Sep 30, 2024
bb60a1d
RealTime Notifications to Include Some Subscriptions
TebogoYungMercykay Sep 30, 2024
04d190b
Fetching and Storing User Subcriptions
TebogoYungMercykay Sep 30, 2024
a55cf29
Updated Google sign in text
IRIA7 Sep 30, 2024
bc5c2e4
Fixed The Undefned Error for Subscriptions
TebogoYungMercykay Sep 30, 2024
21e68c6
Merge pull request #368 from COS301-SE-2024/feature/various_fixes
TebogoYungMercykay Sep 30, 2024
9d53f64
added vercel analytics
hlokomani Sep 30, 2024
7037d98
Merge pull request #370 from COS301-SE-2024/feature/vercel_analytics
TebogoYungMercykay Sep 30, 2024
6127b25
Removed Redundant Line of Code
TebogoYungMercykay Sep 30, 2024
f0fb951
Stopped long user info from overflowing
IRIA7 Sep 30, 2024
f9da9fe
Correct Message for Gaining/Losing Points
TebogoYungMercykay Sep 30, 2024
781fc0f
Prevented issues with resolution responses from showing resolution pe…
IRIA7 Sep 30, 2024
a5d48c6
Merge pull request #369 from COS301-SE-2024/feature/notif_settings
hlokomani Sep 30, 2024
aa19d55
Added indicator when filtering from visualization
IRIA7 Sep 30, 2024
cc2d616
Updated feed test
IRIA7 Sep 30, 2024
12911ee
Merge branch 'develop' of github.com:COS301-SE-2024/The-Republic into…
IRIA7 Sep 30, 2024
57e1e06
Updated the Architectural Specification
TebogoYungMercykay Sep 30, 2024
284d84a
(docs) Change from NGINX to Python Flask Proxy
TebogoYungMercykay Sep 30, 2024
def794c
Merge pull request #371 from COS301-SE-2024/feature/minor_updates
ShamaKamina Sep 30, 2024
e4a1507
(docs) Updated the Technical Installation
TebogoYungMercykay Sep 30, 2024
1e244b4
Updated the Delivery Specification to Include Vercel Deployments
TebogoYungMercykay Sep 30, 2024
15e4ba3
added two tests
ShamaKamina Sep 30, 2024
9681bb8
Updated the Coding Standards to Include Linter Rules
TebogoYungMercykay Sep 30, 2024
f1b0d17
Updated to the Exact Response from API
TebogoYungMercykay Sep 30, 2024
22393c4
Fixed undefined JSON bug
IRIA7 Sep 30, 2024
b3ffcb6
added 2 more tests
ShamaKamina Sep 30, 2024
76003f7
Delete documentation/specifications/ArchitecturalSpecification.pdf
MulisaMusehane Sep 30, 2024
7c8b164
Create TestingSpecificationVersion4.md
MulisaMusehane Sep 30, 2024
516a283
Merge pull request #373 from COS301-SE-2024/feature/tests
TebogoYungMercykay Sep 30, 2024
003a586
Update TestingSpecificationVersion4.md
MulisaMusehane Sep 30, 2024
c1818f0
link gif
MulisaMusehane Sep 30, 2024
98d9463
testing spec pdf
MulisaMusehane Sep 30, 2024
6881f12
Merge pull request #374 from COS301-SE-2024/feature/minor_updates
TebogoYungMercykay Sep 30, 2024
d2fbf53
Update links
MulisaMusehane Sep 30, 2024
c7e2e5b
Separate pdf n md
MulisaMusehane Sep 30, 2024
86a03e4
Fixed links to latest doc
MulisaMusehane Sep 30, 2024
223bb9f
updated the links on the ReadME
ShamaKamina Sep 30, 2024
cc0e7da
updated links
ShamaKamina Sep 30, 2024
b1c4533
Bug Fix: Resolution Pending and Resolved Showing At Once
TebogoYungMercykay Sep 30, 2024
46a449a
Updated requirements pdf to include images
ShamaKamina Sep 30, 2024
0fb72f4
Permanent Fox for Invalid JSON Error
TebogoYungMercykay Sep 30, 2024
374b9fd
Updated the user manual to include images
ShamaKamina Sep 30, 2024
07164fe
Attempt to Fix LazyList Issue, Seems To Work
TebogoYungMercykay Sep 30, 2024
21c7be7
Merge branch 'develop' into feature/resolutons_fix
TebogoYungMercykay Sep 30, 2024
e8c0541
changed Senitment Analysis to public sentiment on the about page
ShamaKamina Sep 30, 2024
82fe559
Merge pull request #375 from COS301-SE-2024/feature/resolutons_fix
ShamaKamina Sep 30, 2024
465984b
Merge pull request #372 from COS301-SE-2024/feature/update_docs
ShamaKamina Sep 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,12 @@

The documentation provides different versions and progress for each demo, guiding you through various aspects of the project, including architectural design, implementation details, and user guidelines - [Click Here to See Documentation Versions](./documentation/README.md)

## Links to the Latest Documentation of the Project

- [User Manual](./documentation/specifications/UserManualVersion3.md)
- [Technical Installation Manual](./documentation/specifications/TechnicalInstallationManual1.md)
- [Coding Standards](./documentation/specifications/CodingStandardsVersion2.md)
- [Requirements Specification](./documentation/specifications/RequirementsSpecificationVersion3.md)
- [Delivery Specification](./documentation/specifications/DeliverySpecificationVersion2.md)
- [Testing Specification](./documentation/specifications/TestingSpecificationVersion3.md)
- [Architectural Specification](./documentation/specifications/ArchitecturalSpecificationVersion3.md)

- [User Manual](./documentation/specifications/UserManual.pdf)
- [Technical Installation Manual](./documentation/specifications/TechnicalInstallationManualVersion2.pdf)
- [Coding Standards](./documentation/specifications/Coding%20Standards.pdf)
- [Requirements Specification](./documentation/specifications/RequirementsSpecification.pdf)
- [Testing Specification](./documentation/specifications/TestingSpecification.pdf)
- [Architectural Specification](./documentation/specifications/ArchitecturalSpecificationVersion4.pdf)


<h1 align="center">Meet The Infinite Loopers!</h1>
Expand Down Expand Up @@ -235,7 +231,7 @@ The documentation provides different versions and progress for each demo, guidin
<b style="font-size: 18px;">HLOKOMANI KHONDLO</b>
</h2>
<b style="font-size: 16px;">Integration Engineer</b>
<br> I am an integration engineer driven by the desire to understand and optimize how systems work. My passion for software engineering allows me to create seamless integrations that enhance product functionality and user experience. I specialize in using various tools and technologies to connect different systems and ensure they work together efficiently.
<br> I'm an integration engineer who’s driven by building solutions that make a difference. I focus on creating systems that connect seamlessly and actually improve how things work. My goal is to deliver efficient and resilient solutions that have a real, lasting impact.
<br><br>
<b style="font-size: 16px;">Profile Links</b>
<br><br>
Expand All @@ -252,13 +248,13 @@ The documentation provides different versions and progress for each demo, guidin
<img src="https://skillicons.dev/icons?i=express">
</a>
<a href="#" style="text-decoration: none; margin-right: 10px; display: inline-block; vertical-align: middle;">
<img src="https://skillicons.dev/icons?i=supabase">
<img src="https://skillicons.dev/icons?i=react">
</a>
<a href="#" style="text-decoration: none; margin-right: 10px; display: inline-block; vertical-align: middle;">
<img src="https://skillicons.dev/icons?i=aws">
<img src="https://skillicons.dev/icons?i=azure">
</a>
<a href="#" style="text-decoration: none; margin-right: 10px; display: inline-block; vertical-align: middle;">
<img src="https://skillicons.dev/icons?i=nodejs">
<img src="https://skillicons.dev/icons?i=supabase">
</a>
<a href="#" style="text-decoration: none; margin-right: 10px; display: inline-block; vertical-align: middle;">
<img src="https://skillicons.dev/icons?i=nextjs">
Expand Down
14 changes: 12 additions & 2 deletions backend/src/__tests__/controllers/commentController.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Request, Response } from "express";
import { Request, Response, NextFunction } from "express";
import { CommentService } from "@/modules/comments/services/commentService";
import { sendResponse } from "@/utilities/response";
import * as commentController from "@/modules/comments/controllers/commentController";
Expand All @@ -19,11 +19,13 @@ jest.mock("@/modules/shared/services/redisClient", () => ({
describe("Comment Controller", () => {
let mockRequest: Partial<Request>;
let mockResponse: Partial<Response>;
let mockNext: NextFunction;
let mockCommentService: jest.Mocked<CommentService>;

beforeEach(() => {
mockRequest = { body: {} };
mockResponse = { json: jest.fn() } as Partial<Response>;
mockNext = jest.fn();
mockCommentService = {
getNumComments: jest.fn(),
getComments: jest.fn(),
Expand All @@ -44,7 +46,15 @@ describe("Comment Controller", () => {

testCases.forEach(({ name, method }) => {
it(`should call sendResponse for ${name}`, async () => {
await method(mockRequest as Request, mockResponse as Response);
if (Array.isArray(method)) {
// If the method is an array (middleware + controller), call each function in the array
for (const fn of method) {
await fn(mockRequest as Request, mockResponse as Response, mockNext);
}
} else {
// If it's a regular function, call it directly
await method(mockRequest as Request, mockResponse as Response);
}
expect(sendResponse).toHaveBeenCalled();
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Request, Response } from "express";
import { Request, Response, NextFunction } from "express";
import { sendResponse } from "@/utilities/response";
import SubscriptionsService from "@/modules/subscriptions/services/subscriptionsService";
import * as subscriptionsController from "@/modules/subscriptions/controllers/subscriptionsController";
Expand Down Expand Up @@ -176,9 +176,11 @@ describe("Subscriptions Controller", () => {
mockResponse,
);

await subscriptionsController.getSubscriptions(
// Call the last function in the getSubscriptions array
await subscriptionsController.getSubscriptions[subscriptionsController.getSubscriptions.length - 1](
req as Request,
res as Response,
jest.fn() as NextFunction
);

expect(
Expand All @@ -193,9 +195,11 @@ describe("Subscriptions Controller", () => {
mockError,
);

await subscriptionsController.getSubscriptions(
// Call the last function in the getSubscriptions array
await subscriptionsController.getSubscriptions[subscriptionsController.getSubscriptions.length - 1](
req as Request,
res as Response,
jest.fn() as NextFunction
);

expect(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Request, Response } from "express";
import { Request, Response, NextFunction } from "express";
import { VisualizationService } from "@/modules/visualizations/services/visualizationService";
import { sendResponse } from "@/utilities/response";
import * as visualizationController from "@/modules/visualizations/controllers/visualizationController";
Expand Down Expand Up @@ -37,9 +37,10 @@ describe("Visualization Controller", () => {
});

it("should call sendResponse for getVizData", async () => {
await visualizationController.getVizData(
await visualizationController.getVizData[visualizationController.getVizData.length - 1](
mockRequest as Request,
mockResponse as Response,
jest.fn() as NextFunction
);
expect(sendResponse).toHaveBeenCalled();
});
Expand All @@ -48,9 +49,10 @@ describe("Visualization Controller", () => {
const error = new Error("Test error");
mockVisualizationService.getVizData.mockRejectedValue(error);

await visualizationController.getVizData(
await visualizationController.getVizData[visualizationController.getVizData.length - 1](
mockRequest as Request,
mockResponse as Response,
jest.fn() as NextFunction
);
expect(sendResponse).toHaveBeenCalledWith(mockResponse, expect.any(Error));
});
Expand Down
32 changes: 0 additions & 32 deletions backend/src/__tests__/routes/commentRoutes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,6 @@ describe("Comments Routes", () => {
jest.clearAllMocks();
});

describe("POST /comments/", () => {
it("should call getComments controller", async () => {
(verifyAndGetUser as jest.Mock).mockImplementation((req, res, next) =>
next(),
);
(commentController.getComments as jest.Mock).mockImplementation(
(req, res) => res.status(200).json({}),
);

const response = await request(app).post("/comments/").send();

expect(response.status).toBe(200);
expect(commentController.getComments).toHaveBeenCalled();
});
});

describe("POST /comments/count", () => {
it("should call getNumComments controller", async () => {
(verifyAndGetUser as jest.Mock).mockImplementation((req, res, next) =>
next(),
);
(commentController.getNumComments as jest.Mock).mockImplementation(
(req, res) => res.status(200).json({}),
);

const response = await request(app).post("/comments/count").send();

expect(response.status).toBe(200);
expect(commentController.getNumComments).toHaveBeenCalled();
});
});

describe("POST /comments/add", () => {
it("should call addComment controller", async () => {
(verifyAndGetUser as jest.Mock).mockImplementation((req, res, next) =>
Expand Down
21 changes: 0 additions & 21 deletions backend/src/__tests__/routes/subscriptionsRoutes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,4 @@ describe("Subscription Routes", () => {
expect(subscriptionsController.locationSubscriptions).toHaveBeenCalled();
});
});

describe("POST /subscriptions/subscriptions", () => {
it("should call getSubscriptions controller", async () => {
(verifyAndGetUser as jest.Mock).mockImplementation((req, res, next) =>
next(),
);
(
subscriptionsController.getSubscriptions as jest.Mock
).mockImplementation((req, res) =>
res.status(200).json({ message: "Get subscriptions successful" }),
);

const response = await request(app)
.post("/subscriptions/subscriptions")
.send();

expect(response.status).toBe(200);
expect(response.body.message).toBe("Get subscriptions successful");
expect(subscriptionsController.getSubscriptions).toHaveBeenCalled();
});
});
});
22 changes: 13 additions & 9 deletions backend/src/__tests__/routes/visualizationRoutes.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import request from "supertest";
import express from "express";
import express, { Request, Response, NextFunction } from "express";
import visualizationRouter from "@/modules/visualizations/routes/visualizationRoutes";

import * as visualizationController from "@/modules/visualizations/controllers/visualizationController";

jest.mock("@/middleware/cacheMiddleware");
jest.mock("@/middleware/cacheMiddleware", () => ({
cacheMiddleware: jest.fn().mockImplementation(() => (req: Request, res: Response, next: NextFunction) => next()),
}));
jest.mock("@/utilities/cacheUtils");

jest.mock("@/modules/shared/services/redisClient", () => ({
Expand All @@ -17,24 +20,25 @@ jest.mock("@/modules/shared/services/redisClient", () => ({
},
}));

jest.mock("@/modules/visualizations/controllers/visualizationController");
jest.mock("@/modules/visualizations/controllers/visualizationController", () => ({
getVizData: jest.fn().mockImplementation((req: Request, res: Response) => {
return res.status(200).json({});
}),
}));

const app = express();
app.use(express.json());
app.use("/visualizations", visualizationRouter);


describe("Visualization Routes", () => {
beforeEach(() => {
jest.clearAllMocks();
});

describe("POST /visualizations/", () => {
describe("POST /visualizations", () => {
it("should call getVizData controller", async () => {
(visualizationController.getVizData as jest.Mock).mockImplementation(
(req, res) => res.status(200).json({}),
);

const response = await request(app).post("/visualizations/").send();
const response = await request(app).post("/visualizations").send();

expect(response.status).toBe(200);
expect(visualizationController.getVizData).toHaveBeenCalled();
Expand Down
4 changes: 3 additions & 1 deletion backend/src/middleware/cacheMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export const cacheMiddleware = (duration: number) => {
} else {
const originalJson = res.json;
res.json = function (body: unknown) {
redisClient?.setex(key, duration, JSON.stringify(body));
if (res.statusCode >= 200 && res.statusCode < 300) {
redisClient?.setex(key, duration, JSON.stringify(body));
}
return originalJson.call(this, body);
};
next();
Expand Down
52 changes: 31 additions & 21 deletions backend/src/modules/comments/controllers/commentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,44 @@ import { Request, Response } from "express";
import { CommentService } from "@/modules/comments/services/commentService";
import { sendResponse } from "@/utilities/response";
import { APIResponse } from "@/types/response";
import { cacheMiddleware } from "@/middleware/cacheMiddleware";
import { clearCachePattern } from "@/utilities/cacheUtils";

const commentService = new CommentService();

export async function getNumComments(req: Request, res: Response) {
try {
const { itemId, itemType, parent_id } = req.body;
const response = await commentService.getNumComments({
itemId,
itemType,
parent_id,
});
sendResponse(res, response);
} catch (error) {
sendResponse(res, error as APIResponse);
}
}
export const getNumComments = [
cacheMiddleware(300),
async (req: Request, res: Response) => {
try {
const { itemId, itemType, parent_id } = req.body;
const response = await commentService.getNumComments({
itemId,
itemType,
parent_id,
});
sendResponse(res, response);
} catch (error) {
sendResponse(res, error as APIResponse);
}
},
];

export async function getComments(req: Request, res: Response) {
try {
const response = await commentService.getComments(req.body);
sendResponse(res, response);
} catch (error) {
sendResponse(res, error as APIResponse);
}
}
export const getComments = [
cacheMiddleware(300),
async (req: Request, res: Response) => {
try {
const response = await commentService.getComments(req.body);
sendResponse(res, response);
} catch (error) {
sendResponse(res, error as APIResponse);
}
},
];

export async function addComment(req: Request, res: Response) {
try {
const response = await commentService.addComment(req.body);
clearCachePattern("__express__/api/comments*");
sendResponse(res, response);
} catch (error) {
sendResponse(res, error as APIResponse);
Expand All @@ -40,6 +49,7 @@ export async function addComment(req: Request, res: Response) {
export async function deleteComment(req: Request, res: Response) {
try {
const response = await commentService.deleteComment(req.body);
clearCachePattern("__express__/api/comments*");
sendResponse(res, response);
} catch (error) {
sendResponse(res, error as APIResponse);
Expand Down
10 changes: 5 additions & 5 deletions backend/src/modules/issues/repositories/issueRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default class IssueRepository {
const days =
forecastData && !forecastError ? formatTime(forecastData) : "6 days";
const information = !issue.resolved_at
? `This issue may take at least ${days} to be resolved. Please check back if your issue is not resolved by then.`
? `This issue may take around ${days} to be resolved based on similar issues in this area.`
: "This issue has already been resolved.";

return {
Expand Down Expand Up @@ -249,7 +249,7 @@ export default class IssueRepository {
const days =
forecastData && !forecastError ? formatTime(forecastData) : "6 days";
const information = !data.resolved_at
? `This issue may take at least ${days} to be resolved. Please check back if your issue is not resolved by then.`
? `This issue may take around ${days} to be resolved based on similar issues in this area.`
: "This issue has already been resolved.";

return {
Expand Down Expand Up @@ -427,7 +427,7 @@ export default class IssueRepository {
const days =
forecastData && !forecastError ? formatTime(forecastData) : "6 days";
const information = !issue.resolved_at
? `This issue may take at least ${days} to be resolved. Please check back if your issue is not resolved by then.`
? `This issue may take around ${days} to be resolved based on similar issues in this area.`
: "This issue has already been resolved.";

return {
Expand Down Expand Up @@ -677,7 +677,7 @@ export default class IssueRepository {
const days =
forecastData && !forecastError ? formatTime(forecastData) : "6 days";
const information = !issue.resolved_at
? `This issue may take at least ${days} to be resolved. Please check back if your issue is not resolved by then.`
? `This issue may take around ${days} to be resolved based on similar issues in this area.`
: "This issue has already been resolved.";

return {
Expand Down Expand Up @@ -772,7 +772,7 @@ export default class IssueRepository {
const days =
forecastData && !forecastError ? formatTime(forecastData) : "6 days";
const information = !issue.resolved_at
? `This issue may take at least ${days} to be resolved. Please check back if your issue is not resolved by then.`
? `This issue may take around ${days} to be resolved based on similar issues in this area.`
: "This issue has already been resolved.";

return {
Expand Down
Loading
Loading