2022-03-26 06:34:00 +00:00
|
|
|
import { db } from '@/db/postgre.js';
|
2022-02-27 02:07:39 +00:00
|
|
|
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';
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-03-26 06:34:00 +00:00
|
|
|
export const ClipRepository = db.getRepository(Clip).extend({
|
|
|
|
async pack(
|
2020-01-29 19:37:25 +00:00
|
|
|
src: Clip['id'] | Clip,
|
2021-09-22 13:35:55 +00:00
|
|
|
): Promise<Packed<'Clip'>> {
|
2022-03-26 06:34:00 +00:00
|
|
|
const clip = typeof src === 'object' ? src : await this.findOneByOrFail({ id: src });
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-11-15 03:47:54 +00:00
|
|
|
return await awaitAll({
|
2020-01-29 19:37:25 +00:00
|
|
|
id: clip.id,
|
|
|
|
createdAt: clip.createdAt.toISOString(),
|
2020-11-15 03:34:47 +00:00
|
|
|
userId: clip.userId,
|
2020-11-15 03:47:54 +00:00
|
|
|
user: Users.pack(clip.user || clip.userId),
|
2020-01-29 19:37:25 +00:00
|
|
|
name: clip.name,
|
2020-11-15 03:04:54 +00:00
|
|
|
description: clip.description,
|
2020-11-15 03:34:47 +00:00
|
|
|
isPublic: clip.isPublic,
|
2020-11-15 03:47:54 +00:00
|
|
|
});
|
2022-03-26 06:34:00 +00:00
|
|
|
},
|
2020-11-29 03:34:39 +00:00
|
|
|
|
2022-03-26 06:34:00 +00:00
|
|
|
packMany(
|
2020-11-29 03:34:39 +00:00
|
|
|
clips: Clip[],
|
|
|
|
) {
|
|
|
|
return Promise.all(clips.map(x => this.pack(x)));
|
2022-03-26 06:34:00 +00:00
|
|
|
},
|
|
|
|
});
|
2020-01-29 19:37:25 +00:00
|
|
|
|