Add new endpoints for activity types and frequencies, and implement email notifications for AM assignments

This commit is contained in:
paritosh18
2025-11-22 19:25:07 +05:30
parent 15c85686c6
commit d0b2de3f18
9 changed files with 353 additions and 84 deletions

View File

@@ -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 { PrePopulateService } from '../services/prepopulate.service';
import { verifyHostToken } from '@/common/middlewares/jwt/authForHost';
const prismaService = new PrismaService();
const prePopulateService = new PrePopulateService(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 verifyHostToken(token);
const result = await prePopulateService.getAllFrequencies();
return {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
},
body: JSON.stringify({
success: true,
message: 'Data retrieved successfully',
data: result,
}),
};
});

View File

@@ -1,65 +1,73 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from '../../../common/database/prisma.service';
@Injectable()
export class PrePopulateService {
constructor(private prisma: PrismaService) { }
constructor(private prisma: PrismaService) {}
async getAllBankDetails() {
return await this.prisma.banks.findMany({
where: {
isActive: true,
deletedAt: null,
async getAllBankDetails() {
return await this.prisma.banks.findMany({
where: {
isActive: true,
deletedAt: null,
},
include: {
BankBranches: {
select: {
id: true,
branchAddress: true,
ifscCode: true,
},
},
},
});
}
async getAllCurrencyDetails() {
return await this.prisma.currencies.findMany({
where: {
isActive: true,
deletedAt: null,
},
});
}
async getAllPQQQuesAndAns() {
return await this.prisma.pQQCategories.findMany({
where: { isActive: true },
include: {
pqqsubCategories: {
include: {
questions: {
include: {
PQQAnswers: {
orderBy: {
displayOrder: 'asc',
},
},
},
orderBy: {
displayOrder: 'asc',
},
},
include: {
BankBranches: {
select: {
id: true,
branchAddress: true,
ifscCode: true
}
}
}
})
}
async getAllCurrencyDetails() {
return await this.prisma.currencies.findMany({
where: {
isActive: true,
deletedAt: null,
},
})
}
async getAllPQQQuesAndAns() {
return await this.prisma.pQQCategories.findMany({
where: { isActive: true },
include: {
pqqsubCategories: {
include: {
questions: {
include: {
PQQAnswers: {
orderBy: {
displayOrder: 'asc'
}
}
},
orderBy: {
displayOrder: 'asc'
}
}
},
orderBy: { displayOrder: 'asc' }
}
},
orderBy: { displayOrder: 'asc' }
});
}
},
orderBy: { displayOrder: 'asc' },
},
},
orderBy: { displayOrder: 'asc' },
});
}
async getAllFrequencies() {
return await this.prisma.frequencies.findMany({
where: {
isActive: true,
deletedAt: null,
},
select: {
id: true,
frequencyName:true
},
});
}
}