This commit is contained in:
Peter Maquiran
2024-08-13 10:52:35 +01:00
parent 5b31a186c2
commit 251f533a68
53 changed files with 985 additions and 453 deletions
@@ -0,0 +1,13 @@
import { z } from "zod";
import { EntityTable } from 'Dexie';
export const AttachmentTableSchema = z.object({
id: z.string(),
$id: z.string(),
messageId: z.string(),
file: z.string(),
})
export type AttachmentTable = z.infer<typeof AttachmentTableSchema>
export type DexieAttachmentsTableSchema = EntityTable<AttachmentTable, '$id'>;
export const AttachmentTableColumn = '++$id, id, messageId, file'
@@ -1,5 +1,6 @@
import { z } from "zod";
import { nativeEnum, z } from "zod";
import { EntityTable } from 'Dexie';
import { MessageAttachmentFileType, MessageAttachmentSource } from "src/app/module/chat/data/dto/message/messageOutputDTO";
export const MessageTable = z.object({
$id: z.number().optional(),
@@ -25,7 +26,14 @@ export const MessageTable = z.object({
sender: z.object({}),
}).array().optional(),
info: z.array(z.object({})).optional(),
attachments: z.array(z.object({})).optional()
attachments: z.array(z.object({
fileType: z.nativeEnum(MessageAttachmentFileType),
source: z.nativeEnum(MessageAttachmentSource),
file: z.string().optional(),
fileName: z.string().optional(),
applicationId: z.string().optional(),
docId: z.string().optional()
})).optional()
})
export type MessageTable = z.infer<typeof MessageTable>
@@ -5,6 +5,7 @@ import { DexieMembersTableSchema, MemberTableColumn } from './schema/members';
import { DexieRoomsTableSchema, RoomTableColumn } from './schema/room';
import { DexieTypingsTableSchema, TypingTableColumn } from './schema/typing';
import { MessageEntity } from '../../../domain/entity/message';
import { AttachmentTable, AttachmentTableColumn, DexieAttachmentsTableSchema } from './schema/attachment';
// import DexieMemory from 'dexie-in-memory';
// Database declaration (move this to its own module also)
@@ -12,14 +13,16 @@ export const chatDatabase = new Dexie('chat-database-infra') as Dexie & {
message: DexieMessageTable,
members: DexieMembersTableSchema,
room: DexieRoomsTableSchema,
typing: DexieTypingsTableSchema
typing: DexieTypingsTableSchema,
attachment: DexieAttachmentsTableSchema,
};
chatDatabase.version(1).stores({
message: messageTableColumn,
members: MemberTableColumn,
room: RoomTableColumn,
typing: TypingTableColumn
typing: TypingTableColumn,
attachment: AttachmentTableColumn
});
chatDatabase.message.mapToClass(MessageEntity)