Made accept activity application from AM api

This commit is contained in:
2025-12-24 15:00:02 +05:30
parent 60ee1f5f21
commit d4b5153814
5 changed files with 144 additions and 3 deletions

View File

@@ -343,6 +343,22 @@ acceptPQByAM:
path: /minglaradmin/hosthub/hosts/accept-pq-by-am
method: patch
acceptActivityDetailsApplicationByAM:
handler: src/modules/minglaradmin/handlers/hosthub/hosts/acceptActivityApplicationByAM.handler
memorySize: 384
package:
patterns:
- 'src/modules/minglaradmin/handlers/hosthub/hosts/acceptActivityApplicationByAM**'
- 'src/modules/minglaradmin/services/**'
- ${file(./serverless/patterns/base.yml):pattern1}
- ${file(./serverless/patterns/base.yml):pattern2}
- ${file(./serverless/patterns/base.yml):pattern3}
- ${file(./serverless/patterns/base.yml):pattern4}
events:
- httpApi:
path: /minglaradmin/hosthub/hosts/accept-activity-application-by-am
method: patch
rejectHostApplication:
handler: src/modules/minglaradmin/handlers/hosthub/onboarding/rejectHostApplication.handler
memorySize: 384
@@ -407,7 +423,6 @@ getAllPQPDetailsForAM:
path: /minglaradmin/hosthub/pqp/pqp-details-for-am/{activityXid}
method: get
getSuggestionsForAM:
handler: src/modules/minglaradmin/handlers/hosthub/onboarding/showSuggestionToAM.handler
memorySize: 384

View File

@@ -57,7 +57,7 @@ export const ACTIVITY_DISPLAY_STATUS = {
ACTIVITY_DRAFT: 'Draft - Activity',
ACTIVITY_IN_REVIEW: 'In Review',
ACTIVITY_TO_REVIEW: 'To Review',
ACTIVITY_NOT_LISTED: 'Not Listed',
NOT_LISTED: 'Not Listed',
ACTIVITY_LISTED: 'Listed',
ACTIVITY_UNLISTED: 'Un Listed',
};
@@ -95,6 +95,6 @@ export const ACTIVITY_AM_DISPLAY_STATUS = {
ACTIVITY_DRAFT: 'Draft - Activity',
ACTIVITY_NEW: 'To Review',
ACTIVITY_ENHANCING: 'Enhancing',
ACTIVITY_NOT_LISTED: 'Not Listed',
NOT_LISTED: 'Not Listed',
ACTIVITY_LISTED: 'Listed',
};

View File

@@ -0,0 +1,59 @@
import { verifyMinglarAdminToken } from '../../../../../common/middlewares/jwt/authForMinglarAdmin';
import { MinglarService } from '../../../services/minglar.service';
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
import { prismaClient } from '../../../../../common/database/prisma.lambda.service';
import { safeHandler } from '../../../../../common/utils/handlers/safeHandler';
import ApiError from '../../../../../common/utils/helper/ApiError';
import { sendActivityAcceptanceMailtoHost } from '../../../../minglaradmin/services/approvalMailtoHost.service';
const minglarService = new MinglarService(prismaClient);
interface Body {
activityId: number;
}
export const handler = safeHandler(async (
event: APIGatewayProxyEvent,
context?: Context
): Promise<APIGatewayProxyResult> => {
const token = event.headers['x-auth-token'] || event.headers['X-Auth-Token'];
if (!token) throw new ApiError(401, 'This is a protected route. Please provide a valid token.');
const userInfo = await verifyMinglarAdminToken(token);
// Parse request body
let body: Body;
try {
body = event.body ? JSON.parse(event.body) : {};
} catch (error) {
throw new ApiError(400, 'Invalid JSON in request body');
}
const { activityId } = body;
if (!activityId) {
throw new ApiError(400, 'activityId is required');
}
await minglarService.acceptActivityApplicationByAM(
Number(activityId),
Number(userInfo.id)
);
const hostXid = await minglarService.getHostXidByActivityId(activityId)
const hostDetails = await minglarService.getUserDetails(hostXid)
await sendActivityAcceptanceMailtoHost(hostDetails.emailAddress, hostDetails.firstName)
return {
statusCode: 201,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
},
body: JSON.stringify({
success: true,
message: 'Approved activity details application successfully',
data: null,
}),
};
});

View File

@@ -112,3 +112,41 @@ export async function sendAMPQQAcceptanceMailtoHost(
throw new ApiError(500, "Failed to send OTP to minglar admin via email.");
}
}
export async function sendActivityAcceptanceMailtoHost(
emailAddress: string,
name: string
): Promise<{
sent: boolean;
// messageId: string
}> {
const subject = "Approval for your activity details application";
const htmlContent = `
<p>Dear ${name},</p>
<p>Congratulations, Your activity details application to minglar admin has been approved.</p>
<p>You can start getting orders for your activity.</p>
<p>You can login to your account using the link below:<br/>
<strong>Link:</strong> ${config.HOST_LINK} </p>
<p>Best regards,<br/>Minglar Team</p>
`;
try {
const result = await brevoService.sendEmail({
recipients: [{ email: emailAddress }],
subject,
htmlContent,
});
console.log("📧 Email sent successfully:", result);
return {
sent: true,
// messageId: result.messageId
};
} catch (err) {
console.error("Brevo email send failed:", err);
throw new ApiError(500, "Failed to send OTP to minglar admin via email.");
}
}

View File

@@ -1794,6 +1794,35 @@ export class MinglarService {
})
}
async acceptActivityApplicationByAM(activityId: number, user_xid: number) {
return await this.prisma.$transaction(async (tx) => {
await tx.activities.update({
where: {
id: activityId,
isActive: true
},
data: {
activityInternalStatus: ACTIVITY_INTERNAL_STATUS.ACTIVITY_APPROVED,
activityDisplayStatus: ACTIVITY_DISPLAY_STATUS.NOT_LISTED,
amInternalStatus: ACTIVITY_AM_INTERNAL_STATUS.ACTIVITY_APPROVED,
amDisplayStatus: ACTIVITY_AM_DISPLAY_STATUS.NOT_LISTED
}
})
await tx.activityTrack.create({
data: {
activityXid: activityId,
trackType: ACTIVITY_TRACK_TYPE.ACTIVITY,
trackStatus: ACTIVITY_TRACK_STATUS.ACCEPTED_BY_AM,
updatedByXid: user_xid,
updatedByRole: ROLE_NAME.ACCOUNT_MANAGER,
updatedOn: new Date()
}
})
})
}
async getHostDetailsById(host_xid) {
const host = await this.prisma.hostHeader.findFirst({
where: { id: host_xid },