2022-09-17 18:27:08 +00:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-09-20 20:33:11 +00:00
|
|
|
import type { ClipsRepository } from '@/models/index.js';
|
2022-09-17 18:27:08 +00:00
|
|
|
import { awaitAll } from '@/misc/prelude/await-all.js';
|
2023-03-10 05:22:37 +00:00
|
|
|
import type { Packed } from '@/misc/json-schema.js';
|
2022-09-17 18:27:08 +00:00
|
|
|
import type { } from '@/models/entities/Blocking.js';
|
|
|
|
import type { Clip } from '@/models/entities/Clip.js';
|
2022-12-04 06:03:09 +00:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2023-03-10 05:22:37 +00:00
|
|
|
import { UserEntityService } from './UserEntityService.js';
|
2022-09-17 18:27:08 +00:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ClipEntityService {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.clipsRepository)
|
|
|
|
private clipsRepository: ClipsRepository,
|
|
|
|
|
|
|
|
private userEntityService: UserEntityService,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2022-12-04 06:03:09 +00:00
|
|
|
@bindThis
|
2022-09-17 18:27:08 +00:00
|
|
|
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,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-04 06:03:09 +00:00
|
|
|
@bindThis
|
2022-09-17 18:27:08 +00:00
|
|
|
public packMany(
|
|
|
|
clips: Clip[],
|
|
|
|
) {
|
|
|
|
return Promise.all(clips.map(x => this.pack(x)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|