mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
fix send webtrix document
This commit is contained in:
@@ -25,7 +25,7 @@ export const MessageEntitySchema = z.object({
|
||||
source: z.nativeEnum(MessageAttachmentSource),
|
||||
file: base64Schema.optional(),
|
||||
fileName: z.string().optional(),
|
||||
applicationId: z.string().optional(),
|
||||
applicationId: z.number().optional(),
|
||||
docId: z.string().optional(),
|
||||
id: z.string().optional(),
|
||||
mimeType: z.string().optional()
|
||||
@@ -60,7 +60,7 @@ export class MessageEntity implements Message {
|
||||
source: MessageAttachmentSource,
|
||||
file?: string,
|
||||
fileName: string,
|
||||
applicationId?: string,
|
||||
applicationId?: number,
|
||||
docId?: string,
|
||||
mimeType?: string,
|
||||
description?: string
|
||||
|
||||
@@ -24,7 +24,7 @@ export class MessageMapper {
|
||||
file: e.file,
|
||||
fileName: e.fileName,
|
||||
applicationId: e.applicationId,
|
||||
docId: e.docId,
|
||||
docId: Number(e.docId),
|
||||
mimeType: e.mimeType
|
||||
}))[0]
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ 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';
|
||||
import { Logger } from 'src/app/services/logger/main/service';
|
||||
import { MessageAttachmentSource } from '../../data/dto/message/messageOutputDTO';
|
||||
|
||||
const MessageInputUseCaseSchema = z.object({
|
||||
memberId: z.number(),
|
||||
@@ -25,7 +27,6 @@ export class MessageCreateUseCaseService {
|
||||
constructor(
|
||||
private MessageRepositoryService: MessageRepositoryService,
|
||||
private AttachmentRepositoryService: AttachmentRepositoryService,
|
||||
private sanitizer: DomSanitizer,
|
||||
) { }
|
||||
|
||||
|
||||
@@ -41,34 +42,40 @@ export class MessageCreateUseCaseService {
|
||||
const createMessageLocally = await this.MessageRepositoryService.createMessageLocally(message)
|
||||
|
||||
if(createMessageLocally.isOk()) {
|
||||
|
||||
console.log('==========================',message);
|
||||
if(message.hasAttachment) {
|
||||
|
||||
for (const attachment of message.attachments) {
|
||||
|
||||
this.AttachmentRepositoryService.create({
|
||||
$messageId: createMessageLocally.value.$id,
|
||||
file: createDataURL(attachment.file, attachment.mimeType)
|
||||
}).then((e) => {
|
||||
if(e.isErr()) {
|
||||
console.log('e', e.error, createDataURL(attachment.file, attachment.mimeType))
|
||||
}
|
||||
})
|
||||
console.log(attachment)
|
||||
if(attachment.source != MessageAttachmentSource.Webtrix) {
|
||||
|
||||
attachment.safeFile = createDataURL(attachment.file, attachment.mimeType)
|
||||
this.AttachmentRepositoryService.create({
|
||||
$messageId: createMessageLocally.value.$id,
|
||||
file: createDataURL(attachment.file, attachment.mimeType)
|
||||
}).then((e) => {
|
||||
if(e.isErr()) {
|
||||
Logger.error('failed to create attachment locally on send message', {
|
||||
error: e.error,
|
||||
data: createDataURL(attachment.file, attachment.mimeType).slice(0, 100) +'...'
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
attachment.safeFile = createDataURL(attachment.file, attachment.mimeType)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const sendToServer = await this.MessageRepositoryService.sendMessage(message)
|
||||
|
||||
|
||||
if(!sendToServer.isOk()) {
|
||||
console.log('sendToServer error', sendToServer.error)
|
||||
Logger.error('failed to send message to the server', {
|
||||
error: sendToServer.error
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
return sendToServer
|
||||
}
|
||||
|
||||
@@ -78,12 +85,13 @@ export class MessageCreateUseCaseService {
|
||||
} else {
|
||||
|
||||
if(validation.error.formErrors.fieldErrors.attachments) {
|
||||
console.log(message.attachments)
|
||||
console.error('invalid attachment', validation.error.formErrors.fieldErrors.attachments)
|
||||
Logger.error('failed to send message doe to invalid attachment', {
|
||||
zodErrorList: validation.error.errors,
|
||||
data: message.attachments
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user