Kind: Service
Source: atloria-monorepo/apps/api/src/doc-version/screenshot-staleness.service.ts
ScreenshotStalenessService evaluates how current a document-version screenshot is and exposes its staleness classification, age in days, and a human-readable explanation. It is used by backend document-version workflows to consistently determine whether screenshots should be considered fresh, aging, or outdated.
Methods
| Method | Signature | Returns | Description |
|---|---|---|---|
getStalenessLevel | `getStalenessLevel(capturedAt: string | Date | null, isCurrentVersion: boolean)` |
getDaysAge | `getDaysAge(date: string | Date)` | number |
getStalenessReason | getStalenessReason(level: StalenessLevel, age: number) | string | Get human-readable reason for the staleness level. |
Where it refuses work
ScreenshotStalenessServicestops the work with an early return when!capturedAt.ScreenshotStalenessServicestops the work with an early return whenisCurrentVersion.ScreenshotStalenessServicestops the work with an early return whenage <= 30.ScreenshotStalenessServicestops the work with an early return whenage <= 90.
Diagram
mermaidsequenceDiagram participant Caller as Document Version Workflow participant Service as ScreenshotStalenessService Caller->>Service: getDaysAge() Service-->>Caller: Screenshot age (days) Caller->>Service: getStalenessLevel() Service-->>Caller: StalenessLevel Caller->>Service: getStalenessReason() Service-->>Caller: Human-readable reason Caller->>Caller: Display status or trigger refresh workflow
Usage
tsimport { Injectable } from '@nestjs/common';
import { ScreenshotStalenessService } from './screenshot-staleness.service';
@Injectable()
export class DocumentVersionStatusService {
constructor(
private readonly screenshotStalenessService: ScreenshotStalenessService,
) {}
getScreenshotStatus() {
return {
level: this.screenshotStalenessService.getStalenessLevel(),
daysAge: this.screenshotStalenessService.getDaysAge(),
reason: this.screenshotStalenessService.getStalenessReason(),
};
}
}
AI Coding Instructions
- Use
getStalenessLevel()as the canonical value for conditional backend behavior, such as flagging or refreshing outdated screenshots. - Use
getDaysAge()for numeric display, sorting, or threshold-related UI/API fields rather than recalculating age elsewhere. - Return
getStalenessReason()alongside the level when exposing staleness data to clients so status decisions remain explainable. - Keep staleness thresholds and classification logic centralized in this service; do not duplicate date-comparison logic in controllers or consumers.
- Ensure consumers handle all available
StalenessLevelvalues rather than assuming only fresh and stale states.
Referenced By
DocVersionModule(MODULE_PROVIDES)DocVersionModule(MODULE_EXPORTS)
Was this page helpful?