feat(#29): implement cron job configuration

- Add CronSchedule model to Prisma schema
- Implement CronService with CRUD operations
- Add REST API endpoints for cron management
- Create MoltBot plugin skill definition (SKILL.md)
- TDD: 9 passing tests for CronService
This commit is contained in:
2026-01-29 23:00:48 -06:00
parent 9de0b2f92f
commit 2e6b7d4070
10 changed files with 562 additions and 56 deletions

View File

@@ -0,0 +1,88 @@
import {
Controller,
Get,
Post,
Patch,
Delete,
Body,
Param,
UseGuards,
} from "@nestjs/common";
import { CronService } from "./cron.service";
import { CreateCronDto, UpdateCronDto } from "./dto";
import { AuthGuard } from "../auth/guards/auth.guard";
import { WorkspaceGuard } from "../common/guards";
import { Workspace, RequirePermission } from "../common/decorators";
import { Permission } from "@prisma/client";
/**
* Controller for cron job scheduling endpoints
* All endpoints require authentication and workspace context
*/
@Controller("cron")
@UseGuards(AuthGuard, WorkspaceGuard)
export class CronController {
constructor(private readonly cronService: CronService) {}
/**
* POST /api/cron
* Create a new cron schedule
* Requires: MEMBER role or higher
*/
@Post()
@RequirePermission(Permission.WORKSPACE_MEMBER)
async create(
@Body() createCronDto: CreateCronDto,
@Workspace() workspaceId: string
) {
return this.cronService.create({ ...createCronDto, workspaceId });
}
/**
* GET /api/cron
* Get all cron schedules for workspace
* Requires: Any workspace member
*/
@Get()
@RequirePermission(Permission.WORKSPACE_ANY)
async findAll(@Workspace() workspaceId: string) {
return this.cronService.findAll(workspaceId);
}
/**
* GET /api/cron/:id
* Get a single cron schedule
* Requires: Any workspace member
*/
@Get(":id")
@RequirePermission(Permission.WORKSPACE_ANY)
async findOne(@Param("id") id: string, @Workspace() workspaceId: string) {
return this.cronService.findOne(id, workspaceId);
}
/**
* PATCH /api/cron/:id
* Update a cron schedule
* Requires: MEMBER role or higher
*/
@Patch(":id")
@RequirePermission(Permission.WORKSPACE_MEMBER)
async update(
@Param("id") id: string,
@Body() updateCronDto: UpdateCronDto,
@Workspace() workspaceId: string
) {
return this.cronService.update(id, workspaceId, updateCronDto);
}
/**
* DELETE /api/cron/:id
* Delete a cron schedule
* Requires: ADMIN role or higher
*/
@Delete(":id")
@RequirePermission(Permission.WORKSPACE_ADMIN)
async remove(@Param("id") id: string, @Workspace() workspaceId: string) {
return this.cronService.remove(id, workspaceId);
}
}