mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
create room
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
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 Table = z.infer<typeof tableSchema>
|
||||
|
||||
// Database declaration (move this to its own module also)
|
||||
export const roomDataSource = new Dexie('FriendDatabase') as Dexie & {
|
||||
room: EntityTable<Table, '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) {
|
||||
|
||||
const roomData = {
|
||||
createdBy: {
|
||||
wxUserId: 0,
|
||||
wxFullName: "",
|
||||
wxeMail: "",
|
||||
userPhoto: ""
|
||||
},
|
||||
roomName: data.data.roomName,
|
||||
id: data.data.id,
|
||||
roomType: 21,
|
||||
expirationDate: '',
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await roomDataSource.room.add(roomData)
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user