tududi/backend/scripts/test-query.js
Chris b0041bafe1
Fix today recurring missing (#548)
* Expose today task from a recurring series

* fixup! Expose today task from a recurring series

* fixup! fixup! Expose today task from a recurring series
2025-11-16 18:00:39 +02:00

56 lines
1.5 KiB
JavaScript

const { Task, sequelize } = require('../models');
const { Op } = require('sequelize');
async function testQuery() {
const whereClause = {
parent_task_id: null,
status: {
[Op.notIn]: [
Task.STATUS.DONE,
Task.STATUS.ARCHIVED,
'done',
'archived',
],
},
};
whereClause[Op.or] = [
{
[Op.and]: [
{
[Op.or]: [
{ recurrence_type: 'none' },
{ recurrence_type: null },
],
},
{ recurring_parent_id: null },
],
},
{
[Op.and]: [{ recurring_parent_id: { [Op.ne]: null } }],
},
];
// Log the SQL that will be generated
const query = Task.findAll({
where: whereClause,
attributes: ['id', 'name', 'recurrence_type', 'recurring_parent_id'],
logging: console.log,
});
console.log('\nThis query should:');
console.log(
'✓ Include: Regular tasks (recurrence_type = null/none, recurring_parent_id = null)'
);
console.log('✓ Include: Recurring instances (recurring_parent_id != null)');
console.log(
'✗ Exclude: Recurring parent templates (recurrence_type = daily/weekly/etc, recurring_parent_id = null)'
);
await sequelize.close();
}
testQuery().catch((err) => {
console.error(err);
process.exit(1);
});