Files
doneit-web/src/app/module/chat/domain/use-case/socket/socket-message-update-use-case.service.ts
T

43 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-08-02 16:20:26 +01:00
import { Injectable } from '@angular/core';
2024-08-19 16:01:58 +01:00
import { MessageLocalDataSourceService } from '../../../data/repository/message/message-local-data-source.service';
2024-08-08 11:44:41 +01:00
import { MessageOutPutDataDTO, MessageOutPutDataDTOSchema } from '../../../data/dto/message/messageOutputDTO';
2024-08-08 15:53:00 +01:00
import { ParamsValidation, SafeValidateSchema, ValidateSchema } from 'src/app/services/decorators/validate-schema.decorator';
2024-08-08 11:44:41 +01:00
import { MessageInputDTOSchema } from '../../../data/dto/message/messageInputDtO';
2024-08-08 15:53:00 +01:00
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
2024-08-02 16:20:26 +01:00
@Injectable({
providedIn: 'root'
})
export class SocketMessageUpdateUseCaseService {
constructor(
private messageLocalDataSourceService: MessageLocalDataSourceService
) { }
2024-08-20 16:34:47 +01:00
@XTracerAsync({name:'Socket-Message-Update-UseCase', bugPrint: true, module:'chat',})
2024-08-08 15:53:00 +01:00
async execute(data: MessageOutPutDataDTO, tracing?: TracingType) {
ParamsValidation(MessageOutPutDataDTOSchema, data, tracing)
tracing?.addEvent("Message existe?")
2024-08-27 09:14:59 +01:00
const result = await this.messageLocalDataSourceService.findOne({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-27 09:14:59 +01:00
if(result.isOk() && result.value) {
2024-08-08 15:53:00 +01:00
tracing?.addEvent("Message found")
2024-08-20 16:34:47 +01:00
const updateResult = await this.messageLocalDataSourceService.update(result.value.$id, incomingMessage)
tracing.setAttribute('outcome', 'success')
return updateResult
2024-08-27 09:14:59 +01:00
} else if(result.isOk() && !result.value) {
2024-08-08 15:53:00 +01:00
tracing?.addEvent("Message not found")
2024-08-02 16:20:26 +01:00
}
2024-08-20 16:34:47 +01:00
2024-08-02 16:20:26 +01:00
}
}