update condition save

This commit is contained in:
Admin 2025-08-07 13:49:11 +07:00
parent 17de7c0645
commit 5fb2658571
2 changed files with 32 additions and 1 deletions

View File

@ -48,6 +48,17 @@ export class ConversationsService {
}
async getConversation(id: Conversation['id']) {
const prev = await this.repo.findOne({
where: { id },
});
if (!prev)
throw new NotFoundException(
AppResponse.toResponse(null, {
message: SystemLang.getText('messages', 'not_found'),
}),
);
await this.event.sendEvent(MessagesEventService.EVENTS.GET_CONVERSATION, {
id,
});

View File

@ -20,7 +20,19 @@ export class MessagesListener {
// Tự động được gọi khi emit 'messages.receive-conversation'
@OnEvent(MessagesEventService.EVENTS.RECEIVE_CONVERSATION)
async handleReceiveConversation(payload: CreateMessageDto[]) {
const result = await this.service.bulkCreate(payload);
if (!payload || !payload.length) {
// Send local event
this.eventService.sendEvent(
MessagesEventService.LOCAL_EVENTS.RECEIVE_CONVERSATION,
[],
);
return;
}
const result = await this.service.bulkCreate(
payload.filter((item) => item.time),
);
// Send local event
this.eventService.sendEvent(
@ -32,6 +44,14 @@ export class MessagesListener {
// Tự động được gọi khi emit 'messages.receive-conversations'
@OnEvent(MessagesEventService.EVENTS.RECEIVE_CONVERSATIONS)
async handleReceiveConversations(data: Conversation[]) {
if (!data || data.length <= 0) {
this.eventService.sendEvent(
MessagesEventService.LOCAL_EVENTS.RECEIVE_CONVERSATIONS,
[],
);
return;
}
const result = await this.repoConversation.save(data);
// Send local event