mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
feat: naming backup schedules (#103)
* docs: add agents instructions * feat: naming backup schedules * fix: wrong table for filtering
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { and, eq, ne } from "drizzle-orm";
|
||||
import cron from "node-cron";
|
||||
import { CronExpressionParser } from "cron-parser";
|
||||
import { NotFoundError, BadRequestError, ConflictError } from "http-errors-enhanced";
|
||||
@@ -44,7 +44,7 @@ const listSchedules = async () => {
|
||||
|
||||
const getSchedule = async (scheduleId: number) => {
|
||||
const schedule = await db.query.backupSchedulesTable.findFirst({
|
||||
where: eq(volumesTable.id, scheduleId),
|
||||
where: eq(backupSchedulesTable.id, scheduleId),
|
||||
with: {
|
||||
volume: true,
|
||||
repository: true,
|
||||
@@ -63,6 +63,14 @@ const createSchedule = async (data: CreateBackupScheduleBody) => {
|
||||
throw new BadRequestError("Invalid cron expression");
|
||||
}
|
||||
|
||||
const existingName = await db.query.backupSchedulesTable.findFirst({
|
||||
where: eq(backupSchedulesTable.name, data.name),
|
||||
});
|
||||
|
||||
if (existingName) {
|
||||
throw new ConflictError("A backup schedule with this name already exists");
|
||||
}
|
||||
|
||||
const volume = await db.query.volumesTable.findFirst({
|
||||
where: eq(volumesTable.id, data.volumeId),
|
||||
});
|
||||
@@ -84,6 +92,7 @@ const createSchedule = async (data: CreateBackupScheduleBody) => {
|
||||
const [newSchedule] = await db
|
||||
.insert(backupSchedulesTable)
|
||||
.values({
|
||||
name: data.name,
|
||||
volumeId: data.volumeId,
|
||||
repositoryId: data.repositoryId,
|
||||
enabled: data.enabled,
|
||||
@@ -115,6 +124,16 @@ const updateSchedule = async (scheduleId: number, data: UpdateBackupScheduleBody
|
||||
throw new BadRequestError("Invalid cron expression");
|
||||
}
|
||||
|
||||
if (data.name) {
|
||||
const existingName = await db.query.backupSchedulesTable.findFirst({
|
||||
where: and(eq(backupSchedulesTable.name, data.name), ne(backupSchedulesTable.id, scheduleId)),
|
||||
});
|
||||
|
||||
if (existingName) {
|
||||
throw new ConflictError("A backup schedule with this name already exists");
|
||||
}
|
||||
}
|
||||
|
||||
const repository = await db.query.repositoriesTable.findFirst({
|
||||
where: eq(repositoriesTable.id, data.repositoryId),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user