mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
move database to infra
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { z } from "zod";
|
||||
import { EntityTable } from 'Dexie';
|
||||
import { zodDataUrlSchema } from "src/app/utils/zod";
|
||||
import { MessageAttachmentFileType, MessageAttachmentSource } from "src/app/module/chat/data/dto/message/messageOutputDTO";
|
||||
|
||||
export const AttachmentTableSchema = z.object({
|
||||
$id: z.number().optional(), // local id
|
||||
$messageId: z.number(),
|
||||
attachmentId: z.string().optional(),
|
||||
file: zodDataUrlSchema,
|
||||
//
|
||||
fileType: z.nativeEnum(MessageAttachmentFileType),
|
||||
source: z.nativeEnum(MessageAttachmentSource),
|
||||
fileName: z.string().optional(),
|
||||
applicationId: z.number().optional(),
|
||||
docId: z.string().optional(),
|
||||
mimeType: z.string().optional(),
|
||||
id: z.string().optional(),
|
||||
description: z.string().optional()
|
||||
})
|
||||
|
||||
export type AttachmentTable = z.infer<typeof AttachmentTableSchema>
|
||||
export type DexieAttachmentsTableSchema = EntityTable<AttachmentTable, '$id'>;
|
||||
export const AttachmentTableColumn = '++$id, id, $messageId, messageId, file'
|
||||
@@ -0,0 +1,19 @@
|
||||
import { z } from "zod";
|
||||
import { EntityTable } from 'Dexie';
|
||||
|
||||
export const MemberTableSchema = z.object({
|
||||
$roomIdUserId: z.string().optional(),
|
||||
id: z.string().optional(), // useless
|
||||
roomId: z.string(),
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string(),
|
||||
userPhoto: z.string().nullable(),
|
||||
joinAt: z.string(),
|
||||
status: z.string().optional(), // useless
|
||||
isAdmin: z.boolean()
|
||||
})
|
||||
|
||||
export type MemberTable = z.infer<typeof MemberTableSchema>
|
||||
export type DexieMembersTableSchema = EntityTable<MemberTable, '$roomIdUserId'>;
|
||||
export const MemberTableColumn = '$roomIdUserId, userId, id, user, joinAt, roomId, status, wxUserId, isAdmin'
|
||||
@@ -0,0 +1,51 @@
|
||||
import { EntityTable } from 'Dexie';
|
||||
import { MessageAttachmentFileType, MessageAttachmentSource } from "src/app/module/chat/data/dto/message/messageOutputDTO";
|
||||
import { z } from 'zod';
|
||||
|
||||
export const MessageTableSchema = z.object({
|
||||
$id: z.number().optional(),
|
||||
id: z.string().optional(),
|
||||
roomId: z.string().uuid().optional(),
|
||||
message: z.string().nullable().optional(),
|
||||
messageType: z.number(),
|
||||
canEdit: z.boolean(),
|
||||
oneShot: z.boolean(),
|
||||
sentAt: z.string().optional(),
|
||||
editedAt: z.string().nullable().optional(),
|
||||
isDeleted: z.boolean().optional(),
|
||||
requireUnlock: z.boolean(),
|
||||
sender: z.object({
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string(),
|
||||
userPhoto: z.string(),
|
||||
}),
|
||||
receiverId: z.number().optional(),
|
||||
sending: z.boolean().optional(),
|
||||
reactions: z.object({
|
||||
id: z.string(),
|
||||
reactedAt: z.string(),
|
||||
reaction: z.string(),
|
||||
sender: z.object({}),
|
||||
}).array().optional(),
|
||||
info: z.array(z.object({
|
||||
memberId: z.number(),
|
||||
readAt: z.string().nullable(),
|
||||
deliverAt: z.string().nullable()
|
||||
})).optional(),
|
||||
attachments: z.array(z.object({
|
||||
fileType: z.nativeEnum(MessageAttachmentFileType),
|
||||
source: z.nativeEnum(MessageAttachmentSource),
|
||||
fileName: z.string().optional(),
|
||||
applicationId: z.number().optional(),
|
||||
docId: z.string().optional(),
|
||||
id: z.string().optional(),
|
||||
description: z.string().nullable().optional(),
|
||||
mimeType: z.string().optional()
|
||||
})).optional()
|
||||
})
|
||||
|
||||
export type MessageTable = z.infer<typeof MessageTableSchema>
|
||||
export type DexieMessageTable = EntityTable<MessageTable, '$id'>;
|
||||
export const messageTableColumn = '++$id, id, roomId, senderId, message, messageType, canEdit, oneShot, requireUnlock'
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { z } from "zod";
|
||||
import { EntityTable } from 'Dexie';
|
||||
import { RoomType } from "src/app/core/chat/entity/group";
|
||||
|
||||
export const RoomTableSchema = z.object({
|
||||
id: z.string(),
|
||||
roomName: z.string(),
|
||||
createdBy: z.object({
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string().email(),
|
||||
userPhoto: z.string().nullable().optional()// api check
|
||||
}),
|
||||
createdAt: z.any(),
|
||||
expirationDate: z.any().nullable(),
|
||||
roomType: z.nativeEnum(RoomType)
|
||||
})
|
||||
|
||||
export type RoomTable = z.infer<typeof RoomTableSchema>
|
||||
export type DexieRoomsTable = EntityTable<RoomTable, 'id'>;
|
||||
export const RoomTableColumn = 'id, createdBy, roomName, roomType, expirationDate, lastMessage'
|
||||
@@ -0,0 +1,13 @@
|
||||
import { z } from "zod";
|
||||
import { EntityTable } from 'Dexie';
|
||||
|
||||
export const TypingTableSchema = z.object({
|
||||
id: z.string().optional(),
|
||||
userId: z.number().optional(),
|
||||
userName: z.string(),
|
||||
roomId: z.string(),
|
||||
})
|
||||
|
||||
export type TypingTable = z.infer<typeof TypingTableSchema>
|
||||
export type DexieTypingsTable = EntityTable<TypingTable, 'id'>;
|
||||
export const TypingTableColumn = 'id, userId, userName, roomId, entryDate'
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
import { Dexie } from 'Dexie';
|
||||
import { DexieMessageTable, messageTableColumn, MessageTable } from 'src/app/infra/database/dexie/instance/chat/schema/message';
|
||||
import { DexieMembersTableSchema, MemberTableColumn } from 'src/app/infra/database/dexie/instance/chat/schema/members';
|
||||
import { DexieRoomsTable, RoomTableColumn } from 'src/app/infra/database/dexie/instance/chat/schema/room';
|
||||
import { DexieTypingsTable, TypingTableColumn } from 'src/app/infra/database/dexie/instance/chat/schema/typing';
|
||||
import { MessageEntity } from 'src/app/core/chat/entity/message';
|
||||
import { AttachmentTableColumn, DexieAttachmentsTableSchema } from 'src/app/infra/database/dexie/instance/chat/schema/attachment';
|
||||
// import FDBFactory from 'fake-indexeddb/lib/FDBFactory';
|
||||
// import FDBKeyRange from 'fake-indexeddb/lib/FDBKeyRange';
|
||||
|
||||
|
||||
// Database declaration (move this to its own module also)
|
||||
export const chatDatabase = new Dexie('chat-database-infra',{
|
||||
// indexedDB: new FDBFactory,
|
||||
// IDBKeyRange: FDBKeyRange, // Mocking IDBKeyRange
|
||||
}) as Dexie & {
|
||||
message: DexieMessageTable,
|
||||
members: DexieMembersTableSchema,
|
||||
room: DexieRoomsTable,
|
||||
typing: DexieTypingsTable,
|
||||
attachment: DexieAttachmentsTableSchema,
|
||||
};
|
||||
|
||||
chatDatabase.version(1).stores({
|
||||
message: messageTableColumn,
|
||||
members: MemberTableColumn,
|
||||
room: RoomTableColumn,
|
||||
typing: TypingTableColumn,
|
||||
attachment: AttachmentTableColumn
|
||||
});
|
||||
|
||||
chatDatabase.message.mapToClass(MessageEntity)
|
||||
// Apply in-memory storage
|
||||
Reference in New Issue
Block a user