contact recoed list
This commit is contained in:
@ -10,6 +10,8 @@ export async function GET(request: NextRequest) {
|
||||
// Get query parameters
|
||||
const url = new URL(request.url);
|
||||
const customerId = url.searchParams.get('customerId');
|
||||
const dateFrom = url.searchParams.get('dateFrom');
|
||||
const dateTo = url.searchParams.get('dateTo');
|
||||
|
||||
// Build query
|
||||
const queryOptions: any = {
|
||||
@ -17,9 +19,33 @@ export async function GET(request: NextRequest) {
|
||||
relations: ['customer']
|
||||
};
|
||||
|
||||
// Build where clause
|
||||
let whereClause: any = {};
|
||||
|
||||
// Filter by customer if customerId is provided
|
||||
if (customerId) {
|
||||
queryOptions.where = { customerId };
|
||||
whereClause.customerId = customerId;
|
||||
}
|
||||
|
||||
// Filter by date range if provided
|
||||
if (dateFrom || dateTo) {
|
||||
whereClause.createdAt = {};
|
||||
|
||||
if (dateFrom) {
|
||||
whereClause.createdAt.gte = new Date(dateFrom);
|
||||
}
|
||||
|
||||
if (dateTo) {
|
||||
// Set the date to the end of the day for inclusive filtering
|
||||
const endDate = new Date(dateTo);
|
||||
endDate.setHours(23, 59, 59, 999);
|
||||
whereClause.createdAt.lte = endDate;
|
||||
}
|
||||
}
|
||||
|
||||
// Add where clause to query options if not empty
|
||||
if (Object.keys(whereClause).length > 0) {
|
||||
queryOptions.where = whereClause;
|
||||
}
|
||||
|
||||
const contactRecords = await contactRecordRepository.find(queryOptions);
|
||||
|
||||
Reference in New Issue
Block a user