mirror of
https://github.com/misskey-dev/misskey
synced 2024-06-16 07:30:41 +02:00
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import { DI } from '@/di-symbols.js';
|
|
import type { NoteFavoritesRepository } from '@/models/index.js';
|
|
import { awaitAll } from '@/misc/prelude/await-all.js';
|
|
import type { Packed } from '@/misc/schema.js';
|
|
import type { } from '@/models/entities/Blocking.js';
|
|
import type { User } from '@/models/entities/User.js';
|
|
import type { NoteFavorite } from '@/models/entities/NoteFavorite.js';
|
|
import { UserEntityService } from './UserEntityService.js';
|
|
import { NoteEntityService } from './NoteEntityService.js';
|
|
import { bindThis } from '@/decorators.js';
|
|
|
|
@Injectable()
|
|
export class NoteFavoriteEntityService {
|
|
constructor(
|
|
@Inject(DI.noteFavoritesRepository)
|
|
private noteFavoritesRepository: NoteFavoritesRepository,
|
|
|
|
private noteEntityService: NoteEntityService,
|
|
) {
|
|
}
|
|
|
|
@bindThis
|
|
public async pack(
|
|
src: NoteFavorite['id'] | NoteFavorite,
|
|
me?: { id: User['id'] } | null | undefined,
|
|
) {
|
|
const favorite = typeof src === 'object' ? src : await this.noteFavoritesRepository.findOneByOrFail({ id: src });
|
|
|
|
return {
|
|
id: favorite.id,
|
|
createdAt: favorite.createdAt.toISOString(),
|
|
noteId: favorite.noteId,
|
|
note: await this.noteEntityService.pack(favorite.note ?? favorite.noteId, me),
|
|
};
|
|
}
|
|
|
|
@bindThis
|
|
public packMany(
|
|
favorites: any[],
|
|
me: { id: User['id'] },
|
|
) {
|
|
return Promise.all(favorites.map(x => this.pack(x, me)));
|
|
}
|
|
}
|