好友:拉黑

This commit is contained in:
luying
2021-02-03 11:49:46 +08:00
parent 585a741be5
commit 2d2c9907ab
7 changed files with 194 additions and 14 deletions
+24 -2
View File
@@ -41,20 +41,42 @@ export default class FriendRelation extends BaseModel {
// 获取列表
public static async findFriendByRole(roleId: string, populate = true) {
public static async findFriendByRole(roleId: string, populateType: number) {
let document = FriendRelationModel.findOne({ roleId })
.lean({ getters: true, virtuals: true });
if (populate) {
if (populateType == 1) {
document
.populate('friends.role', ROLE.SHOW_SIMPLE, 'Role')
.populate('friends.friendShip', null, 'FriendShip');
} else if (populateType == 2) {
document
.populate('blacklist.role', ROLE.SHOW_SIMPLE, 'Role')
}
let result: FriendRelationType = await document;
return result;
}
public static async moveFromFriend(roleId: string, friend: RoleType, friendShip: FriendShipType, toBlack: boolean ) {
let update = {
$pull: { friends: { roleId: friend.roleId } }
}
if(toBlack) {
update['$push'] = { blacklist: { roleId: friend.roleId, role: friend._id, friendShip: friendShip? friendShip._id: null } };
}
let result: FriendRelationType = await FriendRelationModel.findOneAndUpdate({ roleId }, update, { new: true });
return result
}
public static async removeFromBlack(roleId: string, frdRoleId: string ) {
let result: FriendRelationType = await FriendRelationModel.findOneAndUpdate({ roleId }, {
$pull: { blacklist: { roleId: frdRoleId } }
}, { new: true });
return result
}
public static async deleteAccount(roleId: string) {
let result = await FriendRelationModel.deleteMany({ roleId });
await FriendRelationModel.updateMany({}, { $pull: { friends: { roleId }, blacklist: { roleId } }});