2024-08-02 16:20:26 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { MessageLocalDataSourceService } from '../../../data/data-source/message/message-local-data-source.service';
|
2024-08-08 11:44:41 +01:00
|
|
|
import { MessageOutPutDataDTO, MessageOutPutDataDTOSchema } from '../../../data/dto/message/messageOutputDTO';
|
|
|
|
|
import { SafeValidateSchema, ValidateSchema } from 'src/app/services/decorators/validate-schema.decorator';
|
|
|
|
|
import { MessageInputDTOSchema } from '../../../data/dto/message/messageInputDtO';
|
2024-08-02 16:20:26 +01:00
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class SocketMessageUpdateUseCaseService {
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private messageLocalDataSourceService: MessageLocalDataSourceService
|
|
|
|
|
) { }
|
|
|
|
|
|
|
|
|
|
|
2024-08-08 11:44:41 +01:00
|
|
|
@SafeValidateSchema(MessageOutPutDataDTOSchema, 'SocketMessageUpdateUseCaseService')
|
2024-08-02 16:20:26 +01:00
|
|
|
async execute(data: MessageOutPutDataDTO) {
|
2024-08-06 11:24:00 +01:00
|
|
|
const result = await this.messageLocalDataSourceService.messageExist({id: data.id})
|
2024-08-02 16:20:26 +01:00
|
|
|
|
|
|
|
|
const incomingMessage = {
|
|
|
|
|
...data,
|
2024-08-08 09:58:44 +01:00
|
|
|
sending: false
|
2024-08-02 16:20:26 +01:00
|
|
|
}
|
|
|
|
|
|
2024-08-06 11:24:00 +01:00
|
|
|
// delete data.chatRoomId
|
|
|
|
|
|
2024-08-02 16:20:26 +01:00
|
|
|
if(result.isOk()) {
|
2024-08-08 11:44:41 +01:00
|
|
|
console.log('message exist', result.value, incomingMessage)
|
2024-08-07 16:31:31 +01:00
|
|
|
return this.messageLocalDataSourceService.update(result.value.$id, incomingMessage)
|
2024-08-02 16:20:26 +01:00
|
|
|
} else {
|
|
|
|
|
console.log('message else')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|