mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
send all file
This commit is contained in:
@@ -48,6 +48,6 @@ export class MessageAttachmentByMessageIdUseCase {
|
||||
return dataUrl
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MessageEntity } from '../entity/message';
|
||||
import { MessageEntity, MessageEntitySchema, } from '../entity/message';
|
||||
import { MessageRepositoryService } from "src/app/module/chat/data/repository/message-respository.service"
|
||||
import { AttachmentRepositoryService } from "src/app/module/chat/data/repository/attachment-repository.service"
|
||||
import { z } from 'zod';
|
||||
import { z, ZodError } from 'zod';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { InstanceId } from '../chat-service.service';
|
||||
import { createDataURL } from 'src/app/utils/ToBase64';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
import { zodSafeValidation } from 'src/app/utils/zodValidation';
|
||||
|
||||
const MessageInputUseCaseSchema = z.object({
|
||||
memberId: z.number(),
|
||||
@@ -24,48 +25,61 @@ export class MessageCreateUseCaseService {
|
||||
constructor(
|
||||
private MessageRepositoryService: MessageRepositoryService,
|
||||
private AttachmentRepositoryService: AttachmentRepositoryService,
|
||||
private sanitizer: DomSanitizer
|
||||
private sanitizer: DomSanitizer,
|
||||
) { }
|
||||
|
||||
|
||||
async execute(message: MessageEntity) {
|
||||
|
||||
message.sendAttemp++;
|
||||
const validation = zodSafeValidation<MessageEntity>(MessageEntitySchema, message)
|
||||
|
||||
message.requestId = InstanceId +'@'+ uuidv4();
|
||||
if(validation.isOk()) {
|
||||
message.sendAttemp++;
|
||||
|
||||
const createMessageLocally = await this.MessageRepositoryService.createMessageLocally(message)
|
||||
message.requestId = InstanceId +'@'+ uuidv4();
|
||||
|
||||
if(createMessageLocally.isOk()) {
|
||||
const createMessageLocally = await this.MessageRepositoryService.createMessageLocally(message)
|
||||
|
||||
console.log('==========================',message);
|
||||
if(message.hasAttachment) {
|
||||
if(createMessageLocally.isOk()) {
|
||||
|
||||
for (const attachment of message.attachments) {
|
||||
console.log('==========================',message);
|
||||
if(message.hasAttachment) {
|
||||
|
||||
const createAttachmentLocally = this.AttachmentRepositoryService.create({
|
||||
$messageId: createMessageLocally.value.$id,
|
||||
file: createDataURL(attachment.file, attachment.mimeType)
|
||||
})
|
||||
for (const attachment of message.attachments) {
|
||||
|
||||
const createAttachmentLocally = this.AttachmentRepositoryService.create({
|
||||
$messageId: createMessageLocally.value.$id,
|
||||
file: createDataURL(attachment.file, attachment.mimeType)
|
||||
})
|
||||
|
||||
attachment.safeFile = createDataURL(attachment.file, attachment.mimeType)
|
||||
}
|
||||
|
||||
attachment.safeFile = createDataURL(attachment.file, attachment.mimeType)
|
||||
}
|
||||
|
||||
const sendToServer = await this.MessageRepositoryService.sendMessage(message)
|
||||
|
||||
|
||||
if(!sendToServer.isOk()) {
|
||||
console.log('sendToServer error', sendToServer.error)
|
||||
}
|
||||
|
||||
|
||||
return sendToServer
|
||||
}
|
||||
|
||||
const sendToServer = await this.MessageRepositoryService.sendMessage(message)
|
||||
const result = await this.MessageRepositoryService.sendMessage(message)
|
||||
|
||||
return result
|
||||
} else {
|
||||
|
||||
if(!sendToServer.isOk()) {
|
||||
console.log('sendToServer error', sendToServer.error)
|
||||
if(validation.error.formErrors.fieldErrors.attachments) {
|
||||
console.log(message.attachments)
|
||||
console.error('invalid attachment', validation.error.formErrors.fieldErrors.attachments)
|
||||
}
|
||||
|
||||
|
||||
return sendToServer
|
||||
}
|
||||
|
||||
const result = await this.MessageRepositoryService.sendMessage(message)
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user