Filters
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { db, logger } from '../config.js';
|
||||
import { qsos } from '../db/schema/index.js';
|
||||
import { max, sql, eq, and, desc } from 'drizzle-orm';
|
||||
import { max, sql, eq, and, or, desc, like } from 'drizzle-orm';
|
||||
import { updateJobProgress } from './job-queue.service.js';
|
||||
import { parseADIF, normalizeBand, normalizeMode } from '../utils/adif-parser.js';
|
||||
|
||||
@@ -328,6 +328,35 @@ export async function getUserQSOs(userId, filters = {}, options = {}) {
|
||||
if (filters.mode) conditions.push(eq(qsos.mode, filters.mode));
|
||||
if (filters.confirmed) conditions.push(eq(qsos.lotwQslRstatus, 'Y'));
|
||||
|
||||
// Confirmation type filter: lotw, dcl, both, none
|
||||
if (filters.confirmationType) {
|
||||
if (filters.confirmationType === 'lotw') {
|
||||
conditions.push(eq(qsos.lotwQslRstatus, 'Y'));
|
||||
} else if (filters.confirmationType === 'dcl') {
|
||||
conditions.push(eq(qsos.dclQslRstatus, 'Y'));
|
||||
} else if (filters.confirmationType === 'both') {
|
||||
conditions.push(and(
|
||||
eq(qsos.lotwQslRstatus, 'Y'),
|
||||
eq(qsos.dclQslRstatus, 'Y')
|
||||
));
|
||||
} else if (filters.confirmationType === 'none') {
|
||||
conditions.push(and(
|
||||
sql`${qsos.lotwQslRstatus} IS NULL OR ${qsos.lotwQslRstatus} != 'Y'`,
|
||||
sql`${qsos.dclQslRstatus} IS NULL OR ${qsos.dclQslRstatus} != 'Y'`
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Search filter: callsign, entity, or grid
|
||||
if (filters.search) {
|
||||
const searchTerm = `%${filters.search}%`;
|
||||
conditions.push(or(
|
||||
like(qsos.callsign, searchTerm),
|
||||
like(qsos.entity, searchTerm),
|
||||
like(qsos.grid, searchTerm)
|
||||
));
|
||||
}
|
||||
|
||||
const allResults = await db.select().from(qsos).where(and(...conditions));
|
||||
const totalCount = allResults.length;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user