Sharkey/src/services/register-or-fetch-instance-doc.ts

23 lines
477 B
TypeScript
Raw Normal View History

2018-10-24 00:17:55 +03:00
import Instance, { IInstance } from '../models/instance';
import federationChart from '../chart/federation';
2019-02-07 08:00:44 +02:00
export async function registerOrFetchInstanceDoc(host: string): Promise<IInstance> {
2018-10-24 00:17:55 +03:00
if (host == null) return null;
const index = await Instance.findOne({ host });
if (index == null) {
const i = await Instance.insert({
host,
caughtAt: new Date(),
system: null // TODO
});
federationChart.update(true);
return i;
} else {
return index;
}
}