mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 05:21:15 +00:00
fix(server): phase 1 review follow-ups — awaited returns, logged upload-filter rejections, covered handshake/notice branches, call-graph gate in CI, dead test imports
This commit is contained in:
@@ -755,7 +755,7 @@ export class AccommodationsService {
|
||||
deletedBudgetItemIds: number[];
|
||||
mirror: AccommodationMirror;
|
||||
}> {
|
||||
return this.uow.transactional(async () => {
|
||||
return await this.uow.transactional(async () => {
|
||||
const linkedRes = this.db.all<{ id: number }>('SELECT id FROM reservations WHERE accommodation_id = ?', Number(id));
|
||||
const deletedBudgetItemIds: number[] = [];
|
||||
for (const res of linkedRes) {
|
||||
|
||||
@@ -594,7 +594,7 @@ export class AtlasService {
|
||||
* "3 countries added" is not counting the ones that were already there.
|
||||
*/
|
||||
async markCountry(userId: number, code: string, source: 'manual' | 'dawarich' = 'manual'): Promise<boolean> {
|
||||
return this.uow.transactional(async () => {
|
||||
return await this.uow.transactional(async () => {
|
||||
const inserted = this.db
|
||||
.prepare('INSERT OR IGNORE INTO visited_countries (user_id, country_code, source) VALUES (?, ?, ?)')
|
||||
.run(userId, code, source).changes > 0;
|
||||
|
||||
@@ -68,7 +68,11 @@ export class AutoBackupJob implements OnApplicationBootstrap {
|
||||
|
||||
const settings = loadSettings();
|
||||
if (settings.keep_days > 0) {
|
||||
await cleanupOldBackups(this.storage, settings.keep_days);
|
||||
try {
|
||||
await cleanupOldBackups(this.storage, settings.keep_days);
|
||||
} catch (err: unknown) {
|
||||
logError(`Auto-Backup cleanup: ${err instanceof Error ? err.message : String(err)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -118,13 +118,12 @@ export class DocSyncWebhookController implements OnModuleDestroy {
|
||||
const fresh = await reload();
|
||||
if (!fresh || fresh.sync_enabled !== 1) return;
|
||||
if (!(await this.syncIsOn(fresh))) return;
|
||||
void this.sync.syncLink(fresh).then((res) => {
|
||||
// A run that was already in flight answers `busy`, and the changes this
|
||||
// nudge was about may have landed after that run read the folder. Ask
|
||||
// again once rather than waiting out a whole poll interval: once, and
|
||||
// only for `busy`, so this cannot become a loop.
|
||||
if (res?.state === 'busy' && !isRetry) this.schedule(linkId, reload, true);
|
||||
});
|
||||
const res = await this.sync.syncLink(fresh);
|
||||
// A run that was already in flight answers `busy`, and the changes this
|
||||
// nudge was about may have landed after that run read the folder. Ask
|
||||
// again once rather than waiting out a whole poll interval: once, and
|
||||
// only for `busy`, so this cannot become a loop.
|
||||
if (res?.state === 'busy' && !isRetry) this.schedule(linkId, reload, true);
|
||||
})().catch((err: unknown) => {
|
||||
logError(`Document sync webhook nudge failed for link ${linkId}: ${err instanceof Error ? err.message : String(err)}`);
|
||||
});
|
||||
|
||||
@@ -32,6 +32,7 @@ import { Trip } from '../permissions/trip.decorator';
|
||||
import { MAX_FILE_SIZE, BLOCKED_EXTENSIONS, isVideoExtension } from './files.constants';
|
||||
import { FileUploadDto, FileUpdateDto, FileLinkDto } from './files.dto';
|
||||
import { AllowedFileTypesService } from './allowed-file-types.service';
|
||||
import { logError } from '../audit/audit-log.logger';
|
||||
|
||||
/**
|
||||
* Trip-file upload filter, built from the container.
|
||||
@@ -59,7 +60,7 @@ export function filesUploadFileFilter(allowedTypes: AllowedFileTypesService): Op
|
||||
// rejection refuses the file, so the filter still fails closed. Only the
|
||||
// await is wrapped in try/catch, so a throw from cb() itself is never
|
||||
// re-routed into a second cb() call.
|
||||
void (async () => {
|
||||
(async () => {
|
||||
let allowed: string[];
|
||||
try {
|
||||
allowed = (await allowedTypes.get()).split(',').map((e) => e.trim().toLowerCase());
|
||||
@@ -70,7 +71,10 @@ export function filesUploadFileFilter(allowedTypes: AllowedFileTypesService): Op
|
||||
// Video is accepted as media regardless of the admin doc-types allowlist (#823).
|
||||
if (allowed.includes(fileExt) || isVideoExtension(fileExt) || (allowed.includes('*') && !BLOCKED_EXTENSIONS.includes(ext))) return cb(null, true);
|
||||
reject();
|
||||
})();
|
||||
})().catch((err: unknown) => {
|
||||
logError(`files upload fileFilter: ${err instanceof Error ? err.message : String(err)}`);
|
||||
cb(err instanceof Error ? err : new Error(String(err)));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ import {
|
||||
} from './journey.dto';
|
||||
import { isVideoMime, isVideoExtension, MAX_VIDEO_SIZE } from '../files/files.constants';
|
||||
import { AllowedFileTypesService } from '../files/allowed-file-types.service';
|
||||
import { logError } from '../audit/audit-log.logger';
|
||||
|
||||
/**
|
||||
* One filename hook for all four journey upload routes (consumed by
|
||||
@@ -89,7 +90,7 @@ export function journeyImageFileFilter(allowedTypes: AllowedFileTypesService): O
|
||||
// refuses the file, so the filter still fails closed. Only the await is
|
||||
// wrapped in try/catch, so a throw from cb() itself is never re-routed
|
||||
// into a second cb() call.
|
||||
void (async () => {
|
||||
(async () => {
|
||||
let allowed: string[];
|
||||
try {
|
||||
allowed = (await allowedTypes.get()).split(',').map((e) => e.trim().toLowerCase());
|
||||
@@ -98,7 +99,10 @@ export function journeyImageFileFilter(allowedTypes: AllowedFileTypesService): O
|
||||
}
|
||||
if (!allowed.includes('*') && !allowed.includes(ext)) return reject();
|
||||
cb(null, true);
|
||||
})();
|
||||
})().catch((err: unknown) => {
|
||||
logError(`journey photo fileFilter: ${err instanceof Error ? err.message : String(err)}`);
|
||||
cb(err instanceof Error ? err : new Error(String(err)));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,9 @@ export class RealtimeGateway
|
||||
* Every rejection closes with the code the client already handles: 4001 for
|
||||
* anything about identity, 4403 for the MFA policy. The order matters and is
|
||||
* unchanged — a missing token is refused before the store is touched, and the
|
||||
* password-version gate runs before the MFA one.
|
||||
* password-version gate runs before the MFA one. An unexpected error anywhere
|
||||
* in the handshake is also closed as 4001, reason 'connection setup failed',
|
||||
* instead of escaping as an uncaught exception.
|
||||
*/
|
||||
async handleConnection(socket: TrekWebSocket, request: IncomingMessage): Promise<void> {
|
||||
// TrekWsAdapter.bindClientConnect fires this from a plain 'connection'
|
||||
|
||||
@@ -30,7 +30,7 @@ export class SchoolHolidaysService {
|
||||
}
|
||||
|
||||
async deleteCountry(code: string) {
|
||||
return this.uow.transactional(async () => {
|
||||
return await this.uow.transactional(async () => {
|
||||
await this.country(code);
|
||||
if (this.db.get('SELECT id FROM school_holiday_regions WHERE country = ? LIMIT 1', code)) {
|
||||
throw new ConflictException('Remove the regions before deleting this country');
|
||||
@@ -59,7 +59,7 @@ export class SchoolHolidaysService {
|
||||
}
|
||||
|
||||
async createRegion(country: string, body: SchoolHolidayRegionRequest) {
|
||||
return this.uow.transactional(async () => {
|
||||
return await this.uow.transactional(async () => {
|
||||
await this.country(country);
|
||||
await this.checkName(country, body.name, 0);
|
||||
if (body.revision !== 0) throw new ConflictException('New regions must have revision zero');
|
||||
@@ -71,7 +71,7 @@ export class SchoolHolidaysService {
|
||||
}
|
||||
|
||||
async updateRegion(id: number, body: SchoolHolidayRegionRequest) {
|
||||
return this.uow.transactional(async () => {
|
||||
return await this.uow.transactional(async () => {
|
||||
const region = await this.region(id);
|
||||
await this.checkName(region.country, body.name, id);
|
||||
const updated = this.db.run('UPDATE school_holiday_regions SET name = ?, revision = revision + 1 WHERE id = ? AND revision = ?', body.name, id, body.revision);
|
||||
@@ -82,7 +82,7 @@ export class SchoolHolidaysService {
|
||||
}
|
||||
|
||||
async deleteRegion(id: number, revision: number) {
|
||||
return this.uow.transactional(async () => {
|
||||
return await this.uow.transactional(async () => {
|
||||
const region = await this.region(id);
|
||||
if (region.revision !== revision) throw new ConflictException('This region changed. Reload before deleting it.');
|
||||
if (this.db.get("SELECT id FROM vacay_holiday_calendars WHERE type = 'school_holiday' AND region = ? LIMIT 1", region.code)) {
|
||||
|
||||
@@ -132,7 +132,7 @@ export class AdminDefaultUserSettingsController {
|
||||
});
|
||||
// Answer with the stored defaults, not the request body: the service normalises
|
||||
// and drops unknown keys, and the admin panel renders straight from this.
|
||||
return this.settings.getAdminUserDefaults();
|
||||
return await this.settings.getAdminUserDefaults();
|
||||
} catch (err) {
|
||||
throw new HttpException({ error: err instanceof Error ? err.message : String(err) }, 400);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ export async function getActiveNoticesFor(
|
||||
user: { ...user, noTrips: tripCount },
|
||||
currentAppVersion,
|
||||
now,
|
||||
addonEnabled: (addonId: string) => addonFlags.get(addonId) ?? false,
|
||||
addonEnabled: (addonId: string) => addonFlags.get(addonId),
|
||||
managed,
|
||||
};
|
||||
const appVer = semver.coerce(currentAppVersion)?.version ?? '0.0.0';
|
||||
|
||||
Reference in New Issue
Block a user