Files
doneit-web/src/app/services/Repositorys/chat/data-source/room/rooom-local-data-source.service.ts
T
Peter Maquiran 39f89a92a5 add interface
2024-06-04 16:29:10 +01:00

82 lines
1.7 KiB
TypeScript

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<typeof tableSchema>
// Database declaration (move this to its own module also)
export const roomDataSource = new Dexie('FriendDatabase') as Dexie & {
room: EntityTable<TableRoom, 'id'>;
};
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<RoomListOutPutDTO[]> {
return liveQuery(() => roomDataSource.room.toArray()) as any;
}
}