@opinio-dev/models 1.2.1-item-details.2 → 1.3.1-movie-form.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/types/items/Movie.d.ts +3 -1
- package/dist/validation/BaseValidator.d.ts +5 -0
- package/dist/validation/BaseValidator.js +8 -0
- package/dist/validation/FieldValidationResult.d.ts +4 -0
- package/dist/validation/FieldValidationResult.js +1 -0
- package/dist/validation/Validator.d.ts +8 -0
- package/dist/validation/items/MovieValidator.js +3 -3
- package/package.json +1 -1
|
@@ -4,8 +4,10 @@ export interface IMovie extends IBaseItem {
|
|
|
4
4
|
type: 'movie';
|
|
5
5
|
genres: VideoGenre[];
|
|
6
6
|
duration: number;
|
|
7
|
-
|
|
7
|
+
directors: string[];
|
|
8
8
|
cast: string[];
|
|
9
|
+
mpaaRating: string;
|
|
10
|
+
trailerUrl?: string;
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
11
13
|
* Determines if the given item is a movie
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IFieldValidationResult } from './FieldValidationResult.js';
|
|
1
2
|
import { IValidationResult } from './ValidationResult.js';
|
|
2
3
|
import { IValidator } from './Validator.js';
|
|
3
4
|
/**
|
|
@@ -8,6 +9,10 @@ export declare abstract class BaseValidator<T> implements IValidator<T> {
|
|
|
8
9
|
* @inheritdoc
|
|
9
10
|
*/
|
|
10
11
|
validate(item: Partial<T>, ignoredFields?: Array<keyof T>): IValidationResult;
|
|
12
|
+
/**
|
|
13
|
+
* @inheritdoc
|
|
14
|
+
*/
|
|
15
|
+
validateField(item: Partial<T>, field: keyof T): IFieldValidationResult;
|
|
11
16
|
/**
|
|
12
17
|
* Validates fields, returning a record of any errors. Override in subclasses.
|
|
13
18
|
* @param {Partial<T>} item The item to validate.
|
|
@@ -10,6 +10,14 @@ export class BaseValidator {
|
|
|
10
10
|
const filteredErrors = this.__filterIgnoredFields(errors, ignoredFields);
|
|
11
11
|
return this.__createValidationResult(filteredErrors);
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* @inheritdoc
|
|
15
|
+
*/
|
|
16
|
+
validateField(item, field) {
|
|
17
|
+
const errors = this._validateFields(item);
|
|
18
|
+
const error = errors[field];
|
|
19
|
+
return { valid: !error, error };
|
|
20
|
+
}
|
|
13
21
|
/**
|
|
14
22
|
* Filters out errors for ignored fields.
|
|
15
23
|
* @template T The type of the item being validated.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IFieldValidationResult } from './FieldValidationResult.js';
|
|
1
2
|
import { IValidationResult } from './ValidationResult.js';
|
|
2
3
|
export interface IValidator<T> {
|
|
3
4
|
/**
|
|
@@ -7,4 +8,11 @@ export interface IValidator<T> {
|
|
|
7
8
|
* @returns {IValidationResult} The result of the validation.
|
|
8
9
|
*/
|
|
9
10
|
validate(item: Partial<T>, ignoredFields?: Array<keyof T>): IValidationResult;
|
|
11
|
+
/**
|
|
12
|
+
* Validates a passed item's field against predefined rules.
|
|
13
|
+
* @param {Partial<T>} item The item to validate.
|
|
14
|
+
* @param {keyof T} field The field to validate.
|
|
15
|
+
* @returns {IValidationResult} The result of the validation.
|
|
16
|
+
*/
|
|
17
|
+
validateField(item: Partial<T>, field: keyof T): IFieldValidationResult;
|
|
10
18
|
}
|
|
@@ -8,7 +8,7 @@ export class MovieValidator extends BaseItemValidator {
|
|
|
8
8
|
* @inheritdoc
|
|
9
9
|
*/
|
|
10
10
|
_validateTypeSpecificFields(movie) {
|
|
11
|
-
const { genres,
|
|
11
|
+
const { genres, directors, duration, cast } = movie;
|
|
12
12
|
const errors = {};
|
|
13
13
|
if (!genres?.length) {
|
|
14
14
|
errors.genres = 'Movie genres are required';
|
|
@@ -22,8 +22,8 @@ export class MovieValidator extends BaseItemValidator {
|
|
|
22
22
|
if (duration !== undefined && duration <= 0) {
|
|
23
23
|
errors.duration = 'Movie duration is invalid. Duration must be a positive number.';
|
|
24
24
|
}
|
|
25
|
-
if (!
|
|
26
|
-
errors.director = 'Movie director
|
|
25
|
+
if (!directors?.length) {
|
|
26
|
+
errors.director = 'Movie director(s) are required';
|
|
27
27
|
}
|
|
28
28
|
if (!cast?.length) {
|
|
29
29
|
errors.cast = 'Movie cast is required';
|