44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import { DI } from '@/di-symbols.js';
|
|
import type { ClipsRepository } 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 { Clip } from '@/models/entities/Clip.js';
|
|
import { UserEntityService } from './UserEntityService.js';
|
|
|
|
@Injectable()
|
|
export class ClipEntityService {
|
|
constructor(
|
|
@Inject(DI.clipsRepository)
|
|
private clipsRepository: ClipsRepository,
|
|
|
|
private userEntityService: UserEntityService,
|
|
) {
|
|
}
|
|
|
|
public async pack(
|
|
src: Clip['id'] | Clip,
|
|
): Promise<Packed<'Clip'>> {
|
|
const clip = typeof src === 'object' ? src : await this.clipsRepository.findOneByOrFail({ id: src });
|
|
|
|
return await awaitAll({
|
|
id: clip.id,
|
|
createdAt: clip.createdAt.toISOString(),
|
|
userId: clip.userId,
|
|
user: this.userEntityService.pack(clip.user ?? clip.userId),
|
|
name: clip.name,
|
|
description: clip.description,
|
|
isPublic: clip.isPublic,
|
|
});
|
|
}
|
|
|
|
public packMany(
|
|
clips: Clip[],
|
|
) {
|
|
return Promise.all(clips.map(x => this.pack(x)));
|
|
}
|
|
}
|
|
|