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