510de87607
* wip * wip * Update abuse-user-reports.ts * Update files.ts * Update list-remote.ts * Update list.ts * Update show-users.ts * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update update.ts * Update search.ts * Update reactions.ts * Update search.ts * wip * wip * wip * wip * Update update.ts * Update relation.ts * Update available.ts * wip * wip * wip * Update packages/backend/src/server/api/define.ts Co-authored-by: Johann150 <johann.galle@protonmail.com> * Update define.ts * Update define.ts * typo * wip * wip * wip * wip * wip * wip * wip * wip * Update update.ts * wip * Update signup.ts * Update call.ts * minimum for limit * type * remove needless annotation * wip * Update signup.ts * wip * wip * fix * Update create.ts Co-authored-by: Johann150 <johann.galle@protonmail.com>
140 lines
4.0 KiB
TypeScript
140 lines
4.0 KiB
TypeScript
import define from '../../define';
|
|
import { ApiError } from '../../error';
|
|
import { DriveFiles, Followings, NoteFavorites, NoteReactions, Notes, PageLikes, PollVotes, Users } from '@/models/index';
|
|
|
|
export const meta = {
|
|
tags: ['users'],
|
|
|
|
requireCredential: false,
|
|
|
|
errors: {
|
|
noSuchUser: {
|
|
message: 'No such user.',
|
|
code: 'NO_SUCH_USER',
|
|
id: '9e638e45-3b25-4ef7-8f95-07e8498f1819',
|
|
},
|
|
},
|
|
} as const;
|
|
|
|
const paramDef = {
|
|
type: 'object',
|
|
properties: {
|
|
userId: { type: 'string', format: 'misskey:id' },
|
|
},
|
|
required: ['userId'],
|
|
} as const;
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
export default define(meta, paramDef, async (ps, me) => {
|
|
const user = await Users.findOne(ps.userId);
|
|
if (user == null) {
|
|
throw new ApiError(meta.errors.noSuchUser);
|
|
}
|
|
|
|
const [
|
|
notesCount,
|
|
repliesCount,
|
|
renotesCount,
|
|
repliedCount,
|
|
renotedCount,
|
|
pollVotesCount,
|
|
pollVotedCount,
|
|
localFollowingCount,
|
|
remoteFollowingCount,
|
|
localFollowersCount,
|
|
remoteFollowersCount,
|
|
sentReactionsCount,
|
|
receivedReactionsCount,
|
|
noteFavoritesCount,
|
|
pageLikesCount,
|
|
pageLikedCount,
|
|
driveFilesCount,
|
|
driveUsage,
|
|
] = await Promise.all([
|
|
Notes.createQueryBuilder('note')
|
|
.where('note.userId = :userId', { userId: user.id })
|
|
.getCount(),
|
|
Notes.createQueryBuilder('note')
|
|
.where('note.userId = :userId', { userId: user.id })
|
|
.andWhere('note.replyId IS NOT NULL')
|
|
.getCount(),
|
|
Notes.createQueryBuilder('note')
|
|
.where('note.userId = :userId', { userId: user.id })
|
|
.andWhere('note.renoteId IS NOT NULL')
|
|
.getCount(),
|
|
Notes.createQueryBuilder('note')
|
|
.where('note.replyUserId = :userId', { userId: user.id })
|
|
.getCount(),
|
|
Notes.createQueryBuilder('note')
|
|
.where('note.renoteUserId = :userId', { userId: user.id })
|
|
.getCount(),
|
|
PollVotes.createQueryBuilder('vote')
|
|
.where('vote.userId = :userId', { userId: user.id })
|
|
.getCount(),
|
|
PollVotes.createQueryBuilder('vote')
|
|
.innerJoin('vote.note', 'note')
|
|
.where('note.userId = :userId', { userId: user.id })
|
|
.getCount(),
|
|
Followings.createQueryBuilder('following')
|
|
.where('following.followerId = :userId', { userId: user.id })
|
|
.andWhere('following.followeeHost IS NULL')
|
|
.getCount(),
|
|
Followings.createQueryBuilder('following')
|
|
.where('following.followerId = :userId', { userId: user.id })
|
|
.andWhere('following.followeeHost IS NOT NULL')
|
|
.getCount(),
|
|
Followings.createQueryBuilder('following')
|
|
.where('following.followeeId = :userId', { userId: user.id })
|
|
.andWhere('following.followerHost IS NULL')
|
|
.getCount(),
|
|
Followings.createQueryBuilder('following')
|
|
.where('following.followeeId = :userId', { userId: user.id })
|
|
.andWhere('following.followerHost IS NOT NULL')
|
|
.getCount(),
|
|
NoteReactions.createQueryBuilder('reaction')
|
|
.where('reaction.userId = :userId', { userId: user.id })
|
|
.getCount(),
|
|
NoteReactions.createQueryBuilder('reaction')
|
|
.innerJoin('reaction.note', 'note')
|
|
.where('note.userId = :userId', { userId: user.id })
|
|
.getCount(),
|
|
NoteFavorites.createQueryBuilder('favorite')
|
|
.where('favorite.userId = :userId', { userId: user.id })
|
|
.getCount(),
|
|
PageLikes.createQueryBuilder('like')
|
|
.where('like.userId = :userId', { userId: user.id })
|
|
.getCount(),
|
|
PageLikes.createQueryBuilder('like')
|
|
.innerJoin('like.page', 'page')
|
|
.where('page.userId = :userId', { userId: user.id })
|
|
.getCount(),
|
|
DriveFiles.createQueryBuilder('file')
|
|
.where('file.userId = :userId', { userId: user.id })
|
|
.getCount(),
|
|
DriveFiles.calcDriveUsageOf(user),
|
|
]);
|
|
|
|
return {
|
|
notesCount,
|
|
repliesCount,
|
|
renotesCount,
|
|
repliedCount,
|
|
renotedCount,
|
|
pollVotesCount,
|
|
pollVotedCount,
|
|
localFollowingCount,
|
|
remoteFollowingCount,
|
|
localFollowersCount,
|
|
remoteFollowersCount,
|
|
followingCount: localFollowingCount + remoteFollowingCount,
|
|
followersCount: localFollowersCount + remoteFollowersCount,
|
|
sentReactionsCount,
|
|
receivedReactionsCount,
|
|
noteFavoritesCount,
|
|
pageLikesCount,
|
|
pageLikedCount,
|
|
driveFilesCount,
|
|
driveUsage,
|
|
};
|
|
});
|