46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { Body, Controller, Get, Param, Post, UseGuards } from '@nestjs/common';
|
|
import { MessagesService } from './messages.service';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
import { RolesGuard } from '../auth/roles.guard';
|
|
import { Roles } from '../auth/roles.decorator';
|
|
import { CurrentTenantContext } from '../auth/current-tenant.decorator';
|
|
import { TenantContext } from '../../common/tenant-context';
|
|
|
|
@Controller('admin/messages')
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('OWNER', 'ADMIN')
|
|
export class MessagesController {
|
|
constructor(private readonly messagesService: MessagesService) {}
|
|
|
|
@Get('pending')
|
|
listPending(@CurrentTenantContext() ctx: TenantContext) {
|
|
return this.messagesService.listPending(ctx.tenantId);
|
|
}
|
|
|
|
@Get('pending/count')
|
|
pendingCount(@CurrentTenantContext() ctx: TenantContext) {
|
|
return this.messagesService.pendingCount(ctx.tenantId);
|
|
}
|
|
|
|
@Get(':id')
|
|
get(
|
|
@CurrentTenantContext() ctx: TenantContext,
|
|
@Param('id') id: string,
|
|
) {
|
|
return this.messagesService.get(ctx.tenantId, id);
|
|
}
|
|
|
|
@Post(':id/approve')
|
|
approve(
|
|
@CurrentTenantContext() ctx: TenantContext,
|
|
@Param('id') id: string,
|
|
) {
|
|
return this.messagesService.approve(ctx.tenantId, ctx.adminId ?? '', id);
|
|
}
|
|
|
|
@Post('reindex')
|
|
reindex(@CurrentTenantContext() ctx: TenantContext) {
|
|
return this.messagesService.reindexApproved(ctx.tenantId);
|
|
}
|
|
}
|