mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-05-22 01:29:30 -05:00
js -> ts
This commit is contained in:
@@ -35,9 +35,7 @@ export const initializeControllers = (services) => {
|
||||
settingsService: services.settingsService,
|
||||
checkService: services.checkService,
|
||||
});
|
||||
controllers.inviteController = new InviteController(commonDependencies, {
|
||||
inviteService: services.inviteService,
|
||||
});
|
||||
controllers.inviteController = new InviteController(services.inviteService);
|
||||
|
||||
controllers.maintenanceWindowController = new MaintenanceWindowController(services.maintenanceWindowService);
|
||||
controllers.queueController = new QueueController(services.jobQueue);
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
import { inviteBodyValidation, inviteVerificationBodyValidation } from "../../validation/joi.js";
|
||||
import BaseController from "./baseController.js";
|
||||
const SERVICE_NAME = "inviteController";
|
||||
|
||||
/**
|
||||
* Controller for handling user invitation operations
|
||||
* Manages invite token generation, email sending, and token verification
|
||||
*/
|
||||
class InviteController extends BaseController {
|
||||
static SERVICE_NAME = SERVICE_NAME;
|
||||
/**
|
||||
* Creates a new InviteController instance
|
||||
* @param {Object} commonDependencies - Common dependencies injected into the controller
|
||||
* @param {Object} dependencies.inviteService - Service for invite-related operations
|
||||
*/
|
||||
constructor(commonDependencies, { inviteService }) {
|
||||
super(commonDependencies);
|
||||
this.inviteService = inviteService;
|
||||
}
|
||||
|
||||
get serviceName() {
|
||||
return InviteController.SERVICE_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an invite token for a user invitation
|
||||
* @param {Object} req - Express request object
|
||||
* @param {Object} req.body - Request body containing invite details
|
||||
* @param {Object} req.user - Authenticated user object
|
||||
* @param {string} req.user.teamId - Team ID of the authenticated user
|
||||
* @param {Object} res - Express response object
|
||||
* @returns {Promise<Object>} Response with invite token data
|
||||
*/
|
||||
getInviteToken = this.asyncHandler(
|
||||
async (req, res) => {
|
||||
const invite = req.body;
|
||||
const teamId = req?.user?.teamId;
|
||||
invite.teamId = teamId;
|
||||
await inviteBodyValidation.validateAsync(invite);
|
||||
const inviteToken = await this.inviteService.getInviteToken({ invite, teamId });
|
||||
return res.success({
|
||||
msg: this.stringService.inviteIssued,
|
||||
data: inviteToken,
|
||||
});
|
||||
},
|
||||
SERVICE_NAME,
|
||||
"getInviteToken"
|
||||
);
|
||||
|
||||
/**
|
||||
* Sends an invitation email to a user
|
||||
* @param {Object} req - Express request object
|
||||
* @param {Object} req.body - Request body containing invite details
|
||||
* @param {Object} req.user - Authenticated user object
|
||||
* @param {string} req.user.teamId - Team ID of the authenticated user
|
||||
* @param {string} req.user.firstName - First name of the authenticated user
|
||||
* @param {Object} res - Express response object
|
||||
* @returns {Promise<Object>} Response with invite token data
|
||||
*/
|
||||
sendInviteEmail = this.asyncHandler(
|
||||
async (req, res) => {
|
||||
const inviteRequest = req.body;
|
||||
inviteRequest.teamId = req?.user?.teamId;
|
||||
await inviteBodyValidation.validateAsync(inviteRequest);
|
||||
|
||||
const inviteToken = await this.inviteService.sendInviteEmail({
|
||||
inviteRequest,
|
||||
firstName: req?.user?.firstName,
|
||||
});
|
||||
return res.success({
|
||||
msg: this.stringService.inviteIssued,
|
||||
data: inviteToken,
|
||||
});
|
||||
},
|
||||
SERVICE_NAME,
|
||||
"sendInviteEmail"
|
||||
);
|
||||
|
||||
/**
|
||||
* Verifies an invite token and returns invite details
|
||||
* @param {Object} req - Express request object
|
||||
* @param {Object} req.body - Request body containing the invite token
|
||||
* @param {string} req.body.token - The invite token to verify
|
||||
* @param {Object} res - Express response object
|
||||
* @returns {Promise<Object>} Response with verified invite data
|
||||
*/
|
||||
verifyInviteToken = this.asyncHandler(
|
||||
async (req, res) => {
|
||||
await inviteVerificationBodyValidation.validateAsync(req.body);
|
||||
const invite = await this.inviteService.verifyInviteToken({ inviteToken: req?.body?.token });
|
||||
return res.success({
|
||||
msg: this.stringService.inviteVerified,
|
||||
data: invite,
|
||||
});
|
||||
},
|
||||
SERVICE_NAME,
|
||||
"verifyInviteToken"
|
||||
);
|
||||
}
|
||||
|
||||
export default InviteController;
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import { inviteBodyValidation, inviteVerificationBodyValidation } from "@/validation/joi.js";
|
||||
const SERVICE_NAME = "inviteController";
|
||||
|
||||
class InviteController {
|
||||
static SERVICE_NAME = SERVICE_NAME;
|
||||
private inviteService: any;
|
||||
constructor(inviteService: any) {
|
||||
this.inviteService = inviteService;
|
||||
}
|
||||
|
||||
get serviceName() {
|
||||
return InviteController.SERVICE_NAME;
|
||||
}
|
||||
|
||||
getInviteToken = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const invite = req.body;
|
||||
const teamId = req?.user?.teamId;
|
||||
invite.teamId = teamId;
|
||||
await inviteBodyValidation.validateAsync(invite);
|
||||
const inviteToken = await this.inviteService.getInviteToken({ invite, teamId });
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: "Invite token generated successfully",
|
||||
data: inviteToken,
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
sendInviteEmail = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const inviteRequest = req.body;
|
||||
inviteRequest.teamId = req?.user?.teamId;
|
||||
await inviteBodyValidation.validateAsync(inviteRequest);
|
||||
|
||||
const inviteToken = await this.inviteService.sendInviteEmail({
|
||||
inviteRequest,
|
||||
firstName: req?.user?.firstName,
|
||||
});
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: "Invite issued successfully",
|
||||
data: inviteToken,
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
verifyInviteToken = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
await inviteVerificationBodyValidation.validateAsync(req.body);
|
||||
const invite = await this.inviteService.verifyInviteToken({ inviteToken: req?.body?.token });
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: "Invite verified successfully",
|
||||
data: invite,
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default InviteController;
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import { AppError } from "@/utils/AppError.js";
|
||||
import {
|
||||
createMaintenanceWindowBodyValidation,
|
||||
@@ -8,7 +9,6 @@ import {
|
||||
getMaintenanceWindowsByTeamIdQueryValidation,
|
||||
deleteMaintenanceWindowByIdParamValidation,
|
||||
} from "@/validation/joi.js";
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
|
||||
const SERVICE_NAME = "maintenanceWindowController";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user