mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
move database to infra
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { MessageTable } from "src/app/module/chat/infra/database/dexie/schema/message";
|
||||
import { MessageTable } from "src/app/infra/database/dexie/instance/chat/schema/message";
|
||||
import { RoomListItemOutPutDTO, RoomListOutPutDTO } from "../../../dto/room/roomListOutputDTO";
|
||||
|
||||
export function messageListDetermineChanges(serverList: MessageTable[], localList: MessageTable[]) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { RoomTable } from "src/app/module/chat/infra/database/dexie/schema/room";
|
||||
import { RoomTable } from "src/app/infra/database/dexie/instance/chat/schema/room";
|
||||
import { RoomListItemOutPutDTO, RoomListOutPutDTO } from "../../../dto/room/roomListOutputDTO";
|
||||
|
||||
export function roomListDetermineChanges(serverRooms: RoomListItemOutPutDTO[], localRooms: RoomTable[]) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MemberTable } from "src/app/module/chat/infra/database/dexie/schema/members";
|
||||
import { MemberTable } from "src/app/infra/database/dexie/instance/chat/schema/members";
|
||||
import { RoomByIdMemberItemOutputDTO } from "../../../dto/room/roomByIdOutputDTO";
|
||||
|
||||
export function roomMemberListDetermineChanges(____serverRooms: RoomByIdMemberItemOutputDTO[], localRooms: MemberTable[], roomId: string) {
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
import { AttachmentTable, AttachmentTableSchema } from 'src/app/infra/database/dexie/instance/chat/schema/attachment';
|
||||
import { chatDatabase } from 'src/app/infra/database/dexie/service';
|
||||
import { DexieRepository } from 'src/app/infra/repository/dexie/dexie-repository.service';
|
||||
import { chatDatabase } from '../../../infra/database/dexie/service';
|
||||
import { AttachmentTable, AttachmentTableSchema } from '../../../infra/database/dexie/schema/attachment';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
||||
@@ -2,12 +2,12 @@ import { Injectable } from '@angular/core';
|
||||
import { Dexie, EntityTable, liveQuery, Observable } from 'Dexie';
|
||||
import { z } from 'zod';
|
||||
import { DexieRepository } from 'src/app/infra/repository/dexie/dexie-repository.service';
|
||||
import { chatDatabase } from '../../../infra/database/dexie/service';
|
||||
import { ok } from 'neverthrow';
|
||||
import { err, Result } from 'neverthrow';
|
||||
import { MemberListUPdateStatusInputDTO } from '../../../domain/use-case/socket/member-list-update-status-use-case.service';
|
||||
import { MemberTable, MemberTableSchema } from '../../../infra/database/dexie/schema/members';
|
||||
import { from } from 'rxjs';
|
||||
import { MemberTable, MemberTableSchema } from 'src/app/infra/database/dexie/instance/chat/schema/members';
|
||||
import { chatDatabase } from 'src/app/infra/database/dexie/service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
||||
@@ -5,9 +5,9 @@ import { Observable, Subject } from 'rxjs';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { MessageEntity } from '../../../../../core/chat/entity/message';
|
||||
import { DexieRepository } from 'src/app/infra/repository/dexie/dexie-repository.service';
|
||||
import { MessageTable, MessageTableSchema } from 'src/app/module/chat/infra/database/dexie/schema/message';
|
||||
import { chatDatabase } from '../../../infra/database/dexie/service';
|
||||
import { Observable as DexieObservable, PromiseExtended } from 'Dexie';
|
||||
import { MessageTable, MessageTableSchema } from 'src/app/infra/database/dexie/instance/chat/schema/message';
|
||||
import { chatDatabase } from 'src/app/infra/database/dexie/service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
||||
@@ -4,10 +4,10 @@ import { liveQuery, Observable } from 'Dexie';
|
||||
import { err, ok, Result } from 'neverthrow';
|
||||
import { z } from 'zod';
|
||||
import { ValidateSchema } from 'src/app/services/decorators/validate-schema.decorator';
|
||||
import { chatDatabase } from '../../../infra/database/dexie/service';
|
||||
import { RoomTable, RoomTableSchema } from '../../../infra/database/dexie/schema/room';
|
||||
import { DexieRepository } from 'src/app/infra/repository/dexie/dexie-repository.service';
|
||||
import { from } from 'rxjs';
|
||||
import { RoomTable, RoomTableSchema } from 'src/app/infra/database/dexie/instance/chat/schema/room';
|
||||
import { chatDatabase } from 'src/app/infra/database/dexie/service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
||||
@@ -2,8 +2,8 @@ import { Injectable } from '@angular/core';
|
||||
import { z } from 'zod';
|
||||
import { Dexie, EntityTable, liveQuery, Observable } from 'Dexie';
|
||||
import { err, ok } from 'neverthrow';
|
||||
import { chatDatabase } from '../../../infra/database/dexie/service';
|
||||
import { TypingTable } from '../../../infra/database/dexie/schema/typing';
|
||||
import { chatDatabase } from 'src/app/infra/database/dexie/service';
|
||||
import { TypingTable } from 'src/app/infra/database/dexie/instance/chat/schema/typing';
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
import { MemberTable } from "src/app/infra/database/dexie/instance/chat/schema/members";
|
||||
import { RoomByIdMemberItemOutputDTO } from "../../data/dto/room/roomByIdOutputDTO";
|
||||
import { MemberTable } from "../../infra/database/dexie/schema/members";
|
||||
|
||||
export function MemberListMapper(outputDto: RoomByIdMemberItemOutputDTO, roomId: string): MemberTable {
|
||||
return {
|
||||
|
||||
@@ -11,12 +11,12 @@ import { MessageAttachmentSource, MessageOutPutDataDTO } from '../../../data/dto
|
||||
import { MessageLocalDataSourceService } from '../../../data/repository/message/message-local-data-source.service';
|
||||
import { MessageSocketRepositoryService } from '../../../data/repository/message/message-live-signalr-data-source.service';
|
||||
import { err, Result } from 'neverthrow';
|
||||
import { MessageTable } from '../../../infra/database/dexie/schema/message';
|
||||
import { MessageMapper } from '../../mapper/messageMapper';
|
||||
import { RoomType } from "src/app/core/chat/entity/group";
|
||||
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
|
||||
import { MemberListLocalRepository } from 'src/app/module/chat/data/repository/member/member-list-local-repository.service'
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { MessageTable } from 'src/app/infra/database/dexie/instance/chat/schema/message';
|
||||
|
||||
const MessageInputUseCaseSchema = z.object({
|
||||
memberId: z.number(),
|
||||
|
||||
+1
-1
@@ -1,7 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MessageLocalDataSourceService } from '../../../data/repository/message/message-local-data-source.service';
|
||||
import { MessageSocketRepositoryService } from '../../../data/repository/message/message-live-signalr-data-source.service';
|
||||
import { MessageTable } from '../../../infra/database/dexie/schema/message';
|
||||
import { InstanceId } from '../../chat-service.service';
|
||||
import { MessageMapper } from '../../mapper/messageMapper';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
@@ -12,6 +11,7 @@ import { Result } from 'neverthrow';
|
||||
import { RoomType } from 'src/app/core/chat/entity/group';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { MessageOutPutDataDTO } from '../../../data/dto/message/messageOutputDTO';
|
||||
import { MessageTable } from 'src/app/infra/database/dexie/instance/chat/schema/message';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MessageLocalDataSourceService } from '../../../data/repository/message/message-local-data-source.service';
|
||||
import { messageListDetermineChanges } from '../../../data/async/list/rooms/messageListChangedetector';
|
||||
import { MessageTable } from '../../../infra/database/dexie/schema/message';
|
||||
import { MessageRemoteDataSourceService } from '../../../data/repository/message/message-remote-data-source.service';
|
||||
import { MessageSocketRepositoryService } from '../../../data/repository/message/message-live-signalr-data-source.service';
|
||||
import { ok } from 'neverthrow';
|
||||
@@ -10,6 +9,7 @@ import { SessionStore } from 'src/app/store/session.service';
|
||||
import { Logger } from 'src/app/services/logger/main/service';
|
||||
import { XTracerAsync, TracingType } from 'src/app/services/monitoring/opentelemetry/tracer';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { MessageTable } from 'src/app/infra/database/dexie/instance/chat/schema/message';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
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'
|
||||
@@ -1,19 +0,0 @@
|
||||
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'
|
||||
@@ -1,51 +0,0 @@
|
||||
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'
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
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'
|
||||
@@ -1,13 +0,0 @@
|
||||
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'
|
||||
@@ -1,34 +0,0 @@
|
||||
|
||||
import { Dexie } from 'Dexie';
|
||||
import { DexieMessageTable, messageTableColumn, MessageTable } from './schema/message';
|
||||
import { DexieMembersTableSchema, MemberTableColumn } from './schema/members';
|
||||
import { DexieRoomsTable, RoomTableColumn } from './schema/room';
|
||||
import { DexieTypingsTable, TypingTableColumn } from './schema/typing';
|
||||
import { MessageEntity } from '../../../../../core/chat/entity/message';
|
||||
import { AttachmentTableColumn, DexieAttachmentsTableSchema } from './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
|
||||
@@ -133,7 +133,7 @@ export class SignalRConnection {
|
||||
first()
|
||||
).subscribe(value => {
|
||||
resolve(ok(value.data as unknown as T))
|
||||
console.log('Received valid value:', value);
|
||||
// console.log('Received valid value:', value);
|
||||
});
|
||||
|
||||
} catch(error) {
|
||||
|
||||
Reference in New Issue
Block a user