import { Injectable } from '@angular/core'; import { AddMemberToRoomInputDTO } from '../../dto/room/addMemberToRoomInputDto'; import { RoomListOutPutDTO } from '../../dto/room/roomListOutputDTO'; import { Dexie, EntityTable, liveQuery } from 'Dexie'; import { err, ok } from 'neverthrow'; import { Observable } from 'rxjs'; import { RoomOutPutDTO } from '../../dto/room/roomOutputDTO'; import { z } from 'zod'; const tableSchema = z.object({ id: z.string(), roomName: z.string(), createdBy: z.any(), createdAt: z.any(), expirationDate: z.any(), roomType: z.any() }) export type TableRoom = z.infer // Database declaration (move this to its own module also) export const roomDataSource = new Dexie('FriendDatabase') as Dexie & { room: EntityTable; }; roomDataSource.version(1).stores({ room: '++id, createdBy, roomName, roomType, expirationDate' }); @Injectable({ providedIn: 'root' }) export class RoomLocalDataSourceService { private baseUrl = 'https://gdapi-dev.dyndns.info/stage/api/v2/Chat'; // Your base URL constructor() {} async createRoom(data: RoomOutPutDTO) { try { const result = await roomDataSource.room.add(data.data) return ok(result) } catch (e) { return err(false) } } async getRoomList() { } async getRoom(id: string){ } async updateRoom(id: string, room: any) { } async deleteRoom(id: string){ } async addMemberToRoom(data: AddMemberToRoomInputDTO) { } async removeMemberFromRoom(id: string, member: any){ } getItemsLive(): Observable { return liveQuery(() => roomDataSource.room.toArray()) as any; } }