mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
change room name for direct room
This commit is contained in:
@@ -1,4 +1,63 @@
|
||||
import { SessionStore } from "src/app/store/session.service";
|
||||
import { z } from "zod"
|
||||
|
||||
export enum RoomType {
|
||||
Group = 1,
|
||||
Direct = 2
|
||||
}
|
||||
|
||||
const UserSchema = z.object({
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string(),
|
||||
userPhoto: z.string().nullable(),
|
||||
});
|
||||
|
||||
const MemberSchema = z.object({
|
||||
id: z.string(),
|
||||
user: UserSchema,
|
||||
joinAt: z.string(),
|
||||
isAdmin: z.boolean()
|
||||
});
|
||||
|
||||
export const RoomEntitySchema = z.object({
|
||||
id: z.string(),
|
||||
roomName: z.string(),
|
||||
createdBy: z.object({
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string().email(),
|
||||
userPhoto: z.string().nullable().optional()// api check
|
||||
}),
|
||||
createdAt: z.any(),
|
||||
expirationDate: z.any().nullable(),
|
||||
roomType: z.nativeEnum(RoomType),
|
||||
members: z.array(MemberSchema).optional()
|
||||
})
|
||||
|
||||
export type IRoomEntity = z.infer<typeof RoomEntitySchema>
|
||||
|
||||
export class RoomEntity implements IRoomEntity{
|
||||
|
||||
id: typeof RoomEntitySchema._input.id
|
||||
roomName: typeof RoomEntitySchema._input.roomName
|
||||
createdBy: typeof RoomEntitySchema._input.createdBy
|
||||
createdAt: typeof RoomEntitySchema._input.createdAt
|
||||
expirationDate: typeof RoomEntitySchema._input.expirationDate
|
||||
roomType: typeof RoomEntitySchema._input.roomType
|
||||
members: typeof RoomEntitySchema._input.members
|
||||
|
||||
constructor(data: IRoomEntity) {
|
||||
Object.assign(this, data)
|
||||
if(data.roomType == RoomType.Direct) {
|
||||
this.setName()
|
||||
}
|
||||
}
|
||||
|
||||
setName() {
|
||||
const userChatName = this.members?.find((e) => e.user.wxUserId != SessionStore.user.UserId)
|
||||
if(userChatName) {
|
||||
this.roomName = userChatName.user.wxFullName
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { RoomByIdOutputDTO } from "src/app/module/chat/domain/use-case/room/room-get-by-id-use-case.service";
|
||||
import { RoomEntity } from "../entity/group";
|
||||
|
||||
export class GetRoomByIdMapper {
|
||||
static toDomain(input: RoomByIdOutputDTO): RoomEntity {
|
||||
|
||||
return new RoomEntity({
|
||||
createdAt: input.data.createdAt,
|
||||
createdBy: input.data.createdBy,
|
||||
expirationDate: input.data.expirationDate,
|
||||
id: input.data.id,
|
||||
members: input.data.members,
|
||||
roomName: input.data.roomName,
|
||||
roomType: input.data.roomType
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { RoomListItemOutPutDTO } from "src/app/module/chat/domain/use-case/room/room-get-list-use-case.service";
|
||||
import { RoomEntity } from "../entity/group";
|
||||
import { captureAndReraiseAsync } from "src/app/services/decorators/captureAndReraiseAsync";
|
||||
|
||||
export class GetRoomListMapper{
|
||||
|
||||
// @captureAndReraiseAsync('GetRoomListMapper/toDomain')
|
||||
static toDomain(inputs: RoomListItemOutPutDTO[]): RoomEntity[] {
|
||||
|
||||
return inputs.map((roomData) => new RoomEntity({
|
||||
createdAt: roomData.chatRoom.createdAt,
|
||||
createdBy: roomData.chatRoom.createdBy,
|
||||
expirationDate: roomData.chatRoom.expirationDate,
|
||||
id: roomData.chatRoom.id,
|
||||
roomName: roomData.chatRoom.roomName,
|
||||
roomType: roomData.chatRoom.roomType,
|
||||
members: [roomData.chatRoom.user1, roomData.chatRoom.user2].filter((e) => e?.wxUserId).map((b) => ({
|
||||
id: '',
|
||||
isAdmin: false,
|
||||
joinAt: '',
|
||||
user: {
|
||||
userPhoto: b.userPhoto,
|
||||
wxeMail: b.wxeMail,
|
||||
wxFullName: b.wxFullName,
|
||||
wxUserId: b.wxUserId
|
||||
}
|
||||
}))
|
||||
}));
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user