EntityService 整理

This commit is contained in:
まっちゃとーにゅ 2023-10-11 11:28:48 +09:00
parent 487ba201bf
commit 511ff69900
No known key found for this signature in database
GPG key ID: 143DE582A97FE052
26 changed files with 60 additions and 38 deletions

View file

@ -32,11 +32,11 @@ export class AppEntityService {
includeProfileImageIds?: boolean
},
): Promise<Packed<'App'>> {
const opts = Object.assign({
const opts = {
detail: false,
includeSecret: false,
includeProfileImageIds: false,
}, options);
includeProfileImageIds: false, ...options
};
const app = typeof src === 'object' ? src : await this.appsRepository.findOneByOrFail({ id: src });

View file

@ -43,7 +43,7 @@ export class BlockingEntityService {
@bindThis
public async packMany(
blockings: (MiBlocking['id'] | MiBlocking)[],
me: { id: MiUser['id'] },
me: { id: MiUser['id'] } | null | undefined,
) : Promise<Packed<'Blocking'>[]> {
return (await Promise.allSettled(blockings.map(x => this.pack(x, me))))
.filter(result => result.status === 'fulfilled')

View file

@ -8,7 +8,6 @@ import { In } from 'typeorm';
import { DI } from '@/di-symbols.js';
import type { ChannelFavoritesRepository, ChannelFollowingsRepository, ChannelsRepository, DriveFilesRepository, NoteUnreadsRepository, NotesRepository } from '@/models/_.js';
import type { Packed } from '@/misc/json-schema.js';
import type { } from '@/models/Blocking.js';
import type { MiUser } from '@/models/User.js';
import type { MiChannel } from '@/models/Channel.js';
import { bindThis } from '@/decorators.js';

View file

@ -8,7 +8,6 @@ import { DI } from '@/di-symbols.js';
import type { ClipFavoritesRepository, ClipsRepository, MiUser } from '@/models/_.js';
import { awaitAll } from '@/misc/prelude/await-all.js';
import type { Packed } from '@/misc/json-schema.js';
import type { } from '@/models/Blocking.js';
import type { MiClip } from '@/models/Clip.js';
import { bindThis } from '@/decorators.js';
import { UserEntityService } from './UserEntityService.js';

View file

@ -8,7 +8,6 @@ import { DI } from '@/di-symbols.js';
import type { DriveFilesRepository, DriveFoldersRepository } from '@/models/_.js';
import { awaitAll } from '@/misc/prelude/await-all.js';
import type { Packed } from '@/misc/json-schema.js';
import type { } from '@/models/Blocking.js';
import type { MiDriveFolder } from '@/models/DriveFolder.js';
import { bindThis } from '@/decorators.js';

View file

@ -7,7 +7,6 @@ import { Inject, Injectable } from '@nestjs/common';
import { DI } from '@/di-symbols.js';
import type { EmojisRepository } from '@/models/_.js';
import type { Packed } from '@/misc/json-schema.js';
import type { } from '@/models/Blocking.js';
import type { MiEmoji } from '@/models/Emoji.js';
import { bindThis } from '@/decorators.js';

View file

@ -8,7 +8,6 @@ import { DI } from '@/di-symbols.js';
import type { FlashsRepository, FlashLikesRepository } from '@/models/_.js';
import { awaitAll } from '@/misc/prelude/await-all.js';
import type { Packed } from '@/misc/json-schema.js';
import type { } from '@/models/Blocking.js';
import type { MiUser } from '@/models/User.js';
import type { MiFlash } from '@/models/Flash.js';
import { bindThis } from '@/decorators.js';

View file

@ -6,7 +6,6 @@
import { Inject, Injectable } from '@nestjs/common';
import { DI } from '@/di-symbols.js';
import type { FlashLikesRepository } from '@/models/_.js';
import type { } from '@/models/Blocking.js';
import type { MiUser } from '@/models/User.js';
import type { MiFlashLike } from '@/models/FlashLike.js';
import { bindThis } from '@/decorators.js';

View file

@ -6,7 +6,6 @@
import { Inject, Injectable } from '@nestjs/common';
import { DI } from '@/di-symbols.js';
import type { FollowRequestsRepository } from '@/models/_.js';
import type { } from '@/models/Blocking.js';
import type { MiUser } from '@/models/User.js';
import type { MiFollowRequest } from '@/models/FollowRequest.js';
import { bindThis } from '@/decorators.js';

View file

@ -8,7 +8,6 @@ import { DI } from '@/di-symbols.js';
import type { FollowingsRepository } from '@/models/_.js';
import { awaitAll } from '@/misc/prelude/await-all.js';
import type { Packed } from '@/misc/json-schema.js';
import type { } from '@/models/Blocking.js';
import type { MiUser } from '@/models/User.js';
import type { MiFollowing } from '@/models/Following.js';
import { bindThis } from '@/decorators.js';

View file

@ -6,7 +6,6 @@
import { Inject, Injectable } from '@nestjs/common';
import { DI } from '@/di-symbols.js';
import type { GalleryLikesRepository } from '@/models/_.js';
import type { } from '@/models/Blocking.js';
import type { MiGalleryLike } from '@/models/GalleryLike.js';
import { bindThis } from '@/decorators.js';
import { Packed } from '@/misc/json-schema.js';

View file

@ -8,7 +8,6 @@ import { DI } from '@/di-symbols.js';
import type { GalleryLikesRepository, GalleryPostsRepository } from '@/models/_.js';
import { awaitAll } from '@/misc/prelude/await-all.js';
import type { Packed } from '@/misc/json-schema.js';
import type { } from '@/models/Blocking.js';
import type { MiUser } from '@/models/User.js';
import type { MiGalleryPost } from '@/models/GalleryPost.js';
import { bindThis } from '@/decorators.js';

View file

@ -5,7 +5,6 @@
import { Injectable } from '@nestjs/common';
import type { Packed } from '@/misc/json-schema.js';
import type { } from '@/models/Blocking.js';
import type { MiHashtag } from '@/models/Hashtag.js';
import { bindThis } from '@/decorators.js';

View file

@ -5,7 +5,6 @@
import { Injectable } from '@nestjs/common';
import type { Packed } from '@/misc/json-schema.js';
import type { } from '@/models/Blocking.js';
import type { MiInstance } from '@/models/Instance.js';
import { MetaService } from '@/core/MetaService.js';
import { bindThis } from '@/decorators.js';

View file

@ -7,7 +7,6 @@ import { Inject, Injectable } from '@nestjs/common';
import { DI } from '@/di-symbols.js';
import type { ModerationLogsRepository } from '@/models/_.js';
import { awaitAll } from '@/misc/prelude/await-all.js';
import type { } from '@/models/Blocking.js';
import type { MiUser } from '@/models/User.js';
import type { MiModerationLog } from '@/models/ModerationLog.js';
import { bindThis } from '@/decorators.js';

View file

@ -8,7 +8,6 @@ import { DI } from '@/di-symbols.js';
import type { MutingsRepository } from '@/models/_.js';
import { awaitAll } from '@/misc/prelude/await-all.js';
import type { Packed } from '@/misc/json-schema.js';
import type { } from '@/models/Blocking.js';
import type { MiUser } from '@/models/User.js';
import type { MiMuting } from '@/models/Muting.js';
import { bindThis } from '@/decorators.js';

View file

@ -6,7 +6,6 @@
import { Inject, Injectable } from '@nestjs/common';
import { DI } from '@/di-symbols.js';
import type { NoteFavoritesRepository } from '@/models/_.js';
import type { } from '@/models/Blocking.js';
import type { MiUser } from '@/models/User.js';
import type { MiNoteFavorite } from '@/models/NoteFavorite.js';
import { bindThis } from '@/decorators.js';

View file

@ -10,7 +10,6 @@ import type { NoteReactionsRepository } from '@/models/_.js';
import type { Packed } from '@/misc/json-schema.js';
import { bindThis } from '@/decorators.js';
import type { OnModuleInit } from '@nestjs/common';
import type { } from '@/models/Blocking.js';
import type { MiUser } from '@/models/User.js';
import type { MiNoteReaction } from '@/models/NoteReaction.js';
import type { ReactionService } from '../ReactionService.js';

View file

@ -8,7 +8,6 @@ import { DI } from '@/di-symbols.js';
import type { DriveFilesRepository, PagesRepository, PageLikesRepository } from '@/models/_.js';
import { awaitAll } from '@/misc/prelude/await-all.js';
import type { Packed } from '@/misc/json-schema.js';
import type { } from '@/models/Blocking.js';
import type { MiUser } from '@/models/User.js';
import type { MiPage } from '@/models/Page.js';
import type { MiDriveFile } from '@/models/DriveFile.js';

View file

@ -6,7 +6,6 @@
import { Inject, Injectable } from '@nestjs/common';
import { DI } from '@/di-symbols.js';
import type { PageLikesRepository } from '@/models/_.js';
import type { } from '@/models/Blocking.js';
import type { MiUser } from '@/models/User.js';
import type { MiPageLike } from '@/models/PageLike.js';
import { bindThis } from '@/decorators.js';

View file

@ -8,7 +8,6 @@ import { DI } from '@/di-symbols.js';
import type { RenoteMutingsRepository } from '@/models/_.js';
import { awaitAll } from '@/misc/prelude/await-all.js';
import type { Packed } from '@/misc/json-schema.js';
import type { } from '@/models/Blocking.js';
import type { MiUser } from '@/models/User.js';
import type { MiRenoteMuting } from '@/models/RenoteMuting.js';
import { bindThis } from '@/decorators.js';

View file

@ -4,7 +4,6 @@
*/
import { Injectable } from '@nestjs/common';
import type { } from '@/models/Blocking.js';
import type { MiSignin } from '@/models/Signin.js';
import { bindThis } from '@/decorators.js';

View file

@ -289,7 +289,7 @@ export class UserEntityService implements OnModuleInit {
public async pack<ExpectsMe extends boolean | null = null, D extends boolean = false>(
src: MiUser['id'] | MiUser,
me: { id: MiUser['id']; } | null | undefined,
me: { id: MiUser['id'] } | null | undefined,
options?: {
detail?: D,
includeSecrets?: boolean,

View file

@ -7,7 +7,6 @@ import { Inject, Injectable } from '@nestjs/common';
import { DI } from '@/di-symbols.js';
import type { MiUser, MiUserListMembership, UserListMembershipsRepository, UserListsRepository } from '@/models/_.js';
import type { Packed } from '@/misc/json-schema.js';
import type { } from '@/models/Blocking.js';
import type { MiUserList } from '@/models/UserList.js';
import { bindThis } from '@/decorators.js';
import { UserEntityService } from './UserEntityService.js';
@ -44,18 +43,28 @@ export class UserListEntityService {
};
}
@bindThis
public async packMemberships(
src: MiUserListMembership,
me: { id: MiUser['id'] } | null | undefined,
): Promise<Packed<'UserListMembership'>> {
return {
id: src.id,
createdAt: src.createdAt.toISOString(),
userId: src.userId,
user: await this.userEntityService.pack(src.userId, me),
withReplies: src.withReplies,
};
}
@bindThis
public async packMembershipsMany(
memberships: MiUserListMembership[],
me: { id: MiUser['id']; } | null | undefined,
) {
return Promise.all(memberships.map(async x => ({
id: x.id,
createdAt: x.createdAt.toISOString(),
userId: x.userId,
user: await this.userEntityService.pack(x.userId, me),
withReplies: x.withReplies,
})));
me: { id: MiUser['id'] } | null | undefined,
): Promise<Packed<'UserListMembership'>[]> {
return (await Promise.allSettled(memberships.map(u => this.packMemberships(u, me))))
.filter(result => result.status === 'fulfilled')
.map(result => (result as PromiseFulfilledResult<Packed<'UserListMembership'>>).value);
}
}

View file

@ -21,7 +21,7 @@ import { packedClipSchema } from '@/models/json-schema/clip.js';
import { packedDriveFileSchema } from '@/models/json-schema/drive-file.js';
import { packedDriveFolderSchema } from '@/models/json-schema/drive-folder.js';
import { packedFederationInstanceSchema } from '@/models/json-schema/federation-instance.js';
import { packedFlashLikeSchema } from '@/models/json-schema/flash.js';
import { packedFlashLikeSchema, packedFlashSchema } from '@/models/json-schema/flash.js';
import { packedFollowRequestSchema, packedFollowingSchema } from '@/models/json-schema/following.js';
import { packedGalleryLikeSchema, packedGalleryPostSchema } from '@/models/json-schema/gallery.js';
import { packedHashtagSchema } from '@/models/json-schema/hashtag.js';
@ -35,10 +35,9 @@ import { packedNotificationSchema } from '@/models/json-schema/notification.js';
import { packedPageLikeSchema, packedPageSchema } from '@/models/json-schema/page.js';
import { packedQueueCountSchema } from '@/models/json-schema/queue.js';
import { packedEmojiDetailedSchema, packedEmojiSimpleSchema } from '@/models/json-schema/emoji.js';
import { packedFlashSchema } from '@/models/json-schema/flash.js';
import { packedRenoteMutingSchema } from '@/models/json-schema/renote-muting.js';
import { packedRoleSchema } from '@/models/json-schema/role.js';
import { packedUserListSchema } from '@/models/json-schema/user-list.js';
import { packedUserListMembershipSchema, packedUserListSchema } from '@/models/json-schema/user-list.js';
import { packedAnnouncementSchema } from '@/models/json-schema/announcement.js';
export const refs = {
@ -51,6 +50,7 @@ export const refs = {
User: packedUserSchema,
UserList: packedUserListSchema,
UserListMembership: packedUserListMembershipSchema,
Announcement: packedAnnouncementSchema,
App: packedAppSchema,
Note: packedNoteSchema,

View file

@ -37,3 +37,36 @@ export const packedUserListSchema = {
},
},
} as const;
export const packedUserListMembershipSchema = {
type: 'object',
properties: {
id: {
type: 'string',
optional: false, nullable: false,
format: 'id',
example: 'xxxxxxxxxx',
},
createdAt: {
type: 'string',
optional: false, nullable: false,
format: 'date-time',
},
userId: {
type: 'string',
nullable: false, optional: false,
format: 'id',
example: 'xxxxxxxxxx',
},
user: {
type: 'object',
optional: false, nullable: false,
ref: 'UserLite',
},
withReplies: {
type: 'boolean',
nullable: false,
optional: false,
},
},
} as const;