61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
import { Body, Controller, Get, Param, Post, Put } from "@nestjs/common";
|
|
import { ok } from "../common/response";
|
|
import { RulesService } from "./rules.service";
|
|
import { CurrentUser } from "../common/decorators/current-user.decorator";
|
|
|
|
@Controller("rules")
|
|
export class RulesController {
|
|
constructor(private readonly rulesService: RulesService) {}
|
|
|
|
@Get()
|
|
async list(@CurrentUser() userId: string) {
|
|
const data = await this.rulesService.list(userId);
|
|
return ok(data);
|
|
}
|
|
|
|
@Post()
|
|
async create(
|
|
@CurrentUser() userId: string,
|
|
@Body()
|
|
payload: {
|
|
name: string;
|
|
priority?: number;
|
|
conditions: Record<string, unknown>;
|
|
actions: Record<string, unknown>;
|
|
isActive?: boolean;
|
|
},
|
|
) {
|
|
const data = await this.rulesService.create(userId, payload);
|
|
return ok(data);
|
|
}
|
|
|
|
@Put(":id")
|
|
async update(
|
|
@CurrentUser() userId: string,
|
|
@Param("id") id: string,
|
|
@Body()
|
|
payload: {
|
|
name?: string;
|
|
priority?: number;
|
|
conditions?: Record<string, unknown>;
|
|
actions?: Record<string, unknown>;
|
|
isActive?: boolean;
|
|
},
|
|
) {
|
|
const data = await this.rulesService.update(userId, id, payload);
|
|
return ok(data);
|
|
}
|
|
|
|
@Post(":id/execute")
|
|
async execute(@CurrentUser() userId: string, @Param("id") id: string) {
|
|
const data = await this.rulesService.execute(userId, id);
|
|
return ok(data);
|
|
}
|
|
|
|
@Get("suggestions")
|
|
async suggestions(@CurrentUser() userId: string) {
|
|
const data = await this.rulesService.suggest(userId);
|
|
return ok(data);
|
|
}
|
|
}
|