mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
add interface
This commit is contained in:
+30
-9
@@ -2,9 +2,32 @@ 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';
|
||||
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<typeof SocketMessageUpdateOutputSchema>
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@@ -16,21 +39,19 @@ export class SocketMessageUpdateUseCaseService {
|
||||
|
||||
|
||||
@XTracerAsync({name:'Socket-Message-Update-UseCase', bugPrint: true, module:'chat',})
|
||||
async execute(data: MessageOutPutDataDTO, tracing?: TracingType) {
|
||||
async execute(input: ISocketMessageUpdateOutput, tracing?: TracingType) {
|
||||
|
||||
ParamsValidation(MessageOutPutDataDTOSchema, data, tracing)
|
||||
ParamsValidation(MessageOutPutDataDTOSchema, input, tracing)
|
||||
tracing?.addEvent("Message existe?")
|
||||
const result = await this.messageLocalDataSourceService.findOne({id: data.id})
|
||||
const result = await this.messageLocalDataSourceService.findOne({id: input.id})
|
||||
|
||||
const incomingMessage = {
|
||||
...data,
|
||||
sending: false
|
||||
}
|
||||
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, incomingMessage)
|
||||
const updateResult = await this.messageLocalDataSourceService.update(result.value.$id, messageToSave)
|
||||
tracing.setAttribute('outcome', 'success')
|
||||
return updateResult
|
||||
} else if(result.isOk() && !result.value) {
|
||||
|
||||
Reference in New Issue
Block a user