2019-04-07 21:50:36 +09:00
|
|
|
import { EntityRepository, Repository } from 'typeorm';
|
2021-08-19 22:04:15 +09:00
|
|
|
import { NoteReaction } from '@/models/entities/note-reaction';
|
2021-10-17 01:33:15 +09:00
|
|
|
import { Notes, Users } from '../index';
|
2021-09-22 22:35:55 +09:00
|
|
|
import { Packed } from '@/misc/schema';
|
2021-08-19 21:55:45 +09:00
|
|
|
import { convertLegacyReaction } from '@/misc/reaction-lib';
|
2021-08-19 22:04:15 +09:00
|
|
|
import { User } from '@/models/entities/user';
|
2019-04-23 22:35:26 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
@EntityRepository(NoteReaction)
|
|
|
|
export class NoteReactionRepository extends Repository<NoteReaction> {
|
|
|
|
public async pack(
|
|
|
|
src: NoteReaction['id'] | NoteReaction,
|
2021-10-17 01:33:15 +09:00
|
|
|
me?: { id: User['id'] } | null | undefined,
|
|
|
|
options?: {
|
|
|
|
withNote: boolean;
|
|
|
|
},
|
2021-09-22 22:35:55 +09:00
|
|
|
): Promise<Packed<'NoteReaction'>> {
|
2021-10-17 01:33:15 +09:00
|
|
|
const opts = Object.assign({
|
|
|
|
withNote: false,
|
|
|
|
}, options);
|
|
|
|
|
2021-02-13 15:33:38 +09:00
|
|
|
const reaction = typeof src === 'object' ? src : await this.findOneOrFail(src);
|
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),
|
2020-01-30 04:37:25 +09:00
|
|
|
type: convertLegacyReaction(reaction.reaction),
|
2021-10-17 01:33:15 +09:00
|
|
|
...(opts.withNote ? {
|
|
|
|
note: await Notes.pack(reaction.noteId, me),
|
|
|
|
} : {})
|
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',
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
user: {
|
2019-06-27 18:04:09 +09:00
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
2021-09-12 01:12:23 +09:00
|
|
|
ref: 'User' as const,
|
2019-04-23 22:35:26 +09:00
|
|
|
},
|
|
|
|
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
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|