Skip to content

Commit e684c14

Browse files
authored
Merge pull request #5 from laravelcm/validation-rules
Validation rules
2 parents 7cb7974 + b38cff2 commit e684c14

File tree

9 files changed

+33
-20
lines changed

9 files changed

+33
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
export interface SessionState {
2+
formErrors: IValidationError | null;
3+
}
4+
15
export type IValidationError = {
26
message: string;
37
errors: {
48
[key: string]: string[];
59
};
610
status_code: number;
7-
};
11+
};

src/app/core/store/app.store.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { routerReducer, RouterState } from '@ngrx/router-store';
22
import { Action, ActionReducerMap } from '@ngrx/store';
33

4-
import { sessionFeatureKey, sessionReducer, SessionState } from './session/session.reducer';
4+
import { SessionState } from '../interfaces/session.interface';
5+
import { sessionFeatureKey, sessionReducer } from './session/session.reducer';
56

67
export interface AppState {
78
router: RouterState;

src/app/core/store/session/session.reducer.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import { createReducer, on } from '@ngrx/store';
22

3-
import { IValidationError } from '@app/core/interfaces/session.interface';
3+
import { SessionState } from '@app/core/interfaces/session.interface';
44
import * as SessionActions from './session.actions';
55

6-
export interface SessionState {
7-
formErrors: IValidationError | null;
8-
}
9-
106
export const sessionFeatureKey = 'session';
117

128
export const sessionState: SessionState = {

src/app/core/store/session/session.selectors.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createFeatureSelector, createSelector } from '@ngrx/store';
22

3-
import { sessionFeatureKey, SessionState } from './session.reducer';
3+
import { SessionState } from '@app/core/interfaces/session.interface';
4+
import { sessionFeatureKey } from './session.reducer';
45

56
export const sessionFeatureSelector =
67
createFeatureSelector<SessionState>(sessionFeatureKey);

src/app/modules/authentication/pages/reset-password/reset-password.component.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms';
33
import { Store } from '@ngrx/store';
44
import { map, Observable } from 'rxjs';
55

6+
import { PasswordRules } from '@app/shared/rules/password.rule';
67
import {
78
selectError,
89
selectLoading,
910
selectMessage,
1011
selectResetPasswordToken,
1112
} from '../../store/auth.selectors';
1213
import { resetPasswordAction } from '../../store/auth.actions';
13-
import { PasswordRules } from '../../rules/password.rules';
1414

1515
@Component({
1616
templateUrl: './reset-password.component.html',
@@ -29,11 +29,8 @@ export class ResetPasswordComponent {
2929
);
3030

3131
public error$: Observable<string | null> = this.store.select(selectError);
32-
3332
public message$: Observable<string | null> = this.store.select(selectMessage);
34-
3533
public loading$: Observable<boolean> = this.store.select(selectLoading);
36-
3734
public token$: Observable<string | null> = this.store.select(
3835
selectResetPasswordToken
3936
);

src/app/shared/interfaces/response.interface.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ export type IFilterParams = {
1010

1111
export interface Pagination {
1212
total: number;
13-
per_page: number;
14-
current_page: number;
15-
next_page: string | null;
16-
prev_page: string | null;
17-
first_page: string | null;
18-
last_page: string | null;
13+
perPage: number;
14+
currentPage: number;
15+
nextPage: string | null;
16+
prevPage: string | null;
17+
firstPage: string | null;
18+
lastPage: string | null;
1919
from: number;
2020
to: number;
21-
total_pages: number;
21+
totalPages: number;
2222
}

src/app/shared/interfaces/values.interface.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import { Pagination } from './response.interface';
2+
13
/**
24
* This pagination Object is the default structure of
35
* a Custom Laravel Eloquent Pagination Response
46
*
57
* @see https://laravel.com/docs/eloquent-resources#pagination
68
*/
7-
export const pagination = {
9+
export const pagination: Pagination = {
810
total: 0,
911
perPage: 0,
1012
currentPage: 0,
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { AbstractControl, ValidatorFn } from '@angular/forms';
2+
3+
export class WhiteSpaceRule {
4+
static noWhitespace(controlName: string): ValidatorFn {
5+
return (controls: AbstractControl) => {
6+
const control = controls.get(controlName);
7+
const isWhitespace = (control?.value || '').trim().length === 0;
8+
const isValid = !isWhitespace;
9+
return isValid ? null : { whitespace: true };
10+
};
11+
}
12+
}

0 commit comments

Comments
 (0)