Files
carry-your-live/carry-your-live/src/utils/repeatProfileActions.ts
T
2026-08-09 21:42:54 +02:00

31 lines
890 B
TypeScript

import { database, collections } from '../database';
import { Repeat } from '@/types';
import { recordTombstonesInBatch } from '../database/tombstones';
export async function createRepeatProfile(
name: string,
repeat: Repeat,
interval: number,
days: number[]
): Promise<void> {
const now = new Date();
await database.write(async () => {
await collections.repeatProfiles.create((p) => {
p.name = name.trim();
p.repeat = repeat;
p.repeatInterval = interval || 1;
p.repeatDays = [...days].sort().join(',');
p.createdAt = now;
p.updatedAt = now;
});
});
}
export async function deleteRepeatProfile(id: string): Promise<void> {
await database.write(async () => {
const profile = await collections.repeatProfiles.find(id);
await profile.destroyPermanently();
await recordTombstonesInBatch('repeatProfiles', [id]);
});
}