mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-11 15:13:08 +02:00
d071d18dd7
* wip * wip * fix * clean up * Update tsconfig.json * Update activitypub.ts * wip
31 lines
819 B
TypeScript
31 lines
819 B
TypeScript
import { EntityRepository, Repository } from 'typeorm';
|
|
import { Clip } from '@/models/entities/clip.js';
|
|
import { Packed } from '@/misc/schema.js';
|
|
import { Users } from '../index.js';
|
|
import { awaitAll } from '@/prelude/await-all.js';
|
|
|
|
@EntityRepository(Clip)
|
|
export class ClipRepository extends Repository<Clip> {
|
|
public async pack(
|
|
src: Clip['id'] | Clip,
|
|
): Promise<Packed<'Clip'>> {
|
|
const clip = typeof src === 'object' ? src : await this.findOneOrFail(src);
|
|
|
|
return await awaitAll({
|
|
id: clip.id,
|
|
createdAt: clip.createdAt.toISOString(),
|
|
userId: clip.userId,
|
|
user: Users.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)));
|
|
}
|
|
}
|
|
|