78 lines
1.8 KiB
TypeScript
78 lines
1.8 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
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 {
|
|
CreateFaqArticleDto,
|
|
ListFaqQueryDto,
|
|
UpdateFaqArticleDto,
|
|
} from './dto';
|
|
import { FaqService } from './faq.service';
|
|
|
|
@Controller('faq')
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
export class FaqController {
|
|
constructor(private readonly faqService: FaqService) {}
|
|
|
|
@Get()
|
|
list(
|
|
@CurrentUser() user: { organizationId: string; role: string },
|
|
@Query() query: ListFaqQueryDto,
|
|
) {
|
|
const canManage = user.role === 'owner' || user.role === 'admin';
|
|
return this.faqService.list(user.organizationId, {
|
|
q: query.q,
|
|
category: query.category,
|
|
publishedOnly: query.publishedOnly ?? !canManage,
|
|
});
|
|
}
|
|
|
|
@Get(':id')
|
|
get(
|
|
@CurrentUser() user: { organizationId: string },
|
|
@Param('id') id: string,
|
|
) {
|
|
return this.faqService.get(user.organizationId, id);
|
|
}
|
|
|
|
@Post()
|
|
@Roles('owner', 'admin')
|
|
create(
|
|
@CurrentUser() user: { organizationId: string },
|
|
@Body() dto: CreateFaqArticleDto,
|
|
) {
|
|
return this.faqService.create(user.organizationId, dto);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@Roles('owner', 'admin')
|
|
update(
|
|
@CurrentUser() user: { organizationId: string },
|
|
@Param('id') id: string,
|
|
@Body() dto: UpdateFaqArticleDto,
|
|
) {
|
|
return this.faqService.update(user.organizationId, id, dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@Roles('owner', 'admin')
|
|
async remove(
|
|
@CurrentUser() user: { organizationId: string },
|
|
@Param('id') id: string,
|
|
) {
|
|
await this.faqService.remove(user.organizationId, id);
|
|
return { ok: true };
|
|
}
|
|
}
|