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 { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer'; import { MessageEntitySchema } from 'src/app/core/chat/entity/message'; import { z } from 'zod'; import { MessageTable } from 'src/app/infra/database/dexie/instance/chat/schema/message'; const SocketMessageUpdateOutputSchema = MessageEntitySchema.pick({ id: true, attachments: true, canEdit: true, editedAt: true, info: true, isDeleted: true, message: true, messageType: true, oneShot: true, reactions: true, receiverId: true, requireUnlock: true, roomId: true, sender: true, sending: true, sentAt: true, }) export type ISocketMessageUpdateOutput = z.infer @Injectable({ providedIn: 'root' }) export class SocketMessageUpdateUseCaseService { constructor( private messageLocalDataSourceService: MessageLocalDataSourceService ) { } @XTracerAsync({name:'Socket-Message-Update-UseCase', bugPrint: true, module:'chat',}) async execute(input: ISocketMessageUpdateOutput, tracing?: TracingType) { ParamsValidation(MessageOutPutDataDTOSchema, input, tracing) tracing?.addEvent("Message existe?") const result = await this.messageLocalDataSourceService.findOne({id: input.id}) const messageToSave: MessageTable = input messageToSave.sending = false if(result.isOk() && result.value) { tracing?.addEvent("Message found") const updateResult = await this.messageLocalDataSourceService.update(result.value.$id, messageToSave) tracing.setAttribute('outcome', 'success') return updateResult } else if(result.isOk() && !result.value) { tracing?.addEvent("Message not found") } } }