Add event to repositories (getters)

This commit is contained in:
ssmucny 2023-04-16 17:27:34 -04:00
parent 453d25ff37
commit 44d05d58c4
4 changed files with 29 additions and 2 deletions

View File

@ -9,7 +9,7 @@ import { awaitAll } from '@/misc/prelude/await-all.js';
import type { User } from '@/models/entities/User.js'; import type { User } from '@/models/entities/User.js';
import type { Note } from '@/models/entities/Note.js'; import type { Note } from '@/models/entities/Note.js';
import type { NoteReaction } from '@/models/entities/NoteReaction.js'; import type { NoteReaction } from '@/models/entities/NoteReaction.js';
import type { UsersRepository, NotesRepository, FollowingsRepository, PollsRepository, PollVotesRepository, NoteReactionsRepository, ChannelsRepository, DriveFilesRepository } from '@/models/index.js'; import type { UsersRepository, NotesRepository, FollowingsRepository, PollsRepository, PollVotesRepository, NoteReactionsRepository, ChannelsRepository, DriveFilesRepository, EventsRepository } from '@/models/index.js';
import { bindThis } from '@/decorators.js'; import { bindThis } from '@/decorators.js';
import { isNotNull } from '@/misc/is-not-null.js'; import { isNotNull } from '@/misc/is-not-null.js';
import type { OnModuleInit } from '@nestjs/common'; import type { OnModuleInit } from '@nestjs/common';
@ -43,6 +43,9 @@ export class NoteEntityService implements OnModuleInit {
@Inject(DI.pollsRepository) @Inject(DI.pollsRepository)
private pollsRepository: PollsRepository, private pollsRepository: PollsRepository,
@Inject(DI.eventsRepository)
private eventsRepository: EventsRepository,
@Inject(DI.pollVotesRepository) @Inject(DI.pollVotesRepository)
private pollVotesRepository: PollVotesRepository, private pollVotesRepository: PollVotesRepository,
@ -169,6 +172,17 @@ export class NoteEntityService implements OnModuleInit {
}; };
} }
@bindThis
private async populateEvent(note: Note) {
const event = await this.eventsRepository.findOneByOrFail({ noteId: note.id });
return {
title: event.title,
start: event.start,
end: event.end,
metadata: event.metadata,
};
}
@bindThis @bindThis
private async populateMyReaction(note: Note, meId: User['id'], _hint_?: { private async populateMyReaction(note: Note, meId: User['id'], _hint_?: {
myReactions: Map<Note['id'], NoteReaction | null>; myReactions: Map<Note['id'], NoteReaction | null>;
@ -352,6 +366,7 @@ export class NoteEntityService implements OnModuleInit {
}) : undefined, }) : undefined,
poll: note.hasPoll ? this.populatePoll(note, meId) : undefined, poll: note.hasPoll ? this.populatePoll(note, meId) : undefined,
event: note.hasEvent ? this.populateEvent(note) : undefined,
...(meId ? { ...(meId ? {
myReaction: this.populateMyReaction(note, meId, options?._hint_), myReaction: this.populateMyReaction(note, meId, options?._hint_),

View File

@ -32,6 +32,7 @@ export const DI = {
followRequestsRepository: Symbol('followRequestsRepository'), followRequestsRepository: Symbol('followRequestsRepository'),
instancesRepository: Symbol('instancesRepository'), instancesRepository: Symbol('instancesRepository'),
emojisRepository: Symbol('emojisRepository'), emojisRepository: Symbol('emojisRepository'),
eventsRepository: Symbol('eventsRepository'),
driveFilesRepository: Symbol('driveFilesRepository'), driveFilesRepository: Symbol('driveFilesRepository'),
driveFoldersRepository: Symbol('driveFoldersRepository'), driveFoldersRepository: Symbol('driveFoldersRepository'),
metasRepository: Symbol('metasRepository'), metasRepository: Symbol('metasRepository'),

View File

@ -1,6 +1,6 @@
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import { User, Note, Announcement, AnnouncementRead, App, NoteFavorite, NoteThreadMuting, NoteReaction, NoteUnread, Poll, PollVote, UserProfile, UserKeypair, UserPending, AttestationChallenge, UserSecurityKey, UserPublickey, UserList, UserListJoining, UserNotePining, UserIp, UsedUsername, Following, FollowRequest, Instance, Emoji, DriveFile, DriveFolder, Meta, Muting, RenoteMuting, Blocking, SwSubscription, Hashtag, AbuseUserReport, RegistrationTicket, AuthSession, AccessToken, Signin, Page, PageLike, GalleryPost, GalleryLike, ModerationLog, Clip, ClipNote, Antenna, PromoNote, PromoRead, Relay, MutedNote, Channel, ChannelFollowing, ChannelFavorite, RegistryItem, Webhook, Ad, PasswordResetRequest, RetentionAggregation, FlashLike, Flash, Role, RoleAssignment, ClipFavorite } from './index.js'; import { User, Note, Announcement, AnnouncementRead, App, NoteFavorite, NoteThreadMuting, NoteReaction, NoteUnread, Poll, PollVote, UserProfile, UserKeypair, UserPending, AttestationChallenge, UserSecurityKey, UserPublickey, UserList, UserListJoining, UserNotePining, UserIp, UsedUsername, Following, FollowRequest, Instance, Emoji, Event, DriveFile, DriveFolder, Meta, Muting, RenoteMuting, Blocking, SwSubscription, Hashtag, AbuseUserReport, RegistrationTicket, AuthSession, AccessToken, Signin, Page, PageLike, GalleryPost, GalleryLike, ModerationLog, Clip, ClipNote, Antenna, PromoNote, PromoRead, Relay, MutedNote, Channel, ChannelFollowing, ChannelFavorite, RegistryItem, Webhook, Ad, PasswordResetRequest, RetentionAggregation, FlashLike, Flash, Role, RoleAssignment, ClipFavorite } from './index.js';
import type { DataSource } from 'typeorm'; import type { DataSource } from 'typeorm';
import type { Provider } from '@nestjs/common'; import type { Provider } from '@nestjs/common';
@ -160,6 +160,12 @@ const $emojisRepository: Provider = {
inject: [DI.db], inject: [DI.db],
}; };
const $eventsRepository: Provider = {
provide: DI.eventsRepository,
useFactory: (db: DataSource) => db.getRepository(Event),
inject: [DI.db],
};
const $driveFilesRepository: Provider = { const $driveFilesRepository: Provider = {
provide: DI.driveFilesRepository, provide: DI.driveFilesRepository,
useFactory: (db: DataSource) => db.getRepository(DriveFile), useFactory: (db: DataSource) => db.getRepository(DriveFile),
@ -418,6 +424,7 @@ const $roleAssignmentsRepository: Provider = {
$followRequestsRepository, $followRequestsRepository,
$instancesRepository, $instancesRepository,
$emojisRepository, $emojisRepository,
$eventsRepository,
$driveFilesRepository, $driveFilesRepository,
$driveFoldersRepository, $driveFoldersRepository,
$metasRepository, $metasRepository,
@ -484,6 +491,7 @@ const $roleAssignmentsRepository: Provider = {
$followRequestsRepository, $followRequestsRepository,
$instancesRepository, $instancesRepository,
$emojisRepository, $emojisRepository,
$eventsRepository,
$driveFilesRepository, $driveFilesRepository,
$driveFoldersRepository, $driveFoldersRepository,
$metasRepository, $metasRepository,

View File

@ -16,6 +16,7 @@ import { ClipFavorite } from '@/models/entities/ClipFavorite.js';
import { DriveFile } from '@/models/entities/DriveFile.js'; import { DriveFile } from '@/models/entities/DriveFile.js';
import { DriveFolder } from '@/models/entities/DriveFolder.js'; import { DriveFolder } from '@/models/entities/DriveFolder.js';
import { Emoji } from '@/models/entities/Emoji.js'; import { Emoji } from '@/models/entities/Emoji.js';
import { Event } from '@/models/entities/Event.js';
import { Following } from '@/models/entities/Following.js'; import { Following } from '@/models/entities/Following.js';
import { FollowRequest } from '@/models/entities/FollowRequest.js'; import { FollowRequest } from '@/models/entities/FollowRequest.js';
import { GalleryLike } from '@/models/entities/GalleryLike.js'; import { GalleryLike } from '@/models/entities/GalleryLike.js';
@ -83,6 +84,7 @@ export {
DriveFile, DriveFile,
DriveFolder, DriveFolder,
Emoji, Emoji,
Event,
Following, Following,
FollowRequest, FollowRequest,
GalleryLike, GalleryLike,
@ -149,6 +151,7 @@ export type ClipFavoritesRepository = Repository<ClipFavorite>;
export type DriveFilesRepository = Repository<DriveFile>; export type DriveFilesRepository = Repository<DriveFile>;
export type DriveFoldersRepository = Repository<DriveFolder>; export type DriveFoldersRepository = Repository<DriveFolder>;
export type EmojisRepository = Repository<Emoji>; export type EmojisRepository = Repository<Emoji>;
export type EventsRepository = Repository<Event>;
export type FollowingsRepository = Repository<Following>; export type FollowingsRepository = Repository<Following>;
export type FollowRequestsRepository = Repository<FollowRequest>; export type FollowRequestsRepository = Repository<FollowRequest>;
export type GalleryLikesRepository = Repository<GalleryLike>; export type GalleryLikesRepository = Repository<GalleryLike>;