update condition save
This commit is contained in:
parent
17de7c0645
commit
5fb2658571
|
|
@ -48,6 +48,17 @@ export class ConversationsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getConversation(id: Conversation['id']) {
|
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, {
|
await this.event.sendEvent(MessagesEventService.EVENTS.GET_CONVERSATION, {
|
||||||
id,
|
id,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,19 @@ export class MessagesListener {
|
||||||
// Tự động được gọi khi emit 'messages.receive-conversation'
|
// Tự động được gọi khi emit 'messages.receive-conversation'
|
||||||
@OnEvent(MessagesEventService.EVENTS.RECEIVE_CONVERSATION)
|
@OnEvent(MessagesEventService.EVENTS.RECEIVE_CONVERSATION)
|
||||||
async handleReceiveConversation(payload: CreateMessageDto[]) {
|
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
|
// Send local event
|
||||||
this.eventService.sendEvent(
|
this.eventService.sendEvent(
|
||||||
|
|
@ -32,6 +44,14 @@ export class MessagesListener {
|
||||||
// Tự động được gọi khi emit 'messages.receive-conversations'
|
// Tự động được gọi khi emit 'messages.receive-conversations'
|
||||||
@OnEvent(MessagesEventService.EVENTS.RECEIVE_CONVERSATIONS)
|
@OnEvent(MessagesEventService.EVENTS.RECEIVE_CONVERSATIONS)
|
||||||
async handleReceiveConversations(data: Conversation[]) {
|
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);
|
const result = await this.repoConversation.save(data);
|
||||||
|
|
||||||
// Send local event
|
// Send local event
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue