mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
separate database from source data
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { z } from "zod";
|
||||
import { EntityTable } from 'Dexie';
|
||||
|
||||
export const MemberTableSchema = z.object({
|
||||
$roomIdUserId: z.string().optional(),
|
||||
id: z.string(),
|
||||
roomId: z.string(),
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string(),
|
||||
userPhoto: z.string().nullable(),
|
||||
joinAt: z.string(),
|
||||
status: z.string(),
|
||||
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,31 @@
|
||||
import { z } from "zod";
|
||||
import { EntityTable } from 'Dexie';
|
||||
|
||||
export const MessageTable = z.object({
|
||||
$id: z.number().optional(),
|
||||
id: z.string().optional(),
|
||||
roomId: z.string().uuid(),
|
||||
message: z.string(),
|
||||
messageType: z.number(),
|
||||
canEdit: z.boolean(),
|
||||
oneShot: z.boolean(),
|
||||
sentAt: z.string().optional(),
|
||||
requireUnlock: z.boolean(),
|
||||
sender: z.object({
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string(),
|
||||
userPhoto: z.string(),
|
||||
}),
|
||||
sending: z.boolean().optional(),
|
||||
reaction: z.object({
|
||||
id: z.string(),
|
||||
reactedAt: z.string(),
|
||||
reaction: z.string(),
|
||||
sender: z.object({}),
|
||||
}).array()
|
||||
})
|
||||
|
||||
export type MessageTable = z.infer<typeof MessageTable>
|
||||
export type DexieMessageTable = EntityTable<MessageTable, '$id'>;
|
||||
export const messageTableColumn = '++id, roomId, senderId, message, messageType, canEdit, oneShot, requireUnlock'
|
||||
@@ -0,0 +1,19 @@
|
||||
import { z } from "zod";
|
||||
import { EntityTable } from 'Dexie';
|
||||
|
||||
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(),
|
||||
})
|
||||
|
||||
export type RoomTable = z.infer<typeof RoomTableSchema>
|
||||
export type DexieRoomsTableSchema = 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.string(),
|
||||
roomId: z.string(),
|
||||
entryDate: z.string()
|
||||
})
|
||||
|
||||
export type TypingTable = z.infer<typeof TypingTableSchema>
|
||||
export type DexieTypingsTableSchema = EntityTable<TypingTable, 'id'>;
|
||||
export const TypingTableColumn = '++id, userId, roomId, entryDate'
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
import { Dexie, EntityTable, liveQuery } from 'Dexie';
|
||||
import { DexieMessageTable, messageTableColumn, MessageTable } from './schema/message';
|
||||
import { DexieMembersTableSchema, MemberTableColumn } from './schema/members';
|
||||
import { DexieRoomsTableSchema, RoomTableColumn } from './schema/room';
|
||||
import { DexieTypingsTableSchema, TypingTableColumn } from './schema/typing';
|
||||
|
||||
// Database declaration (move this to its own module also)
|
||||
export const chatDatabase = new Dexie('chat-database') as Dexie & {
|
||||
message: DexieMessageTable,
|
||||
members: DexieMembersTableSchema,
|
||||
room: DexieRoomsTableSchema,
|
||||
typing: DexieTypingsTableSchema
|
||||
};
|
||||
|
||||
chatDatabase.version(1).stores({
|
||||
message: messageTableColumn,
|
||||
members: MemberTableColumn,
|
||||
room: RoomTableColumn,
|
||||
typing: TypingTableColumn
|
||||
});
|
||||
Reference in New Issue
Block a user