feat: add dual-date filter
This commit is contained in:
@@ -147,7 +147,7 @@ export const getAppointments = async (req, res) => {
|
||||
const limit = parseInt(req.query.limit) || 10;
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
const { date, startDate, endDate, search } = req.query;
|
||||
const { date, startDate, endDate, createdDate, createdStartDate, createdEndDate, search } = req.query;
|
||||
|
||||
const where = {};
|
||||
|
||||
@@ -161,11 +161,7 @@ export const getAppointments = async (req, res) => {
|
||||
|
||||
const end = new Date(date);
|
||||
end.setHours(23, 59, 59, 999);
|
||||
|
||||
where.date = {
|
||||
gte: start,
|
||||
lte: end,
|
||||
};
|
||||
where.date = { gte: start, lte: end };
|
||||
}
|
||||
|
||||
if (!hasSingleDate && hasRange) {
|
||||
@@ -188,6 +184,33 @@ export const getAppointments = async (req, res) => {
|
||||
where.date = dateFilter;
|
||||
}
|
||||
|
||||
const hasSingleCreatedDate = createdDate && createdDate.trim() !== '';
|
||||
const hasCreatedRange =
|
||||
(createdStartDate && createdStartDate.trim() !== '') || (createdEndDate && createdEndDate.trim() !== '');
|
||||
|
||||
if (hasSingleCreatedDate) {
|
||||
const start = new Date(createdDate);
|
||||
start.setHours(0, 0, 0, 0);
|
||||
const end = new Date(createdDate);
|
||||
end.setHours(23, 59, 59, 999);
|
||||
where.createdAt = { gte: start, lte: end };
|
||||
}
|
||||
|
||||
if (!hasSingleCreatedDate && hasCreatedRange) {
|
||||
const createdDateFilter = {};
|
||||
if (createdStartDate && createdStartDate.trim() !== '') {
|
||||
const start = new Date(createdStartDate);
|
||||
start.setHours(0, 0, 0, 0);
|
||||
createdDateFilter.gte = start;
|
||||
}
|
||||
if (createdEndDate && createdEndDate.trim() !== '') {
|
||||
const end = new Date(createdEndDate);
|
||||
end.setHours(23, 59, 59, 999);
|
||||
createdDateFilter.lte = end;
|
||||
}
|
||||
where.createdAt = createdDateFilter;
|
||||
}
|
||||
|
||||
if (search && search.trim() !== '') {
|
||||
where.OR = [
|
||||
{ name: { contains: search, mode: 'insensitive' } },
|
||||
|
||||
@@ -431,7 +431,17 @@ export const getPackageBySlug = async (req, res) => {
|
||||
|
||||
export const getAllInquiries = async (req, res) => {
|
||||
try {
|
||||
const { page = 1, limit = 10, filterDate, startDate, endDate } = req.query;
|
||||
const {
|
||||
page = 1,
|
||||
limit = 10,
|
||||
filterDate,
|
||||
startDate,
|
||||
endDate,
|
||||
createdDate,
|
||||
createdStartDate,
|
||||
createdEndDate,
|
||||
search,
|
||||
} = req.query;
|
||||
|
||||
const queryPage = parseInt(page);
|
||||
const queryLimit = parseInt(limit);
|
||||
@@ -439,6 +449,15 @@ export const getAllInquiries = async (req, res) => {
|
||||
|
||||
let where = {};
|
||||
|
||||
if (search && search.trim() !== '') {
|
||||
where.OR = [
|
||||
{ fullName: { contains: search, mode: 'insensitive' } },
|
||||
{ mobileNumber: { contains: search } },
|
||||
{ email: { contains: search, mode: 'insensitive' } },
|
||||
{ healthPackage: { name: { contains: search, mode: 'insensitive' } } },
|
||||
];
|
||||
}
|
||||
|
||||
if (filterDate) {
|
||||
where.preferredDate = {
|
||||
gte: new Date(`${filterDate}T00:00:00.000Z`),
|
||||
@@ -454,6 +473,21 @@ export const getAllInquiries = async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (createdDate) {
|
||||
where.createdAt = {
|
||||
gte: new Date(`${createdDate}T00:00:00.000Z`),
|
||||
lte: new Date(`${createdDate}T23:59:59.999Z`),
|
||||
};
|
||||
} else if (createdStartDate || createdEndDate) {
|
||||
where.createdAt = {};
|
||||
if (createdStartDate) {
|
||||
where.createdAt.gte = new Date(`${createdStartDate}T00:00:00.000Z`);
|
||||
}
|
||||
if (createdEndDate) {
|
||||
where.createdAt.lte = new Date(`${createdEndDate}T23:59:59.999Z`);
|
||||
}
|
||||
}
|
||||
|
||||
const [total, inquiries] = await prisma.$transaction([
|
||||
prisma.healthPackageInquiry.count({ where }),
|
||||
prisma.healthPackageInquiry.findMany({
|
||||
|
||||
Reference in New Issue
Block a user