mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
receive message
This commit is contained in:
@@ -25,6 +25,7 @@ export class MessageRemoteDataSourceService {
|
||||
return await this.httpService.post<any>(`${this.baseUrl}/Messages/${id}/React`, reaction);
|
||||
}
|
||||
|
||||
|
||||
@APIReturn(MessageOutPutDTOSchema, 'get/Messages')
|
||||
async getMessagesFromRoom(id: string): DataSourceReturn<MessageOutPutDTO> {
|
||||
return await this.httpService.get(`${this.baseUrl}/Room/${id}/Messages`);
|
||||
|
||||
@@ -20,7 +20,7 @@ export const MessageOutPutDataDTOSchema = z.object({
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string(),
|
||||
userPhoto: z.string().optional()
|
||||
}).nullable(),
|
||||
}),
|
||||
message: z.string().nullable(),
|
||||
messageType: z.number(),
|
||||
sentAt: z.string(),
|
||||
|
||||
+16
-6
@@ -1,5 +1,8 @@
|
||||
import { Injectable, Input } from '@angular/core';
|
||||
import { MessageLocalDataSourceService } from '../../../data/data-source/message/message-local-data-source.service';
|
||||
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
|
||||
import { ParamsValidation } from 'src/app/services/decorators/validate-schema.decorator';
|
||||
import { MessageOutPutDataDTOSchema } from '../../../data/dto/message/messageOutputDTO';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -10,22 +13,29 @@ export class SocketMessageCreateUseCaseService {
|
||||
private messageLocalDataSourceService: MessageLocalDataSourceService,
|
||||
) { }
|
||||
|
||||
async execute(input: any) {
|
||||
@XTracerAsync({name:'Socket-Message-Create-UseCase', bugPrint: true})
|
||||
async execute(input: any, tracing?: TracingType) {
|
||||
|
||||
ParamsValidation(MessageOutPutDataDTOSchema, input, tracing)
|
||||
|
||||
const incomingMessage = {
|
||||
...input,
|
||||
sending: false,
|
||||
roomId:input.chatRoomId
|
||||
sending: false
|
||||
}
|
||||
|
||||
delete input.chatRoomId
|
||||
console.log('create message', {incomingMessage});
|
||||
|
||||
const result = await this.messageLocalDataSourceService.sendMessage(incomingMessage)
|
||||
tracing?.addEvent("Message Create start")
|
||||
const result = await this.messageLocalDataSourceService.createMessage(incomingMessage)
|
||||
tracing?.addEvent("Message Create end")
|
||||
|
||||
if(result.isOk()) {
|
||||
|
||||
} else {
|
||||
console.log(result.error)
|
||||
tracing?.addEvent("error while creating message")
|
||||
tracing.log("error while creating message", {
|
||||
error: result.error
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-8
@@ -1,8 +1,9 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MessageLocalDataSourceService } from '../../../data/data-source/message/message-local-data-source.service';
|
||||
import { MessageOutPutDataDTO, MessageOutPutDataDTOSchema } from '../../../data/dto/message/messageOutputDTO';
|
||||
import { SafeValidateSchema, ValidateSchema } from 'src/app/services/decorators/validate-schema.decorator';
|
||||
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'
|
||||
@@ -14,8 +15,12 @@ export class SocketMessageUpdateUseCaseService {
|
||||
) { }
|
||||
|
||||
|
||||
@SafeValidateSchema(MessageOutPutDataDTOSchema, 'SocketMessageUpdateUseCaseService')
|
||||
async execute(data: MessageOutPutDataDTO) {
|
||||
@XTracerAsync({name:'Socket-Message-Update-UseCase', bugPrint: true})
|
||||
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 = {
|
||||
@@ -23,14 +28,13 @@ export class SocketMessageUpdateUseCaseService {
|
||||
sending: false
|
||||
}
|
||||
|
||||
// delete data.chatRoomId
|
||||
|
||||
if(result.isOk()) {
|
||||
console.log('message exist', result.value, incomingMessage)
|
||||
return this.messageLocalDataSourceService.update(result.value.$id, incomingMessage)
|
||||
tracing?.addEvent("Message found")
|
||||
return await this.messageLocalDataSourceService.update(result.value.$id, incomingMessage)
|
||||
} else {
|
||||
console.log('message else')
|
||||
tracing?.addEvent("Message not found")
|
||||
}
|
||||
|
||||
tracing.setAttribute('outcome', 'success')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user