list room

This commit is contained in:
Peter Maquiran
2024-06-05 11:09:03 +01:00
parent 2e9492db68
commit 1a319093ee
6 changed files with 32 additions and 8 deletions
+1
View File
@@ -167,6 +167,7 @@ export class ChatPage implements OnInit {
ngOnInit() { ngOnInit() {
this.items$ = this.RoomRepositoryService.getItemsLive() this.items$ = this.RoomRepositoryService.getItemsLive()
this.RoomRepositoryService.list();
this.segment = "Contactos"; this.segment = "Contactos";
@@ -23,8 +23,8 @@ export class RoomRemoteDataSourceService {
return await this.httpService.post<RoomOutPutDTO>(`${this.baseUrl}/Room`, data); return await this.httpService.post<RoomOutPutDTO>(`${this.baseUrl}/Room`, data);
} }
async getRoomList(): Promise<Result<RoomListOutPutDTO ,any>> { async getRoomList(): Promise<DataSourceReturn<RoomListOutPutDTO>> {
return await this.httpService.get<any>(`${this.baseUrl}/Room`); return await this.httpService.get<RoomListOutPutDTO>(`${this.baseUrl}/Room`);
} }
async getRoom(id: string): Promise<Result<any ,any>> { async getRoom(id: string): Promise<Result<any ,any>> {
@@ -28,6 +28,16 @@ roomDataSource.version(1).stores({
room: '++id, createdBy, roomName, roomType, expirationDate' room: '++id, createdBy, roomName, roomType, expirationDate'
}); });
interface CreateRoomParams {
id?: string;
roomName?: string;
createdBy?: any;
createdAt?: Date;
expirationDate?: Date;
roomType?: any;
}
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
@@ -38,10 +48,10 @@ export class RoomLocalDataSourceService {
constructor() {} constructor() {}
async createRoom(data: RoomOutPutDTO) { async createRoom(data: CreateRoomParams) {
try { try {
const result = await roomDataSource.room.add(data.data) const result = await roomDataSource.room.add(data)
return ok(result) return ok(result)
} catch (e) { } catch (e) {
return err(false) return err(false)
@@ -15,8 +15,15 @@ const RoomListItemOutPutDTOSchema = z.object({
expirationDate: z.string().datetime(), expirationDate: z.string().datetime(),
roomType: z.number() roomType: z.number()
}); });
// Define the schema for the entire response
const RoomListOutPutDTOSchema = z.object({
success: z.boolean(),
message: z.string(),
data: z.array(RoomListItemOutPutDTOSchema),
});
export type RoomListItemOutPutDTO = z.infer<typeof RoomListItemOutPutDTOSchema> export type RoomListItemOutPutDTO = z.infer<typeof RoomListItemOutPutDTOSchema>
const RoomListOutPutDTOSchema = z.array(RoomListItemOutPutDTOSchema);
export type RoomListOutPutDTO = z.infer<typeof RoomListOutPutDTOSchema> export type RoomListOutPutDTO = z.infer<typeof RoomListOutPutDTOSchema>
@@ -21,6 +21,12 @@ export class RoomRepositoryService {
async list() { async list() {
const result = await this.roomRemoteDataSourceService.getRoomList() const result = await this.roomRemoteDataSourceService.getRoomList()
if(result.isOk()) {
for( const roomData of result.value.data) {
this.roomLocalDataSourceService.createRoom(roomData as any)
}
}
return result return result
} }
@@ -35,7 +41,7 @@ export class RoomRepositoryService {
console.log('result', result) console.log('result', result)
this.roomMemoryDataSourceService.dispatch( addRoom(result.value) ) this.roomMemoryDataSourceService.dispatch( addRoom(result.value) )
this.roomLocalDataSourceService.createRoom(result.value) this.roomLocalDataSourceService.createRoom(result.value.data)
} }
return result return result
@@ -183,7 +183,7 @@ export class NewGroupPage implements OnInit{
if(result.isOk()) { if(result.isOk()) {
this.addGroupMessage.emit(result); // this.addGroupMessage.emit(result);
} else if(result.error instanceof HttpErrorResponse) { } else if(result.error instanceof HttpErrorResponse) {