Skip to content

Commit e8deff7

Browse files
fix: fix ts errors
1 parent 1276e52 commit e8deff7

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

src/lib/adopted-probes.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ type AdoptedProbe = {
1414
}
1515

1616
export class AdoptedProbes {
17-
private adoptedProbesByIp: Map<AdoptedProbe['ip'], Omit<AdoptedProbe, 'ip'>> = new Map();
1817
private connectedIpToUuid: Map<string, string> = new Map();
1918
private connectedUuidToIp: Map<string, string> = new Map();
2019

@@ -37,7 +36,6 @@ export class AdoptedProbes {
3736
this.connectedUuidToIp = new Map(allSockets.map(socket => [ socket.data.probe.uuid, socket.data.probe.ipAddress ]));
3837

3938
const adoptedProbes = await this.sql(TABLE_NAME).select<AdoptedProbe[]>('ip', 'uuid', 'lastSyncDate');
40-
this.adoptedProbesByIp = new Map(adoptedProbes.map(({ ip, uuid, lastSyncDate }) => [ ip, { uuid, lastSyncDate }]));
4139
await Promise.all(adoptedProbes.map(({ ip, uuid }) => this.syncProbeIds(ip, uuid)));
4240
await Promise.all(adoptedProbes.map(({ ip, lastSyncDate }) => this.updateSyncDate(ip, lastSyncDate)));
4341
}
@@ -62,18 +60,18 @@ export class AdoptedProbes {
6260
}
6361

6462
private async updateSyncDate (ip: string, lastSyncDate: string) {
65-
if (this.isToday(lastSyncDate)) {
63+
if (this.isToday(lastSyncDate)) { // date is already synced
6664
return;
6765
}
6866

6967
const probeIsConnected = this.connectedIpToUuid.has(ip);
7068

71-
if (probeIsConnected) {
69+
if (probeIsConnected) { // date is old, but probe is connected, therefore updating the sync date
7270
await this.updateLastSyncDate(ip);
7371
return;
7472
}
7573

76-
if (this.isMoreThan30DaysAgo(lastSyncDate)) {
74+
if (this.isMoreThan30DaysAgo(lastSyncDate)) { // probe wasn't connected for >30 days, removing adoption
7775
await this.deleteAdoptedProbe(ip);
7876
}
7977
}

test/tests/unit/adopted-probes.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from 'chai';
2-
import { Knex } from 'knex';
2+
import type { Knex } from 'knex';
33
import * as sinon from 'sinon';
44
import { AdoptedProbes } from '../../../src/lib/adopted-probes.js';
55

test/tests/unit/middleware/only-admin.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ beforeEach(() => {
1313
describe('rate limit middleware', () => {
1414
it('should reject requests with "isAdmin" false', async () => {
1515
const ctx = { isAdmin: false } as unknown as Context;
16-
const err = await onlyAdmin()(ctx, next).catch(err => err);
16+
const err = await onlyAdmin()(ctx, next).catch((err: unknown) => err);
1717
expect(err).to.deep.equal(createHttpError(403, 'Forbidden', { type: 'access_forbidden' }));
1818
expect(next.callCount).to.equal(0);
1919
});

0 commit comments

Comments
 (0)