58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
Patch,
|
|
Post,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
import { CurrentUser } from '../auth/current-user.decorator';
|
|
import { Roles } from '../auth/roles.decorator';
|
|
import { RolesGuard } from '../auth/roles.guard';
|
|
import {
|
|
CreateMessageAutomationRuleDto,
|
|
UpdateMessageAutomationRuleDto,
|
|
} from './dto';
|
|
import { MessageAutomationsService } from './message-automations.service';
|
|
|
|
@Controller('message-automations')
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('owner', 'admin')
|
|
export class MessageAutomationsController {
|
|
constructor(private readonly messages: MessageAutomationsService) {}
|
|
|
|
@Get()
|
|
list(@CurrentUser() user: { organizationId: string }) {
|
|
return this.messages.list(user.organizationId);
|
|
}
|
|
|
|
@Post()
|
|
create(
|
|
@CurrentUser() user: { organizationId: string },
|
|
@Body() dto: CreateMessageAutomationRuleDto,
|
|
) {
|
|
return this.messages.create(user.organizationId, dto);
|
|
}
|
|
|
|
@Patch(':id')
|
|
update(
|
|
@CurrentUser() user: { organizationId: string },
|
|
@Param('id') id: string,
|
|
@Body() dto: UpdateMessageAutomationRuleDto,
|
|
) {
|
|
return this.messages.update(user.organizationId, id, dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
async remove(
|
|
@CurrentUser() user: { organizationId: string },
|
|
@Param('id') id: string,
|
|
) {
|
|
await this.messages.remove(user.organizationId, id);
|
|
return { ok: true };
|
|
}
|
|
}
|