Introduce followed log and following log
This commit is contained in:
11
src/models/followed-log.ts
Normal file
11
src/models/followed-log.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { ObjectID } from 'mongodb';
|
||||
import db from '../db/mongodb';
|
||||
|
||||
const FollowedLog = db.get<IFollowedLog>('followedLogs');
|
||||
export default FollowedLog;
|
||||
|
||||
export type IFollowedLog = {
|
||||
_id: ObjectID;
|
||||
userId: ObjectID;
|
||||
count: number;
|
||||
};
|
11
src/models/following-log.ts
Normal file
11
src/models/following-log.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { ObjectID } from 'mongodb';
|
||||
import db from '../db/mongodb';
|
||||
|
||||
const FollowingLog = db.get<IFollowingLog>('followingLogs');
|
||||
export default FollowingLog;
|
||||
|
||||
export type IFollowingLog = {
|
||||
_id: ObjectID;
|
||||
userId: ObjectID;
|
||||
count: number;
|
||||
};
|
@ -8,7 +8,6 @@ export default Following;
|
||||
export type IFollowing = {
|
||||
_id: mongo.ObjectID;
|
||||
createdAt: Date;
|
||||
deletedAt: Date;
|
||||
followeeId: mongo.ObjectID;
|
||||
followerId: mongo.ObjectID;
|
||||
};
|
||||
|
@ -234,8 +234,7 @@ export const pack = (
|
||||
_user.isFollowing = (async () => {
|
||||
const follow = await Following.findOne({
|
||||
followerId: meId,
|
||||
followeeId: _user.id,
|
||||
deletedAt: { $exists: false }
|
||||
followeeId: _user.id
|
||||
});
|
||||
return follow !== null;
|
||||
})();
|
||||
@ -244,8 +243,7 @@ export const pack = (
|
||||
_user.isFollowed = (async () => {
|
||||
const follow2 = await Following.findOne({
|
||||
followerId: _user.id,
|
||||
followeeId: meId,
|
||||
deletedAt: { $exists: false }
|
||||
followeeId: meId
|
||||
});
|
||||
return follow2 !== null;
|
||||
})();
|
||||
@ -275,15 +273,13 @@ export const pack = (
|
||||
// Get following you know count
|
||||
_user.followingYouKnowCount = Following.count({
|
||||
followeeId: { $in: myFollowingIds },
|
||||
followerId: _user.id,
|
||||
deletedAt: { $exists: false }
|
||||
followerId: _user.id
|
||||
});
|
||||
|
||||
// Get followers you know count
|
||||
_user.followersYouKnowCount = Following.count({
|
||||
followeeId: _user.id,
|
||||
followerId: { $in: myFollowingIds },
|
||||
deletedAt: { $exists: false }
|
||||
followerId: { $in: myFollowingIds }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user