refactor(UserSchedule): index by a unique id rather than name (#166)
* refactor(UserSchedule): index by a unique id rather than name * refactor: Update parameter names in schedule function jsdocs * refactor: change more instances of .name to .id * refactor: Fix typo in variable name and update references * refactor: Remove console.log statement * fix(chromatic): Update ScheduleListItem story * refactor: remove unused eslint rule
This commit is contained in:
@@ -2,19 +2,19 @@ import { UserScheduleStore } from '@shared/storage/UserScheduleStore';
|
||||
|
||||
/**
|
||||
* Renames a schedule with the specified name to a new name.
|
||||
* @param scheduleName - The name of the schedule to be renamed.
|
||||
* @param scheduleId - The id of the schedule to be renamed.
|
||||
* @param newName - The new name for the schedule.
|
||||
* @returns A promise that resolves to a string if there is an error, or undefined if the schedule is renamed successfully.
|
||||
*/
|
||||
export default async function renameSchedule(scheduleName: string, newName: string): Promise<string | undefined> {
|
||||
export default async function renameSchedule(scheduleId: string, newName: string): Promise<string | undefined> {
|
||||
const schedules = await UserScheduleStore.get('schedules');
|
||||
const scheduleIndex = schedules.findIndex(schedule => schedule.name === scheduleName);
|
||||
const scheduleIndex = schedules.findIndex(schedule => schedule.id === scheduleId);
|
||||
if (scheduleIndex === -1) {
|
||||
return `Schedule ${scheduleName} does not exist`;
|
||||
}
|
||||
if (schedules.find(schedule => schedule.name === newName)) {
|
||||
return `Schedule ${newName} already exists`;
|
||||
return `Schedule ${scheduleId} does not exist`;
|
||||
}
|
||||
// if (schedules.find(schedule => schedule.name === newName)) {
|
||||
// return `Schedule ${newName} already exists`;
|
||||
// }
|
||||
|
||||
schedules[scheduleIndex].name = newName;
|
||||
schedules[scheduleIndex].updatedAt = Date.now();
|
||||
|
||||
Reference in New Issue
Block a user