2024-08-07 11:18:41 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { MessageEntity } from '../entity/message';
|
|
|
|
|
import { SessionStore } from 'src/app/store/session.service';
|
|
|
|
|
import { MessageRepositoryService } from "src/app/module/chat/data/repository/message-respository.service"
|
|
|
|
|
import { z } from 'zod';
|
2024-08-13 10:52:35 +01:00
|
|
|
import { v4 as uuidv4 } from 'uuid'
|
|
|
|
|
import { InstanceId } from '../chat-service.service';
|
2024-08-07 11:18:41 +01:00
|
|
|
|
|
|
|
|
const MessageInputUseCaseSchema = z.object({
|
|
|
|
|
memberId: z.number(),
|
|
|
|
|
roomId: z.string(),
|
|
|
|
|
message: z.string()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export type MessageInputUseCase = z.infer< typeof MessageInputUseCaseSchema>
|
|
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class MessageCreateUseCaseService {
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private MessageRepositoryService: MessageRepositoryService
|
|
|
|
|
) { }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async execute(input: MessageEntity) {
|
|
|
|
|
|
|
|
|
|
input.sendAttemp++;
|
|
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
input.requestId = InstanceId +'@'+ uuidv4();
|
|
|
|
|
|
2024-08-07 11:18:41 +01:00
|
|
|
const result = await this.MessageRepositoryService.sendMessage(input)
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
}
|