mirror of
https://github.com/morten-olsen/mini-loader.git
synced 2026-02-08 01:36:26 +01:00
feat: add scheduler (#30)
This commit is contained in:
53
packages/server/src/router/router.schedules.ts
Normal file
53
packages/server/src/router/router.schedules.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { z } from 'zod';
|
||||
import { addScheduleSchema, findSchedulesSchema } from '../repos/repos.js';
|
||||
import { publicProcedure, router } from './router.utils.js';
|
||||
|
||||
const add = publicProcedure.input(addScheduleSchema).mutation(async ({ input, ctx }) => {
|
||||
const { runtime } = ctx;
|
||||
const { repos } = runtime;
|
||||
const { schedules } = repos;
|
||||
|
||||
const result = await schedules.add(input);
|
||||
return result;
|
||||
});
|
||||
|
||||
const find = publicProcedure.input(findSchedulesSchema).query(async ({ input, ctx }) => {
|
||||
const { runtime } = ctx;
|
||||
const { repos } = runtime;
|
||||
const { schedules } = repos;
|
||||
|
||||
const result = await schedules.find(input);
|
||||
return result;
|
||||
});
|
||||
|
||||
const prepareRemove = publicProcedure.input(findSchedulesSchema).query(async ({ input, ctx }) => {
|
||||
const { runtime } = ctx;
|
||||
const { repos } = runtime;
|
||||
const { schedules } = repos;
|
||||
|
||||
return await schedules.prepareRemove(input);
|
||||
});
|
||||
|
||||
const remove = publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
hash: z.string(),
|
||||
ids: z.array(z.string()),
|
||||
}),
|
||||
)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { runtime } = ctx;
|
||||
const { repos } = runtime;
|
||||
const { artifacts } = repos;
|
||||
|
||||
await artifacts.remove(input.hash, input.ids);
|
||||
});
|
||||
|
||||
const schedulesRouter = router({
|
||||
add,
|
||||
find,
|
||||
remove,
|
||||
prepareRemove,
|
||||
});
|
||||
|
||||
export { schedulesRouter };
|
||||
Reference in New Issue
Block a user