refactor: add InstanceRepository
This commit is contained in:
parent
debef43111
commit
0d3757f2d3
4 changed files with 41 additions and 11 deletions
|
@ -61,6 +61,7 @@ import { RegistryItem } from './entities/registry-item';
|
|||
import { Ad } from './entities/ad';
|
||||
import { PasswordResetRequest } from './entities/password-reset-request';
|
||||
import { UserPending } from './entities/user-pending';
|
||||
import { InstanceRepository } from './repositories/instance';
|
||||
|
||||
export const Announcements = getRepository(Announcement);
|
||||
export const AnnouncementReads = getRepository(AnnouncementRead);
|
||||
|
@ -89,7 +90,7 @@ export const UserNotePinings = getRepository(UserNotePining);
|
|||
export const UsedUsernames = getRepository(UsedUsername);
|
||||
export const Followings = getCustomRepository(FollowingRepository);
|
||||
export const FollowRequests = getCustomRepository(FollowRequestRepository);
|
||||
export const Instances = getRepository(Instance);
|
||||
export const Instances = getCustomRepository(InstanceRepository);
|
||||
export const Emojis = getCustomRepository(EmojiRepository);
|
||||
export const DriveFiles = getCustomRepository(DriveFileRepository);
|
||||
export const DriveFolders = getCustomRepository(DriveFolderRepository);
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
import config from '@/config/index';
|
||||
|
39
packages/backend/src/models/repositories/instance.ts
Normal file
39
packages/backend/src/models/repositories/instance.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
import { EntityRepository, Repository } from 'typeorm';
|
||||
import { Instance } from '@/models/entities/instance';
|
||||
import { Packed } from '@/misc/schema';
|
||||
|
||||
@EntityRepository(Instance)
|
||||
export class InstanceRepository extends Repository<Instance> {
|
||||
public async pack(
|
||||
instance: Instance,
|
||||
): Promise<Packed<'FederationInstance'>> {
|
||||
return {
|
||||
id: instance.id,
|
||||
caughtAt: instance.caughtAt.toISOString(),
|
||||
host: instance.host,
|
||||
usersCount: instance.usersCount,
|
||||
notesCount: instance.notesCount,
|
||||
followingCount: instance.followingCount,
|
||||
followersCount: instance.followersCount,
|
||||
latestRequestSentAt: instance.latestRequestSentAt ? instance.latestRequestSentAt.toISOString() : null,
|
||||
lastCommunicatedAt: instance.lastCommunicatedAt.toISOString(),
|
||||
isNotResponding: instance.isNotResponding,
|
||||
isSuspended: instance.isSuspended,
|
||||
softwareName: instance.softwareName,
|
||||
softwareVersion: instance.softwareVersion,
|
||||
openRegistrations: instance.openRegistrations,
|
||||
name: instance.name,
|
||||
description: instance.description,
|
||||
maintainerName: instance.maintainerName,
|
||||
maintainerEmail: instance.maintainerEmail,
|
||||
iconUrl: instance.iconUrl,
|
||||
infoUpdatedAt: instance.infoUpdatedAt ? instance.infoUpdatedAt.toISOString() : null,
|
||||
};
|
||||
}
|
||||
|
||||
public packMany(
|
||||
instances: Instance[],
|
||||
) {
|
||||
return Promise.all(instances.map(x => this.pack(x)));
|
||||
}
|
||||
}
|
|
@ -34,14 +34,6 @@ export const packedFederationInstanceSchema = {
|
|||
type: 'number',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
driveUsage: {
|
||||
type: 'number',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
driveFiles: {
|
||||
type: 'number',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
latestRequestSentAt: {
|
||||
type: 'string',
|
||||
optional: false, nullable: true,
|
||||
|
|
Loading…
Reference in a new issue