聊天:查看私聊消息的接口和测试
This commit is contained in:
@@ -35,23 +35,27 @@ export default class ChatInfo extends BaseModel {
|
||||
public static async createInfo(data: ChatInfoParam) {
|
||||
const roleId = data.roleId!;
|
||||
const docData = new ChatInfoModel();
|
||||
const result = await ChatInfoModel.findOneAndUpdate({ roleId }, { ...docData.toJSON(), ...data }, { upsert: true, new: true }).select('-_id').lean();
|
||||
const result: ChatInfoType = await ChatInfoModel.findOneAndUpdate({ roleId }, { ...docData.toJSON(), ...data }, { upsert: true, new: true }).select('-_id').lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async findInfo(roleId: string) {
|
||||
let result = await ChatInfoModel.findOne({ roleId }).select('-_id').lean();
|
||||
let result: ChatInfoType = await ChatInfoModel.findOne({ roleId }).select('-_id').lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async updateInfo(data: ChatInfoParam) {
|
||||
const roleId = data.roleId!;
|
||||
const result = await ChatInfoModel.findOneAndUpdate({ roleId }, { $set: { ...data } }, { new: true }).select('-_id').lean();
|
||||
const result: ChatInfoType = await ChatInfoModel.findOneAndUpdate({ roleId }, { $set: { ...data } }, { new: true }).select('-_id').lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async updateReadTime(roleId: string, targetRoleId: string, time: Date) {
|
||||
const result: ChatInfoType = await ChatInfoModel.findOneAndUpdate({ roleId, 'recentPrivateChats.targetRoleId': targetRoleId }, { 'recentPrivateChats.$.lastReadTime': time }, { new: true }).select('-_id').lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const ChatInfoModel = getModelForClass(ChatInfo);
|
||||
|
||||
export interface ChatInfoType extends Pick<DocumentType<ChatInfo>, keyof ChatInfo> {};
|
||||
|
||||
Reference in New Issue
Block a user