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

66 lines
1.5 KiB
TypeScript
Raw Normal View History

2020-03-30 19:15:04 -05:00
import { EntityRepository, Repository } from 'typeorm';
import { Emoji } from '@/models/entities/emoji';
import { Packed } from '@/misc/schema';
2020-03-30 19:15:04 -05:00
@EntityRepository(Emoji)
export class EmojiRepository extends Repository<Emoji> {
public async pack(
src: Emoji['id'] | Emoji,
): Promise<Packed<'Emoji'>> {
2021-02-13 00:33:38 -06:00
const emoji = typeof src === 'object' ? src : await this.findOneOrFail(src);
2020-03-30 19:15:04 -05: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)));
}
}
export const packedEmojiSchema = {
type: 'object' as const,
optional: false as const, nullable: false as const,
properties: {
id: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'id',
example: 'xxxxxxxxxx',
},
aliases: {
type: 'array' as const,
optional: false as const, nullable: false as const,
items: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'id',
},
},
name: {
type: 'string' as const,
optional: false as const, nullable: false as const,
},
category: {
type: 'string' as const,
optional: false as const, nullable: true as const,
},
host: {
type: 'string' as const,
optional: false as const, nullable: true as const,
},
url: {
type: 'string' as const,
optional: false as const, nullable: false as const,
},
2021-12-09 08:58:30 -06:00
},
};