mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
add error message
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ export class MessageRemoteDataSourceService {
|
||||
|
||||
constructor(private httpService: HttpService) {}
|
||||
|
||||
@APIReturn(MessageOutPutDTOSchema)
|
||||
@APIReturn(MessageOutPutDTOSchema, 'get/Messages')
|
||||
@ValidateSchema(MessageInputDTOSchema)
|
||||
async sendMessage(data: MessageInputDTO) {
|
||||
return await this.httpService.post<MessageOutPutDTO>(`${this.baseUrl}/Messages`, data);
|
||||
|
||||
+3
-3
@@ -23,19 +23,19 @@ export class RoomRemoteDataSourceService {
|
||||
|
||||
|
||||
@ValidateSchema(RoomInputDTOSchema)
|
||||
@APIReturn(RoomOutPutDTOSchema)
|
||||
@APIReturn(RoomOutPutDTOSchema, 'post/Room')
|
||||
async createRoom(data: RoomInputDTO): DataSourceReturn<RoomOutPutDTO> {
|
||||
return await this.httpService.post<RoomOutPutDTO>(`${this.baseUrl}/Room`, data);
|
||||
}
|
||||
|
||||
|
||||
@APIReturn(RoomListOutPutDTOSchema)
|
||||
@APIReturn(RoomListOutPutDTOSchema, 'get/Room')
|
||||
async getRoomList(): Promise<DataSourceReturn<RoomListOutPutDTO>> {
|
||||
return await this.httpService.get<RoomListOutPutDTO>(`${this.baseUrl}/Room`);
|
||||
}
|
||||
|
||||
@ValidateSchema(RoomByIdInputDTOSchema)
|
||||
@APIReturn(RoomByIdOutputDTOSchema)
|
||||
@APIReturn(RoomByIdOutputDTOSchema,'get/Room/${id}')
|
||||
async getRoom(id: RoomByIdInputDTO): DataSourceReturn<RoomByIdOutputDTO> {
|
||||
return await this.httpService.get(`${this.baseUrl}/Room/${id}`);
|
||||
}
|
||||
|
||||
@@ -58,6 +58,16 @@ export class RoomLocalDataSourceService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async deleteRoomById(id: string) {
|
||||
try {
|
||||
const result = await roomDataSource.room.delete(id)
|
||||
return ok(result)
|
||||
} catch (e) {
|
||||
return err(false)
|
||||
}
|
||||
}
|
||||
|
||||
async updateRoom(data: TableRoom) {
|
||||
try {
|
||||
const result = await roomDataSource.room.update(data.id, data);
|
||||
|
||||
@@ -4,7 +4,8 @@ export const RoomInputDTOSchema = z.object({
|
||||
roomName: z.string(),
|
||||
createdBy: z.number(),
|
||||
roomType: z.number(),
|
||||
expirationDate: z.string().datetime().nullable()
|
||||
expirationDate: z.string().datetime().nullable(),
|
||||
members: z.array(z.number())
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const RoomOutPutDTOSchema = z.object({
|
||||
success: z.string(),
|
||||
success: z.boolean(),
|
||||
message: z.string(),
|
||||
data: z.object({
|
||||
id: z.string(),
|
||||
roomName: z.string(),
|
||||
createdBy: z.any(),
|
||||
createdAt: z.date(),
|
||||
expirationDate: z.date(),
|
||||
createdAt: z.string(),
|
||||
expirationDate: z.string().nullable(),
|
||||
roomType: z.any()
|
||||
})
|
||||
});
|
||||
|
||||
@@ -9,6 +9,7 @@ import { RoomByIdInputDTO } from '../dto/room/roomByIdInputDTO';
|
||||
import { roomListDetermineChanges } from '../async/rooms/roomListChangeDetector';
|
||||
import { UserRemoveListInputDTO } from '../dto/room/userRemoveListInputDTO';
|
||||
import { roomMemberListDetermineChanges } from '../async/rooms/roomMembersChangeDetector';
|
||||
import { captureAndReraiseAsync } from 'src/app/services/decorators/captureAndReraiseAsync';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -21,6 +22,7 @@ export class RoomRepositoryService {
|
||||
private roomLocalDataSourceService: RoomLocalDataSourceService
|
||||
) { }
|
||||
|
||||
@captureAndReraiseAsync('RoomRepositoryService/list')
|
||||
async list() {
|
||||
const result = await this.roomRemoteDataSourceService.getRoomList()
|
||||
|
||||
@@ -33,15 +35,25 @@ export class RoomRepositoryService {
|
||||
if(result.isOk()) {
|
||||
const { roomsToDelete, roomsToInsert, roomsToUpdate } = roomListDetermineChanges(result.value.data, localList)
|
||||
|
||||
console.log({ roomsToDelete, roomsToInsert, roomsToUpdate })
|
||||
console.log({roomsToDelete, roomsToInsert, roomsToUpdate})
|
||||
|
||||
for( const roomData of roomsToInsert) {
|
||||
this.roomLocalDataSourceService.createOrUpdateRoom(roomData)
|
||||
this.roomLocalDataSourceService.createRoom(roomData)
|
||||
}
|
||||
|
||||
for( const roomData of roomsToUpdate) {
|
||||
this.roomLocalDataSourceService.updateRoom(roomData)
|
||||
}
|
||||
|
||||
for( const roomData of roomsToDelete) {
|
||||
this.roomLocalDataSourceService.deleteRoomById(roomData.id)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@captureAndReraiseAsync('RoomRepositoryService/getRoomById')
|
||||
async getRoomById(id: RoomByIdInputDTO) {
|
||||
const result = await this.roomRemoteDataSourceService.getRoom(id)
|
||||
|
||||
@@ -50,6 +62,13 @@ export class RoomRepositoryService {
|
||||
|
||||
const { membersToInsert, membersToUpdate, membersToDelete } = roomMemberListDetermineChanges(result.value.data.members, localList, id)
|
||||
|
||||
|
||||
const a = await this.roomLocalDataSourceService.createOrUpdateRoom(result.value.data)
|
||||
|
||||
if(a.isErr()) {
|
||||
return a
|
||||
}
|
||||
|
||||
for (const user of membersToInsert) {
|
||||
this.roomLocalDataSourceService.addMember({...user, roomId:id})
|
||||
}
|
||||
@@ -63,6 +82,7 @@ export class RoomRepositoryService {
|
||||
return result
|
||||
}
|
||||
|
||||
@captureAndReraiseAsync('RoomRepositoryService/create')
|
||||
async create(data: RoomInputDTO) {
|
||||
|
||||
const result = await this.roomRemoteDataSourceService.createRoom(data)
|
||||
|
||||
Reference in New Issue
Block a user