mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-13 15:33:09 +02:00
27 lines
621 B
TypeScript
27 lines
621 B
TypeScript
import { EntityRepository, Repository } from 'typeorm';
|
|
import { Emoji } from '../entities/emoji';
|
|
import { ensure } from '../../prelude/ensure';
|
|
|
|
@EntityRepository(Emoji)
|
|
export class EmojiRepository extends Repository<Emoji> {
|
|
public async pack(
|
|
src: Emoji['id'] | Emoji,
|
|
) {
|
|
const emoji = typeof src === 'object' ? src : await this.findOne(src).then(ensure);
|
|
|
|
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)));
|
|
}
|
|
}
|