mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
leave room
This commit is contained in:
+13
-1
@@ -3,11 +3,17 @@ import { RoomListItemOutPutDTO, RoomListOutPutDTO } from '../../dto/room/roomLis
|
||||
import { Dexie, EntityTable, liveQuery, Observable } from 'Dexie';
|
||||
import { err, ok, Result } from 'neverthrow';
|
||||
import { z } from 'zod';
|
||||
import { ValidateSchema } from 'src/app/services/decorators/validate-schema.decorator';
|
||||
|
||||
const tableSchema = z.object({
|
||||
id: z.string(),
|
||||
roomName: z.string(),
|
||||
createdBy: z.any(),
|
||||
createdBy: z.object({
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string().email(),
|
||||
userPhoto: z.string().nullable()// api check
|
||||
}),
|
||||
createdAt: z.any(),
|
||||
expirationDate: z.any(),
|
||||
roomType: z.any()
|
||||
@@ -49,6 +55,7 @@ export class RoomLocalDataSourceService {
|
||||
|
||||
constructor() {}
|
||||
|
||||
@ValidateSchema(tableSchema)
|
||||
async createRoom(data: TableRoom) {
|
||||
try {
|
||||
const result = await roomDataSource.room.add(data)
|
||||
@@ -68,6 +75,11 @@ export class RoomLocalDataSourceService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async leaveRoom(id: string) {
|
||||
return this.deleteRoomById(id)
|
||||
}
|
||||
|
||||
async updateRoom(data: TableRoom) {
|
||||
try {
|
||||
const result = await roomDataSource.room.update(data.id, data);
|
||||
|
||||
@@ -58,6 +58,10 @@ export class RoomRepositoryService {
|
||||
const { roomsToDelete, roomsToInsert, roomsToUpdate } = roomListDetermineChanges([result.value.data], localList)
|
||||
|
||||
for( const roomData of roomsToUpdate) {
|
||||
if(!roomData.createdBy?.wxUserId) {
|
||||
delete roomData.createdBy;
|
||||
}
|
||||
|
||||
this.roomLocalDataSourceService.updateRoom(roomData)
|
||||
}
|
||||
|
||||
@@ -132,6 +136,17 @@ export class RoomRepositoryService {
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
async leaveRoom(data: UserRemoveListInputDTO) {
|
||||
const result = await this.roomRemoteDataSourceService.removeMemberFromRoom(data)
|
||||
|
||||
if(result.isOk()) {
|
||||
return this.roomLocalDataSourceService.leaveRoom(data.id)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
getItemsLive() {
|
||||
return this.roomLocalDataSourceService.getItemsLive()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user