Skip to content

Commit

Permalink
keep name after schedule completion or recreation
Browse files Browse the repository at this point in the history
  • Loading branch information
shaankhosla committed Sep 23, 2023
1 parent 89c5f15 commit 299d1b2
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/loot-core/src/server/schedules/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ async function checkIfScheduleExists(name, scheduleId) {
return true;
}

async function nameFromScheduleId(scheduleId) {
console.log(scheduleId);
let idForName = await db.first(

Check warning on line 213 in packages/loot-core/src/server/schedules/app.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎····'SELECT·name·from·schedules·WHERE·id·=·?',` with `'SELECT·name·from·schedules·WHERE·id·=·?',·[`
'SELECT name from schedules WHERE id = ?',
[scheduleId],

Check warning on line 215 in packages/loot-core/src/server/schedules/app.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `[scheduleId]` with `scheduleId`
);

Check warning on line 216 in packages/loot-core/src/server/schedules/app.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `]`
return idForName['name'];
}

export async function createSchedule({
schedule = null,
conditions = [],
Expand Down Expand Up @@ -274,13 +283,13 @@ export async function updateSchedule({
if (schedule.rule) {
throw new Error('You cannot change the rule of a schedule');
}

if (schedule.name) {
if (await checkIfScheduleExists(schedule.name, schedule.id)) {
let scheduleName = await nameFromScheduleId(schedule.id);
if (scheduleName) {
if (await checkIfScheduleExists(scheduleName, schedule.id)) {
throw new Error('There is already a schedule with this name');
}
} else {
schedule.name = null;
scheduleName = null;
}
// We need the rule if there are conditions
let rule;
Expand Down

0 comments on commit 299d1b2

Please sign in to comment.