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:
88
apps/api/src/cron/cron.controller.ts
Normal file
88
apps/api/src/cron/cron.controller.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user