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