mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { MessageLocalDataSourceService } from '../../../data/repository/message/message-local-data-source.service';
|
|
import { MessageOutPutDataDTO, MessageOutPutDataDTOSchema } from '../../../data/dto/message/messageOutputDTO';
|
|
import { ParamsValidation, SafeValidateSchema, ValidateSchema } from 'src/app/services/decorators/validate-schema.decorator';
|
|
import { MessageInputDTOSchema } from '../../../data/dto/message/messageInputDtO';
|
|
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class SocketMessageUpdateUseCaseService {
|
|
|
|
constructor(
|
|
private messageLocalDataSourceService: MessageLocalDataSourceService
|
|
) { }
|
|
|
|
|
|
@XTracerAsync({name:'Socket-Message-Update-UseCase', bugPrint: true, module:'chat',})
|
|
async execute(data: MessageOutPutDataDTO, tracing?: TracingType) {
|
|
|
|
ParamsValidation(MessageOutPutDataDTOSchema, data, tracing)
|
|
tracing?.addEvent("Message existe?")
|
|
const result = await this.messageLocalDataSourceService.messageExist({id: data.id})
|
|
|
|
const incomingMessage = {
|
|
...data,
|
|
sending: false
|
|
}
|
|
|
|
if(result.isOk()) {
|
|
tracing?.addEvent("Message found")
|
|
const updateResult = await this.messageLocalDataSourceService.update(result.value.$id, incomingMessage)
|
|
tracing.setAttribute('outcome', 'success')
|
|
return updateResult
|
|
} else {
|
|
tracing?.addEvent("Message not found")
|
|
}
|
|
|
|
|
|
}
|
|
}
|