2019-04-07 12:50:36 +00:00
|
|
|
import { EntityRepository, Repository } from 'typeorm';
|
2021-08-19 09:33:41 +00:00
|
|
|
import { NoteReaction } from '../entities/note-reaction.js';
|
|
|
|
import { Users } from '../index.js';
|
|
|
|
import { SchemaType } from '@/misc/schema.js';
|
|
|
|
import { convertLegacyReaction } from '@/misc/reaction-lib.js';
|
|
|
|
import { User } from '../entities/user.js';
|
2019-04-23 13:35:26 +00:00
|
|
|
|
|
|
|
export type PackedNoteReaction = SchemaType<typeof packedNoteReactionSchema>;
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
@EntityRepository(NoteReaction)
|
|
|
|
export class NoteReactionRepository extends Repository<NoteReaction> {
|
|
|
|
public async pack(
|
|
|
|
src: NoteReaction['id'] | NoteReaction,
|
2021-03-24 02:05:37 +00:00
|
|
|
me?: { id: User['id'] } | null | undefined
|
2019-04-23 13:35:26 +00:00
|
|
|
): Promise<PackedNoteReaction> {
|
2021-02-13 06:33:38 +00:00
|
|
|
const reaction = typeof src === 'object' ? src : await this.findOneOrFail(src);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
id: reaction.id,
|
2019-04-23 13:35:26 +00:00
|
|
|
createdAt: reaction.createdAt.toISOString(),
|
2019-04-07 12:50:36 +00:00
|
|
|
user: await Users.pack(reaction.userId, me),
|
2020-01-29 19:37:25 +00:00
|
|
|
type: convertLegacyReaction(reaction.reaction),
|
2019-04-07 12:50:36 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2019-04-23 13:35:26 +00:00
|
|
|
|
|
|
|
export const packedNoteReactionSchema = {
|
2019-06-27 09:04:09 +00:00
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
2019-04-23 13:35:26 +00:00
|
|
|
properties: {
|
|
|
|
id: {
|
2019-06-27 09:04:09 +00:00
|
|
|
type: 'string' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
2019-04-23 13:35:26 +00:00
|
|
|
format: 'id',
|
|
|
|
example: 'xxxxxxxxxx',
|
|
|
|
},
|
|
|
|
createdAt: {
|
2019-06-27 09:04:09 +00:00
|
|
|
type: 'string' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
2019-04-23 13:35:26 +00:00
|
|
|
format: 'date-time',
|
|
|
|
},
|
|
|
|
user: {
|
2019-06-27 09:04:09 +00:00
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
2019-04-23 13:35:26 +00:00
|
|
|
ref: 'User',
|
|
|
|
},
|
|
|
|
type: {
|
2019-06-27 09:04:09 +00:00
|
|
|
type: 'string' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
2019-04-23 13:35:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|