mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-11 12:43:09 -05:00
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { ScheduleEntity } from '../../types/models';
|
|
import * as db from '../db';
|
|
|
|
import { GOAL_PREFIX, TEMPLATE_PREFIX } from './template-notes';
|
|
|
|
/* eslint-disable rulesdir/typography */
|
|
export async function resetCategoryGoalDefsWithNoTemplates(): Promise<void> {
|
|
await db.run(
|
|
`
|
|
UPDATE categories
|
|
SET goal_def = NULL
|
|
WHERE id NOT IN (SELECT n.id
|
|
FROM notes n
|
|
WHERE lower(note) LIKE '%${TEMPLATE_PREFIX}%'
|
|
OR lower(note) LIKE '%${GOAL_PREFIX}%')
|
|
`,
|
|
);
|
|
}
|
|
|
|
/* eslint-enable rulesdir/typography */
|
|
|
|
export type CategoryWithTemplateNote = {
|
|
id: string;
|
|
name: string;
|
|
note: string;
|
|
};
|
|
|
|
export async function getCategoriesWithTemplateNotes(): Promise<
|
|
CategoryWithTemplateNote[]
|
|
> {
|
|
return await db.all(
|
|
`
|
|
SELECT c.id AS id, c.name as name, n.note AS note
|
|
FROM notes n
|
|
JOIN categories c ON n.id = c.id
|
|
WHERE c.id = n.id
|
|
AND c.tombstone = 0
|
|
AND (lower(note) LIKE '%${TEMPLATE_PREFIX}%'
|
|
OR lower(note) LIKE '%${GOAL_PREFIX}%')
|
|
`,
|
|
);
|
|
}
|
|
|
|
export async function getActiveSchedules(): Promise<ScheduleEntity[]> {
|
|
return await db.all(
|
|
'SELECT id, rule, active, completed, posts_transaction, tombstone, name from schedules WHERE name NOT NULL AND tombstone = 0',
|
|
);
|
|
}
|