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' } },
|
||||
|
||||
Reference in New Issue
Block a user