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

64 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-08-02 16:20:26 +01:00
import { Injectable, Input } 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 15:53:00 +01:00
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
import { ParamsValidation } from 'src/app/services/decorators/validate-schema.decorator';
2024-08-27 20:29:57 +01:00
import { MessageEntitySchema } from 'src/app/core/chat/entity/message';
import { z } from 'zod';
const SocketMessageCreateOutputSchema = 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 ISocketMessageCreateOutput = z.infer<typeof SocketMessageCreateOutputSchema>
2024-08-02 16:20:26 +01:00
@Injectable({
providedIn: 'root'
})
export class SocketMessageCreateUseCaseService {
constructor(
private messageLocalDataSourceService: MessageLocalDataSourceService,
) { }
2024-08-20 16:34:47 +01:00
@XTracerAsync({name:'Socket-Message-Create-UseCase', module:'chat', bugPrint: true})
2024-08-27 20:29:57 +01:00
async execute(input: ISocketMessageCreateOutput, tracing?: TracingType) {
2024-08-08 15:53:00 +01:00
2024-08-27 20:29:57 +01:00
ParamsValidation(SocketMessageCreateOutputSchema, input, tracing)
2024-08-02 16:20:26 +01:00
const incomingMessage = {
...input,
2024-08-08 15:53:00 +01:00
sending: false
2024-08-02 16:20:26 +01:00
}
2024-08-08 15:53:00 +01:00
console.log('create message', {incomingMessage});
2024-08-06 11:24:00 +01:00
2024-08-08 15:53:00 +01:00
tracing?.addEvent("Message Create start")
2024-08-27 09:14:59 +01:00
const result = await this.messageLocalDataSourceService.insert(incomingMessage)
2024-08-08 15:53:00 +01:00
tracing?.addEvent("Message Create end")
2024-08-02 16:20:26 +01:00
if(result.isOk()) {
} else {
2024-08-08 15:53:00 +01:00
tracing?.addEvent("error while creating message")
tracing.log("error while creating message", {
error: result.error
})
2024-08-02 16:20:26 +01:00
}
}
}