mirror of
https://github.com/unraid/api.git
synced 2026-01-05 16:09:49 -06:00
feat: add parityCheckStatus field to array query (#1611)
Responds with a ParityCheck:
```ts
type ParityCheck {
"""Date of the parity check"""
date: DateTime
"""Duration of the parity check in seconds"""
duration: Int
"""Speed of the parity check, in MB/s"""
speed: String
"""Status of the parity check"""
status: ParityCheckStatus!
"""Number of errors during the parity check"""
errors: Int
"""Progress percentage of the parity check"""
progress: Int
"""Whether corrections are being written to parity"""
correcting: Boolean
"""Whether the parity check is paused"""
paused: Boolean
"""Whether the parity check is running"""
running: Boolean
}
enum ParityCheckStatus {
NEVER_RUN = 'never_run',
RUNNING = 'running',
PAUSED = 'paused',
COMPLETED = 'completed',
CANCELLED = 'cancelled',
FAILED = 'failed',
}
```
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- New Features
- Exposes a structured parity-check status for arrays with detailed
fields (status enum: NEVER_RUN, RUNNING, PAUSED, COMPLETED, CANCELLED,
FAILED), date, duration, speed, progress, errors, and running/paused
flags.
- Tests
- Adds comprehensive unit tests covering all parity-check states,
numeric edge cases, speed/date/duration/progress calculations, and
real-world scenarios.
- Refactor
- Safer numeric/date parsing and a new numeric-conversion helper; minor
formatting/cleanup in shared utilities.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
@@ -16,15 +16,15 @@ import type { Get } from "type-fest";
|
||||
* @returns An array of strings
|
||||
*/
|
||||
export function csvStringToArray(
|
||||
csvString?: string | null,
|
||||
opts: { noEmpty?: boolean } = { noEmpty: true }
|
||||
csvString?: string | null,
|
||||
opts: { noEmpty?: boolean } = { noEmpty: true }
|
||||
): string[] {
|
||||
if (!csvString) return [];
|
||||
const result = csvString.split(',').map((item) => item.trim());
|
||||
if (opts.noEmpty) {
|
||||
return result.filter((item) => item !== '');
|
||||
}
|
||||
return result;
|
||||
if (!csvString) return [];
|
||||
const result = csvString.split(",").map((item) => item.trim());
|
||||
if (opts.noEmpty) {
|
||||
return result.filter((item) => item !== "");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,8 +41,23 @@ export function csvStringToArray(
|
||||
* @returns The nested value or undefined if the path is invalid
|
||||
*/
|
||||
export function getNestedValue<TObj extends object, TPath extends string>(
|
||||
obj: TObj,
|
||||
path: TPath
|
||||
obj: TObj,
|
||||
path: TPath
|
||||
): Get<TObj, TPath> {
|
||||
return path.split('.').reduce((acc, part) => acc?.[part], obj as any) as Get<TObj, TPath>;
|
||||
return path.split(".").reduce((acc, part) => acc?.[part], obj as any) as Get<
|
||||
TObj,
|
||||
TPath
|
||||
>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a value to a number. If the value is NaN, returns the default value.
|
||||
*
|
||||
* @param value - The value to convert to a number
|
||||
* @param defaultValue - The default value to return if the value is NaN. Default is 0.
|
||||
* @returns The number value or the default value if the value is NaN
|
||||
*/
|
||||
export function toNumberAlways(value: unknown, defaultValue = 0): number {
|
||||
const num = Number(value);
|
||||
return Number.isNaN(num) ? defaultValue : num;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user