31 lines
890 B
TypeScript
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]);
|
|
});
|
|
}
|