Sharkey/packages/backend/src/models/repositories/emoji.ts

28 lines
639 B
TypeScript
Raw Normal View History

2020-03-31 03:15:04 +03:00
import { EntityRepository, Repository } from 'typeorm';
import { Emoji } from '@/models/entities/emoji';
import { Packed } from '@/misc/schema';
2020-03-31 03:15:04 +03:00
@EntityRepository(Emoji)
export class EmojiRepository extends Repository<Emoji> {
public async pack(
src: Emoji['id'] | Emoji,
): Promise<Packed<'Emoji'>> {
2021-02-13 08:33:38 +02:00
const emoji = typeof src === 'object' ? src : await this.findOneOrFail(src);
2020-03-31 03:15:04 +03:00
return {
id: emoji.id,
aliases: emoji.aliases,
name: emoji.name,
category: emoji.category,
host: emoji.host,
url: emoji.url,
};
}
public packMany(
emojis: any[],
) {
return Promise.all(emojis.map(x => this.pack(x)));
}
}