fixed minor issues
This commit is contained in:
@@ -30,7 +30,7 @@ export const handler = safeHandler(async (
|
||||
throw new ApiError(400, 'activityTypeXid is required');
|
||||
}
|
||||
|
||||
const created = await hostService.createActivity(
|
||||
await hostService.createActivity(
|
||||
userInfo.id,
|
||||
Number(activityTypeXid),
|
||||
frequenciesXid ? Number(frequenciesXid) : undefined,
|
||||
|
||||
@@ -182,17 +182,17 @@ export const handler = safeHandler(async (event: APIGatewayProxyEvent): Promise<
|
||||
if (folderType === 'logo') {
|
||||
// Logo: Documents/Host/logo/{HostID}/{sanitized_filename}
|
||||
const sanitizedFileName = sanitizeFileName(originalName);
|
||||
s3Key = `Documents/Host/logo/${hostId}/${sanitizedFileName}`;
|
||||
s3Key = `Documents/Host/${hostId}/logo/${sanitizedFileName}`;
|
||||
} else if (folderType === 'documents' && documentTypeXid && fieldName) {
|
||||
// Host Documents: Documents/Host/documents/{HostID}/{documentTypeXid}_{fieldName}.{extension}
|
||||
const fileName = `${documentTypeXid}_${fieldName}.${fileExtension}`;
|
||||
const sanitizedFileName = sanitizeFileName(fileName);
|
||||
s3Key = `Documents/Host/documents/${hostId}/${sanitizedFileName}`;
|
||||
s3Key = `Documents/Host/${hostId}/documents/${sanitizedFileName}`;
|
||||
} else if (folderType === 'parent_company' && documentTypeXid && fieldName) {
|
||||
// Parent Documents: Documents/Host/parent_company/{HostID}/{documentTypeXid}_{fieldName}.{extension}
|
||||
const fileName = `${documentTypeXid}_${fieldName}.${fileExtension}`;
|
||||
const sanitizedFileName = sanitizeFileName(fileName);
|
||||
s3Key = `Documents/Host/parent_company/${hostId}/${sanitizedFileName}`;
|
||||
s3Key = `Documents/Host/${hostId}/parent_company/${sanitizedFileName}`;
|
||||
} else {
|
||||
throw new ApiError(400, 'Invalid folder type or missing documentTypeXid/fieldName');
|
||||
}
|
||||
|
||||
@@ -21,22 +21,25 @@ export const handler = safeHandler(async (
|
||||
const userInfo = await verifyHostToken(token);
|
||||
const userId = Number(userInfo.id);
|
||||
|
||||
let body: { activity_xid: number };
|
||||
const activity_xid = event.queryStringParameters?.activity_xid
|
||||
? Number(event.queryStringParameters.activity_xid)
|
||||
: null;
|
||||
|
||||
try {
|
||||
body = event.body ? JSON.parse(event.body) : {};
|
||||
} catch (error) {
|
||||
throw new ApiError(400, 'Invalid JSON in request body');
|
||||
}
|
||||
|
||||
const { activity_xid } = body;
|
||||
if(!activity_xid){
|
||||
throw new ApiError(400, "Activity id is required.")
|
||||
// Validate it
|
||||
if (!activity_xid || isNaN(activity_xid)) {
|
||||
throw new ApiError(400, "Activity id is required and must be a number.");
|
||||
}
|
||||
|
||||
// Fetch user with their HostHeader stepper info
|
||||
const pqqQuestionDetails = await hostService.getLatestQuestionDetailsPQQ(activity_xid);
|
||||
|
||||
const result = {
|
||||
pqqQuestionXid: pqqQuestionDetails.pqqQuestionXid,
|
||||
pqqAnswerXid: pqqQuestionDetails.pqqAnswerXid,
|
||||
pqqSubCategoryXid: pqqQuestionDetails.pqqQuestions.pqqSubCategoryXid,
|
||||
categoryXid: pqqQuestionDetails.pqqQuestions.pqqSubCategories.categoryXid
|
||||
}
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
@@ -45,8 +48,8 @@ export const handler = safeHandler(async (
|
||||
},
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'Stepper information retrieved successfully',
|
||||
data: pqqQuestionDetails,
|
||||
message: 'Latest information retrieved successfully',
|
||||
data: result,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -165,9 +165,9 @@ export const handler = safeHandler(async (event: APIGatewayProxyEvent): Promise<
|
||||
if (!pqqQuestionXid || isNaN(pqqQuestionXid)) throw new ApiError(400, "Valid pqqQuestionXid is required");
|
||||
if (!pqqAnswerXid || isNaN(pqqAnswerXid)) throw new ApiError(400, "Valid pqqAnswerXid is required");
|
||||
|
||||
console.log(`📝 Processing - Activity: ${activityXid}, Question: ${pqqQuestionXid}, Answer: ${pqqAnswerXid}`);
|
||||
console.log(`💬 Comments: ${comments ? 'Provided' : 'Not provided'}`);
|
||||
console.log(`📎 Files: ${files.length}`);
|
||||
// console.log(`📝 Processing - Activity: ${activityXid}, Question: ${pqqQuestionXid}, Answer: ${pqqAnswerXid}`);
|
||||
// console.log(`💬 Comments: ${comments ? 'Provided' : 'Not provided'}`);
|
||||
// console.log(`📎 Files: ${files.length}`);
|
||||
|
||||
// 5) UPSERT: Check if header already exists for this combination
|
||||
const existingHeader = await pqqService.findHeaderByCompositeKey(
|
||||
|
||||
@@ -9,7 +9,7 @@ import { z } from 'zod';
|
||||
import { hostCompanyDetailsSchema } from '@/common/utils/validation/host/hostCompanyDetails.validation';
|
||||
import { HOST_STATUS_DISPLAY, HOST_STATUS_INTERNAL, STEPPER } from '@/common/utils/constants/host.constant';
|
||||
import { MINGLAR_STATUS_DISPLAY, MINGLAR_STATUS_INTERNAL } from '@/common/utils/constants/minglar.constant';
|
||||
import { ROLE } from '@/common/utils/constants/common.constant';
|
||||
import { ROLE, USER_STATUS } from '@/common/utils/constants/common.constant';
|
||||
import { getPresignedUrl } from '@/common/middlewares/aws/getPreSignedUrl';
|
||||
import config from '@/config/config';
|
||||
|
||||
@@ -192,7 +192,7 @@ export class HostService {
|
||||
// Update user with hashed password
|
||||
await this.prisma.user.update({
|
||||
where: { id: user.id },
|
||||
data: { userPassword: hashedPassword },
|
||||
data: { userPassword: hashedPassword, isEmailVerfied: true, userStatus: USER_STATUS.ACTIVE },
|
||||
});
|
||||
|
||||
return true;
|
||||
@@ -249,7 +249,20 @@ export class HostService {
|
||||
async getLatestQuestionDetailsPQQ(activity_xid: number) {
|
||||
return await this.prisma.activityPQQheader.findFirst({
|
||||
where: { activityXid: activity_xid, isActive: true },
|
||||
select: { pqqQuestionXid: true, pqqAnswerXid: true },
|
||||
select: {
|
||||
pqqQuestionXid: true,
|
||||
pqqAnswerXid: true,
|
||||
pqqQuestions: {
|
||||
select: {
|
||||
pqqSubCategoryXid: true,
|
||||
pqqSubCategories: {
|
||||
select: {
|
||||
categoryXid: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
orderBy: { id: 'desc' }
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import { verifyOnlyMinglarAdminToken } from '@/common/middlewares/jwt/authForOnlyMinglarAdmin';
|
||||
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
|
||||
import { PrismaService } from '../../../common/database/prisma.service';
|
||||
import { safeHandler } from '../../../common/utils/handlers/safeHandler';
|
||||
import ApiError from '../../../common/utils/helper/ApiError';
|
||||
import { MinglarService } from '../services/minglar.service';
|
||||
|
||||
const prismaService = new PrismaService();
|
||||
const minglarService = new MinglarService(prismaService);
|
||||
|
||||
export const handler = safeHandler(async (
|
||||
event: APIGatewayProxyEvent,
|
||||
context?: Context
|
||||
): Promise<APIGatewayProxyResult> => {
|
||||
// Extract token from headers
|
||||
const token = event.headers['x-auth-token'] || event.headers['X-Auth-Token']
|
||||
if(!token) {
|
||||
throw new ApiError(400, 'This is a protected route. Please provide a valid token.');
|
||||
}
|
||||
|
||||
// Authenticate user using the shared authForHost function
|
||||
await verifyOnlyMinglarAdminToken(token);
|
||||
|
||||
const response = await minglarService.getAllInvitedCoadminAndAM();
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'Data retrieved successfully',
|
||||
data: response,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -494,7 +494,7 @@ export class MinglarService {
|
||||
notIn: [ROLE.CO_ADMIN, ROLE.ACCOUNT_MANAGER]
|
||||
},
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Add search filter if search query is provided
|
||||
if (search && search.trim() !== '') {
|
||||
@@ -585,7 +585,7 @@ export class MinglarService {
|
||||
companyName: host.companyName || null,
|
||||
city: host.cities || null,
|
||||
state: host.states || null,
|
||||
country: host.countries || null,
|
||||
country: host.countries || null,
|
||||
assignedOn: host.assignedOn || null,
|
||||
}));
|
||||
}
|
||||
@@ -644,6 +644,32 @@ export class MinglarService {
|
||||
}));
|
||||
}
|
||||
|
||||
async getAllInvitedCoadminAndAM() {
|
||||
return await this.prisma.user.findMany({
|
||||
where: {
|
||||
roleXid: {
|
||||
in: [
|
||||
ROLE.MINGLAR_ADMIN, // Admin
|
||||
ROLE.CO_ADMIN, // Co-Admin
|
||||
ROLE.ACCOUNT_MANAGER // AM
|
||||
]
|
||||
},
|
||||
isActive: true,
|
||||
userStatus: {
|
||||
not: USER_STATUS.DE_ACTIVATED // Exclude DE_ACTIVATED status
|
||||
},
|
||||
},
|
||||
include: {
|
||||
role: {
|
||||
select: {
|
||||
id: true,
|
||||
roleName: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async assignAMToHost(userId: number, hostXid: number, accountManagerXid: number) {
|
||||
const hostDetails = await this.prisma.hostHeader.findFirst({
|
||||
@@ -685,8 +711,8 @@ export class MinglarService {
|
||||
if (!accountManagerXid) return false;
|
||||
|
||||
const amUser = await this.prisma.user.findUnique({
|
||||
where: { id: accountManagerXid ,isActive:true},
|
||||
select: { emailAddress: true},
|
||||
where: { id: accountManagerXid, isActive: true },
|
||||
select: { emailAddress: true },
|
||||
});
|
||||
|
||||
if (!amUser || !amUser.emailAddress) {
|
||||
|
||||
Reference in New Issue
Block a user