39 lines
973 B
TypeScript
39 lines
973 B
TypeScript
import { UndefinedOr } from "../../../../utilities";
|
|
import { RuleValidator } from "../RuleValidator";
|
|
import { Result } from "./Result";
|
|
import {
|
|
IStringValueObjectOptions,
|
|
StringValueObject,
|
|
} from "./StringValueObject";
|
|
|
|
export class Measure extends StringValueObject {
|
|
protected static validate(
|
|
value: UndefinedOr<string>,
|
|
options: IStringValueObjectOptions,
|
|
) {
|
|
const ruleIsEmpty = RuleValidator.RULE_ALLOW_EMPTY.default("").label(
|
|
String(options.label),
|
|
);
|
|
|
|
return RuleValidator.validate<string>(ruleIsEmpty, value);
|
|
}
|
|
|
|
public static create(
|
|
value: UndefinedOr<string>,
|
|
options: IStringValueObjectOptions = {},
|
|
) {
|
|
const _options = {
|
|
label: "description",
|
|
...options,
|
|
};
|
|
|
|
const validationResult = Measure.validate(value, _options);
|
|
|
|
if (validationResult.isFailure) {
|
|
return Result.fail(validationResult.error);
|
|
}
|
|
|
|
return Result.ok(new Measure(validationResult.object));
|
|
}
|
|
}
|