Merge branch 'paritosh-main1' of http://git.wdipl.com/Mayank.Mishra/MinglarBackendNestJS into sprint1
This commit is contained in:
@@ -11,11 +11,6 @@ export const hostBankDetailsSchema = z.object({
|
||||
.nonempty("Account holder name is required")
|
||||
.min(2, { message: "Account holder name must be at least 2 characters" }),
|
||||
|
||||
ifscCode: z
|
||||
.string()
|
||||
.nonempty("IFSC code is required")
|
||||
.regex(/^[A-Z]{4}0[A-Z0-9]{6}$/, { message: "Invalid IFSC code format" }),
|
||||
|
||||
bankXid: z
|
||||
.number()
|
||||
.int({ message: "Bank ID must be an integer" })
|
||||
|
||||
@@ -90,5 +90,6 @@ export class AddPaymentDetailsDTO {
|
||||
this.accountHolderName = accountHolderName;
|
||||
this.ifscCode = ifscCode;
|
||||
this.hostXid = hostXid;
|
||||
this.currencyXid = currencyXid;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { PrismaService } from '../../../../../common/database/prisma.service';
|
||||
import { safeHandler } from '../../../../../common/utils/handlers/safeHandler';
|
||||
import ApiError from '../../../../../common/utils/helper/ApiError';
|
||||
import { HostService } from '../../../services/host.service';
|
||||
import { string } from 'zod';
|
||||
import { paginationService } from '../../../../../common/utils/pagination/pagination.service';
|
||||
|
||||
|
||||
const prismaService = new PrismaService();
|
||||
@@ -29,11 +29,18 @@ export const handler = safeHandler(async (
|
||||
// Verify token and get user info
|
||||
const userInfo = await verifyHostToken(token);
|
||||
|
||||
// Get pagination params from event
|
||||
const paginationParams = paginationService.getPaginationFromEvent(event);
|
||||
const paginationOptions = paginationService.parsePaginationParams(paginationParams);
|
||||
|
||||
// Read optional search query (supports ?search= or ?q=)
|
||||
const search = event.queryStringParameters?.search || event.queryStringParameters?.q || undefined;
|
||||
|
||||
const data = await hostService.getAllHostActivity(search ? String(search) : undefined, Number(userInfo.id));
|
||||
const result = await hostService.getAllHostActivity(
|
||||
search ? String(search) : undefined,
|
||||
Number(userInfo.id),
|
||||
paginationOptions
|
||||
);
|
||||
|
||||
|
||||
return {
|
||||
@@ -45,8 +52,7 @@ export const handler = safeHandler(async (
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'Data retrieved successfully',
|
||||
data,
|
||||
|
||||
...result,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -33,7 +33,7 @@ export const handler = safeHandler(async (
|
||||
}
|
||||
|
||||
// Parse request body
|
||||
let body: { bankXid?: number; bankBranchXid?: number; accountNumber?: string; confirmAccountNumber?: string; accountHolderName?: string; ifscCode?: string; currencyXid?: number };
|
||||
let body: { bankXid?: number; bankBranchXid?: number; accountNumber?: string; confirmAccountNumber?: string; accountHolderName?: string; currencyXid?: number };
|
||||
|
||||
try {
|
||||
body = event.body ? JSON.parse(event.body) : {};
|
||||
@@ -54,7 +54,16 @@ export const handler = safeHandler(async (
|
||||
|
||||
const validatedData = validationResult.data;
|
||||
|
||||
await hostService.addPaymentDetails(validatedData);
|
||||
// Fetch IFSC code from bank branch
|
||||
const bankBranch = await hostService.getBankBranchById(validatedData.bankBranchXid);
|
||||
if (!bankBranch) {
|
||||
throw new ApiError(404, 'Bank branch not found');
|
||||
}
|
||||
|
||||
await hostService.addPaymentDetails({
|
||||
...validatedData,
|
||||
ifscCode: bankBranch.ifscCode,
|
||||
});
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
|
||||
@@ -353,6 +353,17 @@ export class HostService {
|
||||
return true;
|
||||
}
|
||||
|
||||
async getBankBranchById(bankBranchXid: number) {
|
||||
return await this.prisma.bankBranches.findUnique({
|
||||
where: { id: bankBranchXid },
|
||||
select: {
|
||||
id: true,
|
||||
ifscCode: true,
|
||||
bankXid: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async addPaymentDetails(data: AddPaymentDetailsDTO) {
|
||||
return await this.prisma.$transaction(async (tx) => {
|
||||
const addedPaymentDetails = await tx.hostBankDetails.create({
|
||||
@@ -373,35 +384,43 @@ export class HostService {
|
||||
});
|
||||
}
|
||||
|
||||
async getAllHostActivity(search?: string, user_xid?: number) {
|
||||
async getAllHostActivity(search?: string, user_xid?: number, paginationOptions?: { page: number; limit: number; skip: number }) {
|
||||
const hostDetails = await this.prisma.hostHeader.findFirst({
|
||||
where: { userXid: user_xid, isActive: true }
|
||||
})
|
||||
|
||||
const hostAllActivities = await this.prisma.activities.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
hostXid: hostDetails.id,
|
||||
},
|
||||
include: {
|
||||
ActivitiesMedia: true,
|
||||
ActivityAmDetails: {
|
||||
select: {
|
||||
accountManager: {
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
profileImage: true,
|
||||
emailAddress: true,
|
||||
roleXid: true,
|
||||
const whereClause = {
|
||||
isActive: true,
|
||||
hostXid: hostDetails.id,
|
||||
};
|
||||
|
||||
const [hostAllActivities, totalCount] = await Promise.all([
|
||||
this.prisma.activities.findMany({
|
||||
where: whereClause,
|
||||
include: {
|
||||
ActivitiesMedia: true,
|
||||
ActivityAmDetails: {
|
||||
select: {
|
||||
accountManager: {
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
profileImage: true,
|
||||
emailAddress: true,
|
||||
roleXid: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
activityType: true,
|
||||
},
|
||||
activityType: true,
|
||||
},
|
||||
});
|
||||
skip: paginationOptions?.skip || 0,
|
||||
take: paginationOptions?.limit || 10,
|
||||
orderBy: { id: 'desc' },
|
||||
}),
|
||||
this.prisma.activities.count({ where: whereClause }),
|
||||
]);
|
||||
|
||||
for (const activity of hostAllActivities) {
|
||||
|
||||
@@ -441,8 +460,12 @@ export class HostService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return hostAllActivities;
|
||||
const { paginationService } = require('@/common/utils/pagination/pagination.service');
|
||||
return paginationService.createPaginatedResponse(
|
||||
hostAllActivities,
|
||||
totalCount,
|
||||
paginationOptions || { page: 1, limit: 10, skip: 0 }
|
||||
);
|
||||
}
|
||||
|
||||
async acceptMinglarAgreement(user_xid: number) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { PrismaService } from '../../../../../common/database/prisma.service';
|
||||
import { MinglarService } from '../../../services/minglar.service';
|
||||
import ApiError from '../../../../../common/utils/helper/ApiError';
|
||||
import { verifyMinglarAdminToken } from '../../../../../common/middlewares/jwt/authForMinglarAdmin';
|
||||
import { HOST_SUGGESTION_TITLES } from '../../../../../common/utils/constants/minglar.constant';
|
||||
// import { HOST_SUGGESTION_TITLES } from '../../../../../common/utils/constants/minglar.constant';
|
||||
|
||||
const prismaService = new PrismaService();
|
||||
const minglarService = new MinglarService(prismaService);
|
||||
@@ -67,10 +67,10 @@ export const handler = safeHandler(async (
|
||||
}
|
||||
|
||||
// Validate title is one of the allowed types
|
||||
const allowedTitles = Object.values(HOST_SUGGESTION_TITLES);
|
||||
if (!allowedTitles.includes(title)) {
|
||||
throw new ApiError(400, `Invalid title. Allowed values: ${allowedTitles.join(', ')}`);
|
||||
}
|
||||
// const allowedTitles = Object.values(HOST_SUGGESTION_TITLES);
|
||||
// if (!allowedTitles.includes(title)) {
|
||||
// throw new ApiError(400, `Invalid title. Allowed values: ${allowedTitles.join(', ')}`);
|
||||
// }
|
||||
|
||||
// Add suggestion using service
|
||||
await minglarService.addPqqSuggestion(title, comments, activity_pqq_header_xid,user.id);
|
||||
|
||||
@@ -5,6 +5,7 @@ import { safeHandler } from '../../../../../common/utils/handlers/safeHandler';
|
||||
import ApiError from '../../../../../common/utils/helper/ApiError';
|
||||
import { PrePopulateService } from '../../../../prepopulate/services/prepopulate.service';
|
||||
import { MinglarService } from '../../../services/minglar.service';
|
||||
import { paginationService } from '../../../../../common/utils/pagination/pagination.service';
|
||||
|
||||
const prismaService = new PrismaService();
|
||||
const minglarService = new MinglarService(prismaService);
|
||||
@@ -30,11 +31,18 @@ export const handler = safeHandler(async (
|
||||
|
||||
const hostXid = Number(event.pathParameters?.id)
|
||||
|
||||
// Get pagination params from event
|
||||
const paginationParams = paginationService.getPaginationFromEvent(event);
|
||||
const paginationOptions = paginationService.parsePaginationParams(paginationParams);
|
||||
|
||||
// Read optional search query (supports ?search= or ?q=)
|
||||
const search = event.queryStringParameters?.search || event.queryStringParameters?.q || undefined;
|
||||
|
||||
const data = await minglarService.getAllHostActivityForMinglar(search ? String(search) : undefined, hostXid);
|
||||
const result = await minglarService.getAllHostActivityForMinglar(
|
||||
search ? String(search) : undefined,
|
||||
hostXid,
|
||||
paginationOptions
|
||||
);
|
||||
|
||||
|
||||
return {
|
||||
@@ -46,7 +54,7 @@ export const handler = safeHandler(async (
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'Data retrieved successfully',
|
||||
data,
|
||||
...result,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -255,48 +255,46 @@ export class MinglarService {
|
||||
});
|
||||
}
|
||||
|
||||
async getAllHostActivityForMinglar(search?: string, hostXid?: number) {
|
||||
|
||||
const where: any = {
|
||||
async getAllHostActivityForMinglar(search?: string, hostXid?: number, paginationOptions?: { page: number; limit: number; skip: number }) {
|
||||
const whereClause = {
|
||||
isActive: true,
|
||||
hostXid: hostXid
|
||||
...(hostXid ? { hostXid } : {}), // Add only if provided
|
||||
};
|
||||
|
||||
if (search && search.trim() !== '') {
|
||||
const q = search.trim();
|
||||
where.OR = [
|
||||
{ activityTypeName: { contains: q, mode: 'insensitive' } },
|
||||
{ interests: { interestName: { contains: q, mode: 'insensitive' } } },
|
||||
];
|
||||
}
|
||||
const hostActivities = await this.prisma.activities.findMany({
|
||||
where,
|
||||
include: {
|
||||
ActivitiesMedia: {
|
||||
select: {
|
||||
id: true,
|
||||
mediaFileName: true,
|
||||
mediaType: true,
|
||||
displayOrder: true,
|
||||
const [hostActivities, totalCount] = await Promise.all([
|
||||
this.prisma.activities.findMany({
|
||||
where: whereClause,
|
||||
include: {
|
||||
ActivitiesMedia: {
|
||||
select: {
|
||||
id: true,
|
||||
mediaFileName: true,
|
||||
mediaType: true,
|
||||
displayOrder: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
ActivityAmDetails: {
|
||||
select: {
|
||||
accountManager: {
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
profileImage: true,
|
||||
emailAddress: true,
|
||||
roleXid: true,
|
||||
ActivityAmDetails: {
|
||||
select: {
|
||||
accountManager: {
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
profileImage: true,
|
||||
emailAddress: true,
|
||||
roleXid: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
activityType: true,
|
||||
},
|
||||
activityType: true,
|
||||
},
|
||||
});
|
||||
skip: paginationOptions?.skip || 0,
|
||||
take: paginationOptions?.limit || 10,
|
||||
orderBy: { id: 'desc' },
|
||||
}),
|
||||
this.prisma.activities.count({ where: whereClause }),
|
||||
]);
|
||||
|
||||
// Process each activity
|
||||
for (const activity of hostActivities) {
|
||||
@@ -337,8 +335,12 @@ export class MinglarService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return hostActivities;
|
||||
const { paginationService } = require('@/common/utils/pagination/pagination.service');
|
||||
return paginationService.createPaginatedResponse(
|
||||
hostActivities,
|
||||
totalCount,
|
||||
paginationOptions || { page: 1, limit: 10, skip: 0 }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user