mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-27 09:23:09 +02:00
Refactoring
This commit is contained in:
parent
28f8933c3c
commit
79354f4faf
5 changed files with 32 additions and 25 deletions
|
@ -2,7 +2,6 @@ import { getRepository, getCustomRepository } from 'typeorm';
|
||||||
import { Announcement } from './entities/announcement';
|
import { Announcement } from './entities/announcement';
|
||||||
import { AnnouncementRead } from './entities/announcement-read';
|
import { AnnouncementRead } from './entities/announcement-read';
|
||||||
import { Instance } from './entities/instance';
|
import { Instance } from './entities/instance';
|
||||||
import { Emoji } from './entities/emoji';
|
|
||||||
import { Poll } from './entities/poll';
|
import { Poll } from './entities/poll';
|
||||||
import { PollVote } from './entities/poll-vote';
|
import { PollVote } from './entities/poll-vote';
|
||||||
import { Meta } from './entities/meta';
|
import { Meta } from './entities/meta';
|
||||||
|
@ -52,6 +51,7 @@ import { AntennaRepository } from './repositories/antenna';
|
||||||
import { AntennaNote } from './entities/antenna-note';
|
import { AntennaNote } from './entities/antenna-note';
|
||||||
import { PromoNote } from './entities/promo-note';
|
import { PromoNote } from './entities/promo-note';
|
||||||
import { PromoRead } from './entities/promo-read';
|
import { PromoRead } from './entities/promo-read';
|
||||||
|
import { EmojiRepository } from './repositories/emoji';
|
||||||
|
|
||||||
export const Announcements = getRepository(Announcement);
|
export const Announcements = getRepository(Announcement);
|
||||||
export const AnnouncementReads = getRepository(AnnouncementRead);
|
export const AnnouncementReads = getRepository(AnnouncementRead);
|
||||||
|
@ -79,7 +79,7 @@ export const UsedUsernames = getRepository(UsedUsername);
|
||||||
export const Followings = getCustomRepository(FollowingRepository);
|
export const Followings = getCustomRepository(FollowingRepository);
|
||||||
export const FollowRequests = getCustomRepository(FollowRequestRepository);
|
export const FollowRequests = getCustomRepository(FollowRequestRepository);
|
||||||
export const Instances = getRepository(Instance);
|
export const Instances = getRepository(Instance);
|
||||||
export const Emojis = getRepository(Emoji);
|
export const Emojis = getCustomRepository(EmojiRepository);
|
||||||
export const DriveFiles = getCustomRepository(DriveFileRepository);
|
export const DriveFiles = getCustomRepository(DriveFileRepository);
|
||||||
export const DriveFolders = getCustomRepository(DriveFolderRepository);
|
export const DriveFolders = getCustomRepository(DriveFolderRepository);
|
||||||
export const Notifications = getCustomRepository(NotificationRepository);
|
export const Notifications = getCustomRepository(NotificationRepository);
|
||||||
|
|
27
src/models/repositories/emoji.ts
Normal file
27
src/models/repositories/emoji.ts
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
|
import { Emoji } from '../entities/emoji';
|
||||||
|
import { ensure } from '../../prelude/ensure';
|
||||||
|
|
||||||
|
@EntityRepository(Emoji)
|
||||||
|
export class EmojiRepository extends Repository<Emoji> {
|
||||||
|
public async pack(
|
||||||
|
src: Emoji['id'] | Emoji,
|
||||||
|
) {
|
||||||
|
const emoji = typeof src === 'object' ? src : await this.findOne(src).then(ensure);
|
||||||
|
|
||||||
|
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)));
|
||||||
|
}
|
||||||
|
}
|
|
@ -51,12 +51,5 @@ export default define(meta, async (ps) => {
|
||||||
.take(ps.limit!)
|
.take(ps.limit!)
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
return emojis.map(e => ({
|
return Emojis.packMany(emojis);
|
||||||
id: e.id,
|
|
||||||
name: e.name,
|
|
||||||
category: e.category,
|
|
||||||
aliases: e.aliases,
|
|
||||||
host: e.host,
|
|
||||||
url: e.url
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -36,12 +36,5 @@ export default define(meta, async (ps) => {
|
||||||
.take(ps.limit!)
|
.take(ps.limit!)
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
return emojis.map(e => ({
|
return Emojis.packMany(emojis);
|
||||||
id: e.id,
|
|
||||||
name: e.name,
|
|
||||||
category: e.category,
|
|
||||||
aliases: e.aliases,
|
|
||||||
host: e.host,
|
|
||||||
url: e.url
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -130,13 +130,7 @@ export default define(meta, async (ps, me) => {
|
||||||
errorImageUrl: instance.errorImageUrl,
|
errorImageUrl: instance.errorImageUrl,
|
||||||
iconUrl: instance.iconUrl,
|
iconUrl: instance.iconUrl,
|
||||||
maxNoteTextLength: Math.min(instance.maxNoteTextLength, DB_MAX_NOTE_TEXT_LENGTH),
|
maxNoteTextLength: Math.min(instance.maxNoteTextLength, DB_MAX_NOTE_TEXT_LENGTH),
|
||||||
emojis: emojis.map(e => ({
|
emojis: await Emojis.packMany(emojis),
|
||||||
id: e.id,
|
|
||||||
aliases: e.aliases,
|
|
||||||
name: e.name,
|
|
||||||
category: e.category,
|
|
||||||
url: e.url,
|
|
||||||
})),
|
|
||||||
requireSetup: (await Users.count({
|
requireSetup: (await Users.count({
|
||||||
host: null,
|
host: null,
|
||||||
})) === 0,
|
})) === 0,
|
||||||
|
|
Loading…
Reference in a new issue