02d89e6385
Add knowledge document GET/PUT and admin edit UI; auto-create support tickets on client 400 validation errors across user/shop/partner apps; batch create tasks and publish from support tickets; restore mini-user store env single-column layout. Co-authored-by: Cursor <cursoragent@cursor.com>
165 lines
4.8 KiB
TypeScript
165 lines
4.8 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
Post,
|
|
Put,
|
|
Query,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import type {
|
|
CreateKnowledgeBaseRequest,
|
|
CreateKnowledgeDocumentRequest,
|
|
UpdateKnowledgeBaseRequest,
|
|
UpdateKnowledgeDocumentRequest,
|
|
} from '@dukang/shared-types';
|
|
import { HqAuthGuard } from '../../common/guards/hq-auth.guard';
|
|
import {
|
|
HqPermissionGuard,
|
|
RequireHqPermissions,
|
|
} from '../../common/guards/hq-permission.guard';
|
|
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
|
import type { AuthUser } from '../../common/guards/jwt-auth.guard';
|
|
import { HqOperation } from '../../common/hq-operation/hq-operation.decorator';
|
|
import { HqOperationAction } from '../../common/hq-operation/hq-operation.constants';
|
|
import { AdminKnowledgeBasesService } from './admin-knowledge-bases.service';
|
|
|
|
@Controller('admin/knowledge-bases')
|
|
@UseGuards(HqAuthGuard, HqPermissionGuard)
|
|
@RequireHqPermissions('knowledge_bases')
|
|
export class AdminKnowledgeBasesController {
|
|
constructor(private readonly service: AdminKnowledgeBasesService) {}
|
|
|
|
@Get()
|
|
async list(
|
|
@CurrentUser() user: AuthUser,
|
|
@Query('name') name?: string,
|
|
@Query('enabled') enabled?: string,
|
|
@Query('page') page?: string,
|
|
@Query('pageSize') pageSize?: string,
|
|
) {
|
|
const actor = await this.service.resolveActor(user.actorId);
|
|
return this.service.list(actor, {
|
|
name,
|
|
enabled,
|
|
page: page ? Number(page) : undefined,
|
|
pageSize: pageSize ? Number(pageSize) : undefined,
|
|
});
|
|
}
|
|
|
|
@Get('options')
|
|
async options(@CurrentUser() user: AuthUser) {
|
|
const actor = await this.service.resolveActor(user.actorId);
|
|
return this.service.options(actor);
|
|
}
|
|
|
|
@Get(':id')
|
|
async detail(@CurrentUser() user: AuthUser, @Param('id') id: string) {
|
|
const actor = await this.service.resolveActor(user.actorId);
|
|
return this.service.detail(actor, BigInt(id));
|
|
}
|
|
|
|
@Post()
|
|
@HqOperation({
|
|
action: HqOperationAction.KNOWLEDGE_BASE_CREATE,
|
|
refType: 'KNOWLEDGE_BASE',
|
|
includeBody: true,
|
|
})
|
|
async create(@CurrentUser() user: AuthUser, @Body() body: CreateKnowledgeBaseRequest) {
|
|
const actor = await this.service.resolveActor(user.actorId);
|
|
return this.service.create(actor, body);
|
|
}
|
|
|
|
@Put(':id')
|
|
@HqOperation({
|
|
action: HqOperationAction.KNOWLEDGE_BASE_UPDATE,
|
|
refType: 'KNOWLEDGE_BASE',
|
|
refIdField: 'id',
|
|
includeBody: true,
|
|
})
|
|
async update(
|
|
@CurrentUser() user: AuthUser,
|
|
@Param('id') id: string,
|
|
@Body() body: UpdateKnowledgeBaseRequest,
|
|
) {
|
|
const actor = await this.service.resolveActor(user.actorId);
|
|
return this.service.update(actor, BigInt(id), body);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@HqOperation({
|
|
action: HqOperationAction.KNOWLEDGE_BASE_DELETE,
|
|
refType: 'KNOWLEDGE_BASE',
|
|
refIdField: 'id',
|
|
})
|
|
async remove(@CurrentUser() user: AuthUser, @Param('id') id: string) {
|
|
const actor = await this.service.resolveActor(user.actorId);
|
|
return this.service.remove(actor, BigInt(id));
|
|
}
|
|
|
|
@Get(':id/documents')
|
|
async listDocuments(@CurrentUser() user: AuthUser, @Param('id') id: string) {
|
|
const actor = await this.service.resolveActor(user.actorId);
|
|
return this.service.listDocuments(actor, BigInt(id));
|
|
}
|
|
|
|
@Post(':id/documents')
|
|
@HqOperation({
|
|
action: HqOperationAction.KNOWLEDGE_DOC_CREATE,
|
|
refType: 'KNOWLEDGE_DOCUMENT',
|
|
includeBody: true,
|
|
})
|
|
async addDocument(
|
|
@CurrentUser() user: AuthUser,
|
|
@Param('id') id: string,
|
|
@Body() body: CreateKnowledgeDocumentRequest,
|
|
) {
|
|
const actor = await this.service.resolveActor(user.actorId);
|
|
return this.service.addDocument(actor, BigInt(id), body);
|
|
}
|
|
|
|
@Get(':id/documents/:docId')
|
|
async getDocument(
|
|
@CurrentUser() user: AuthUser,
|
|
@Param('id') id: string,
|
|
@Param('docId') docId: string,
|
|
) {
|
|
const actor = await this.service.resolveActor(user.actorId);
|
|
return this.service.getDocument(actor, BigInt(id), BigInt(docId));
|
|
}
|
|
|
|
@Put(':id/documents/:docId')
|
|
@HqOperation({
|
|
action: HqOperationAction.KNOWLEDGE_DOC_UPDATE,
|
|
refType: 'KNOWLEDGE_DOCUMENT',
|
|
refIdField: 'docId',
|
|
includeBody: true,
|
|
})
|
|
async updateDocument(
|
|
@CurrentUser() user: AuthUser,
|
|
@Param('id') id: string,
|
|
@Param('docId') docId: string,
|
|
@Body() body: UpdateKnowledgeDocumentRequest,
|
|
) {
|
|
const actor = await this.service.resolveActor(user.actorId);
|
|
return this.service.updateDocument(actor, BigInt(id), BigInt(docId), body);
|
|
}
|
|
|
|
@Delete(':id/documents/:docId')
|
|
@HqOperation({
|
|
action: HqOperationAction.KNOWLEDGE_DOC_DELETE,
|
|
refType: 'KNOWLEDGE_DOCUMENT',
|
|
refIdField: 'docId',
|
|
})
|
|
async removeDocument(
|
|
@CurrentUser() user: AuthUser,
|
|
@Param('id') id: string,
|
|
@Param('docId') docId: string,
|
|
) {
|
|
const actor = await this.service.resolveActor(user.actorId);
|
|
return this.service.removeDocument(actor, BigInt(id), BigInt(docId));
|
|
}
|
|
}
|