2019-04-07 07:50:36 -05:00
|
|
|
import { EntityRepository, Repository } from 'typeorm';
|
|
|
|
import { NoteReaction } from '../entities/note-reaction';
|
|
|
|
import { Users } from '..';
|
2019-04-12 11:43:22 -05:00
|
|
|
import { ensure } from '../../prelude/ensure';
|
2019-04-23 08:35:26 -05:00
|
|
|
import { types, bool, SchemaType } from '../../misc/schema';
|
|
|
|
|
|
|
|
export type PackedNoteReaction = SchemaType<typeof packedNoteReactionSchema>;
|
2019-04-07 07:50:36 -05:00
|
|
|
|
|
|
|
@EntityRepository(NoteReaction)
|
|
|
|
export class NoteReactionRepository extends Repository<NoteReaction> {
|
|
|
|
public async pack(
|
|
|
|
src: NoteReaction['id'] | NoteReaction,
|
|
|
|
me?: any
|
2019-04-23 08:35:26 -05:00
|
|
|
): Promise<PackedNoteReaction> {
|
2019-04-12 11:43:22 -05:00
|
|
|
const reaction = typeof src === 'object' ? src : await this.findOne(src).then(ensure);
|
2019-04-07 07:50:36 -05:00
|
|
|
|
|
|
|
return {
|
|
|
|
id: reaction.id,
|
2019-04-23 08:35:26 -05:00
|
|
|
createdAt: reaction.createdAt.toISOString(),
|
2019-04-07 07:50:36 -05:00
|
|
|
user: await Users.pack(reaction.userId, me),
|
2019-04-23 08:35:26 -05:00
|
|
|
type: reaction.reaction,
|
2019-04-07 07:50:36 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2019-04-23 08:35:26 -05:00
|
|
|
|
|
|
|
export const packedNoteReactionSchema = {
|
|
|
|
type: types.object,
|
|
|
|
optional: bool.false, nullable: bool.false,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: types.string,
|
|
|
|
optional: bool.false, nullable: bool.false,
|
|
|
|
format: 'id',
|
|
|
|
description: 'The unique identifier for this reaction.',
|
|
|
|
example: 'xxxxxxxxxx',
|
|
|
|
},
|
|
|
|
createdAt: {
|
|
|
|
type: types.string,
|
|
|
|
optional: bool.false, nullable: bool.false,
|
|
|
|
format: 'date-time',
|
|
|
|
description: 'The date that the reaction was created.'
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
type: types.object,
|
|
|
|
optional: bool.false, nullable: bool.false,
|
|
|
|
ref: 'User',
|
|
|
|
description: 'User who performed this reaction.'
|
|
|
|
},
|
|
|
|
type: {
|
|
|
|
type: types.string,
|
|
|
|
optional: bool.false, nullable: bool.false,
|
|
|
|
description: 'The reaction type.'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|