feat(conversations): add search endpoint — M1-006 (#299)
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #299.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
@@ -11,6 +12,7 @@ import {
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import type { Brain } from '@mosaic/brain';
|
||||
@@ -21,6 +23,7 @@ import {
|
||||
CreateConversationDto,
|
||||
UpdateConversationDto,
|
||||
SendMessageDto,
|
||||
SearchMessagesDto,
|
||||
} from './conversations.dto.js';
|
||||
|
||||
@Controller('api/conversations')
|
||||
@@ -33,6 +36,16 @@ export class ConversationsController {
|
||||
return this.brain.conversations.findAll(user.id);
|
||||
}
|
||||
|
||||
@Get('search')
|
||||
async search(@Query() dto: SearchMessagesDto, @CurrentUser() user: { id: string }) {
|
||||
if (!dto.q || dto.q.trim().length === 0) {
|
||||
throw new BadRequestException('Query parameter "q" is required and must not be empty');
|
||||
}
|
||||
const limit = dto.limit ?? 20;
|
||||
const offset = dto.offset ?? 0;
|
||||
return this.brain.conversations.searchMessages(user.id, dto.q.trim(), limit, offset);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(@Param('id') id: string, @CurrentUser() user: { id: string }) {
|
||||
const conversation = await this.brain.conversations.findById(id, user.id);
|
||||
|
||||
Reference in New Issue
Block a user