-
-
Notifications
You must be signed in to change notification settings - Fork 685
js->ts #3112
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
js->ts #3112
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,109 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| import { Request, Response, NextFunction } from "express"; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| import { createStatusPageBodyValidation, getStatusPageParamValidation, getStatusPageQueryValidation, imageValidation } from "@/validation/joi.js"; | ||||||||||||||||||||||||||||||||||||||||||||
| import { AppError } from "@/utils/AppError.js"; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| const SERVICE_NAME = "statusPageController"; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| class StatusPageController { | ||||||||||||||||||||||||||||||||||||||||||||
| static SERVICE_NAME = SERVICE_NAME; | ||||||||||||||||||||||||||||||||||||||||||||
| private db: any; | ||||||||||||||||||||||||||||||||||||||||||||
| constructor(db: any) { | ||||||||||||||||||||||||||||||||||||||||||||
| this.db = db; | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+8
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1 | Confidence: High The controller's constructor signature has been changed from accepting
Suggested change
Comment on lines
+10
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2 | Confidence: High The Code Suggestion: interface DatabaseService {
statusPageModule: {
createStatusPage: (params: any) => Promise<any>;
updateStatusPage: (data: any, file: any) => Promise<any | null>;
// ... other methods
};
}
private db: DatabaseService;
constructor(db: DatabaseService) {
this.db = db;
} |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| get serviceName() { | ||||||||||||||||||||||||||||||||||||||||||||
| return StatusPageController.SERVICE_NAME; | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| createStatusPage = async (req: Request, res: Response, next: NextFunction) => { | ||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2 | Confidence: High The method directly destructures Code Suggestion: // Option: Type assertion (if confident)
const user = req.user as { _id: string; teamId: string }; // or a proper User type
const { _id, teamId } = user;
// Or, a runtime check for safety in development
if (!req.user) {
throw new Error('Authentication middleware failed to set req.user');
}Evidence: method:createStatusPage, search:req.user |
||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||
| await createStatusPageBodyValidation.validateAsync(req.body); | ||||||||||||||||||||||||||||||||||||||||||||
| await imageValidation.validateAsync(req.file); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| const { _id, teamId } = req.user; | ||||||||||||||||||||||||||||||||||||||||||||
| const statusPage = await this.db.statusPageModule.createStatusPage({ | ||||||||||||||||||||||||||||||||||||||||||||
| statusPageData: req.body, | ||||||||||||||||||||||||||||||||||||||||||||
| image: req.file, | ||||||||||||||||||||||||||||||||||||||||||||
| userId: _id, | ||||||||||||||||||||||||||||||||||||||||||||
| teamId, | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
| return res.status(200).json({ | ||||||||||||||||||||||||||||||||||||||||||||
| msg: "Status page created successfully", | ||||||||||||||||||||||||||||||||||||||||||||
| data: statusPage, | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||
| next(error); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extend the Express Line 24 accesses 🔷 Add type declarations for req.userCreate a type declaration file (e.g., import { Request } from 'express';
declare module 'express-serve-static-core' {
interface Request {
user?: {
_id: string;
teamId: string;
// Add other user properties as needed
};
}
}Then ensure this declaration is included in your 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| updateStatusPage = async (req: Request, res: Response, next: NextFunction) => { | ||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1 | Confidence: High The original |
||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||
| await createStatusPageBodyValidation.validateAsync(req.body); | ||||||||||||||||||||||||||||||||||||||||||||
| await imageValidation.validateAsync(req.file); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| const statusPage = await this.db.statusPageModule.updateStatusPage(req.body, req.file); | ||||||||||||||||||||||||||||||||||||||||||||
| if (statusPage === null) { | ||||||||||||||||||||||||||||||||||||||||||||
| throw new AppError({ message: "Status page not found", status: 404 }); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| return res.status(200).json({ | ||||||||||||||||||||||||||||||||||||||||||||
| msg: "Status page updated successfully", | ||||||||||||||||||||||||||||||||||||||||||||
| data: statusPage, | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||
| next(error); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| getStatusPage = async (req: Request, res: Response, next: NextFunction) => { | ||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||
| const statusPage = await this.db.statusPageModule.getStatusPage(); | ||||||||||||||||||||||||||||||||||||||||||||
| return res.status(200).json({ | ||||||||||||||||||||||||||||||||||||||||||||
| msg: "Status page retrieved successfully", | ||||||||||||||||||||||||||||||||||||||||||||
| data: statusPage, | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||
| next(error); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| getStatusPageByUrl = async (req: Request, res: Response, next: NextFunction) => { | ||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||
| await getStatusPageParamValidation.validateAsync(req.params); | ||||||||||||||||||||||||||||||||||||||||||||
| await getStatusPageQueryValidation.validateAsync(req.query); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| const statusPage = await this.db.statusPageModule.getStatusPageByUrl(req.params.url); | ||||||||||||||||||||||||||||||||||||||||||||
| return res.status(200).json({ | ||||||||||||||||||||||||||||||||||||||||||||
| msg: "Status page retrieved successfully", | ||||||||||||||||||||||||||||||||||||||||||||
| data: statusPage, | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||
| next(error); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+70
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Find the statusPageModule implementation
fd -t f -e ts -e js | grep -i "module\|service" | grep -i "status" | head -20Repository: bluewave-labs/Checkmate Length of output: 165 🏁 Script executed: #!/bin/bash
# Search for statusPageModule definition and getStatusPageByUrl implementation
rg "statusPageModule|getStatusPageByUrl" -t ts --max-count 20Repository: bluewave-labs/Checkmate Length of output: 975 🏁 Script executed: #!/bin/bash
# Look at the controllers directory structure
find server/src/controllers -type f -name "*.ts" | head -10Repository: bluewave-labs/Checkmate Length of output: 308 🏁 Script executed: #!/bin/bash
# Read the statusPageModule to understand getStatusPageByUrl implementation
cat server/src/db/v1/modules/statusPageModule.jsRepository: bluewave-labs/Checkmate Length of output: 7100 🏁 Script executed: #!/bin/bash
# Read the statusPageController to see validation definitions and full context
cat server/src/controllers/v1/statusPageController.tsRepository: bluewave-labs/Checkmate Length of output: 3147 🏁 Script executed: #!/bin/bash
# Find the validation definitions
fd -t f -name "joi.js" -o -name "joi.ts"Repository: bluewave-labs/Checkmate Length of output: 297 🏁 Script executed: #!/bin/bash
# Search for getStatusPageQueryValidation definition
rg "getStatusPageQueryValidation" -A 5 -B 2Repository: bluewave-labs/Checkmate Length of output: 2437 Query parameters validated but never used. Line 73 validates Either pass the query parameters to the module method or remove the unnecessary validation on line 73. 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
| getStatusPagesByTeamId = async (req: Request, res: Response, next: NextFunction) => { | ||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||
| const teamId = req.user.teamId; | ||||||||||||||||||||||||||||||||||||||||||||
| const statusPages = await this.db.statusPageModule.getStatusPagesByTeamId(teamId); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| return res.status(200).json({ | ||||||||||||||||||||||||||||||||||||||||||||
| msg: "Status pages retrieved successfully", | ||||||||||||||||||||||||||||||||||||||||||||
| data: statusPages, | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||
| next(error); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||
| deleteStatusPage = async (req: Request, res: Response, next: NextFunction) => { | ||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||
| await this.db.statusPageModule.deleteStatusPage(req.params.url); | ||||||||||||||||||||||||||||||||||||||||||||
| return res.status(200).json({ | ||||||||||||||||||||||||||||||||||||||||||||
| msg: "Status page deleted successfully", | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||
| next(error); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+97
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing parameter validation in Line 99 uses ➕ Add parameter validation deleteStatusPage = async (req: Request, res: Response, next: NextFunction) => {
try {
+ await getStatusPageParamValidation.validateAsync(req.params);
await this.db.statusPageModule.deleteStatusPage(req.params.url);
return res.status(200).json({
msg: "Status page deleted successfully",
});
} catch (error) {
next(error);
}
};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Comment on lines
+97
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2 | Confidence: Medium Speculative: The Code Suggestion: deleteStatusPage = async (req: Request, res: Response, next: NextFunction) => {
try {
await getStatusPageParamValidation.validateAsync(req.params); // Re-use the same validation
await this.db.statusPageModule.deleteStatusPage(req.params.url);
return res.status(200).json({
msg: "Status page deleted successfully",
});
} catch (error) {
next(error);
}
};Evidence: method:deleteStatusPage |
||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| export default StatusPageController; | ||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Type the
dbparameter properly instead of usingany.Using
anydefeats the purpose of TypeScript migration. Thedbobject has a known structure with astatusPageModuleproperty. Consider creating a proper interface or type for the database dependency.🔷 Suggested type-safe approach
Create a type or interface for the database:
📝 Committable suggestion
🤖 Prompt for AI Agents