2022-03-26 15:34:00 +09:00
|
|
|
import { db } from '@/db/postgre.js';
|
2022-02-27 11:07:39 +09:00
|
|
|
import { Instance } from '@/models/entities/instance.js';
|
|
|
|
import { Packed } from '@/misc/schema.js';
|
2022-02-18 20:43:50 +09:00
|
|
|
|
2022-03-26 15:34:00 +09:00
|
|
|
export const InstanceRepository = db.getRepository(Instance).extend({
|
|
|
|
async pack(
|
2022-02-18 20:43:50 +09:00
|
|
|
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,
|
|
|
|
};
|
2022-03-26 15:34:00 +09:00
|
|
|
},
|
2022-02-18 20:43:50 +09:00
|
|
|
|
2022-03-26 15:34:00 +09:00
|
|
|
packMany(
|
2022-02-18 20:43:50 +09:00
|
|
|
instances: Instance[],
|
|
|
|
) {
|
|
|
|
return Promise.all(instances.map(x => this.pack(x)));
|
2022-03-26 15:34:00 +09:00
|
|
|
},
|
|
|
|
});
|