Skip to content

Commit d578a26

Browse files
committed
client store solved
1 parent d26e728 commit d578a26

File tree

9 files changed

+28
-17
lines changed

9 files changed

+28
-17
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"test": "ng test",
1010
"lint": "ng lint",
1111
"e2e": "ng e2e",
12-
"server": "json-server --watch server/db.json --delay 600 --middlewares server/exists.js"
12+
"server": "json-server --watch server/db.json --routes routes.json --delay 600 --middlewares server/exists.js"
1313
},
1414
"private": true,
1515
"dependencies": {

routes.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"/api/*": "/$1",
3+
"/client": "/clients",
4+
"/todo": "/todos",
5+
"/reset": "/reset"
6+
}

server/db.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
{
1313
"id": 2,
14-
"company": "Zboo",
14+
"company": "Zbooxx",
1515
"description": "Exercitation voluptate ipsum occaecat est id veniam eiusmod. Dolor aute adipisicing ullamco cupidatat cupidatat nisi nulla officia anim laboris voluptate Lorem. Exercitation aliquip enim ut magna consequat proident. Elit officia Lorem exercitation consequat ea cillum in aliqua. Ad commodo in sit proident laborum do sint.\n\nMollit ullamco nisi cillum exercitation qui excepteur mollit non nostrud cillum sit consequat fugiat et. Exercitation laborum commodo incididunt do nisi quis aliquip duis. Lorem est veniam veniam non magna nisi mollit reprehenderit laborum. Velit consectetur enim sunt sint eu cupidatat ea aute Lorem sint mollit aute non sint. Et Lorem laboris Lorem veniam do voluptate laboris mollit veniam aute. Voluptate exercitation excepteur irure dolore quis fugiat esse reprehenderit dolor duis in occaecat nulla.\n\nAd id dolore aute et fugiat laboris duis sit quis labore. Eiusmod ad minim veniam proident elit amet tempor officia anim qui incididunt. Nulla eiusmod Lorem culpa esse nostrud quis occaecat esse do ipsum fugiat irure pariatur.",
1616
"address": "916 Beverley Road, Martinez, Kentucky, 4406",
1717
"name": "Bryan Leonard",
@@ -2112,4 +2112,4 @@
21122112
"completed": false
21132113
}
21142114
]
2115-
}
2115+
}

src/app/pages/clients/containers/clients-page/clients-page.component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { Observable, Subject } from 'rxjs';
88
import { Client } from '../../../../store/client/models/client.model';
99

1010
import * as fromClient from '../../../../store/client';
11-
import { ClientItemActionTypes } from '../../../../store/client';
1211
import { select, Store } from '@ngrx/store';
1312
import { GridPayload } from '../../../../shared/models/grid.payload';
1413
import { MatDialog } from '@angular/material';
@@ -49,8 +48,8 @@ export class ClientsPageComponent implements OnInit, OnDestroy {
4948
actions$
5049
.pipe(
5150
ofType(
52-
ClientItemActionTypes.AddClientSuccess,
53-
ClientItemActionTypes.UpdateClientSuccess
51+
fromClient.ClientItemActionTypes.AddClientSuccess,
52+
fromClient.ClientItemActionTypes.UpdateClientSuccess
5453
),
5554
takeUntil(this.destroyed$),
5655
tap(() => {

src/app/store/client/services/client.service.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ import {
77
} from 'src/app/store/client/models/client.model';
88
import { GridPayload } from '../../../shared/models/grid.payload';
99
import { Observable } from 'rxjs';
10+
import { environment } from '../../../../environments/environment';
1011

1112
@Injectable({
1213
providedIn: 'root',
1314
})
1415
export class ClientService extends BaseService {
16+
apiUrl = environment.apiUrl;
17+
1518
getClientList(gridInfo: GridPayload) {
1619
return this.gridRequest<ClientApiModel>(
17-
'/clients',
20+
this.apiUrl + '/clients',
1821
gridInfo.offset,
1922
gridInfo.sortProp,
2023
gridInfo.sortDir
@@ -27,14 +30,17 @@ export class ClientService extends BaseService {
2730
}
2831

2932
addClient(payload: Client): Observable<Client> {
30-
return this.http.post<Client>('/clients', payload);
33+
return this.http.post<Client>(this.apiUrl + '/clients', payload);
3134
}
3235

3336
updateClient(payload: Client): Observable<Client> {
34-
return this.http.put<Client>(`/clients/${payload.id}`, payload);
37+
return this.http.put<Client>(
38+
`${this.apiUrl}/clients/${payload.id}`,
39+
payload
40+
);
3541
}
3642

3743
deleteClient(id: number) {
38-
return this.http.delete(`/clients/${id}`);
44+
return this.http.delete(`${this.apiUrl}/clients/${id}`);
3945
}
4046
}

src/app/store/store.module.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ import { NgrxCacheModule, NgrxCache } from 'apollo-angular-cache-ngrx';
99

1010
import { reducers, metaReducers } from '.';
1111
import { TodoEffects } from './todo/effects';
12-
import { ClientListEffects } from './client/effects/list.effects';
13-
import { ClientItemEffects } from './client/effects/item.effects';
14-
1512
import { environment } from '../../environments/environment';
1613

1714
@NgModule({
@@ -21,14 +18,14 @@ import { environment } from '../../environments/environment';
2118
metaReducers,
2219
runtimeChecks: {
2320
strictStateImmutability: true,
24-
strictActionImmutability: true,
21+
strictActionImmutability: false, // TODO need to be true
2522
},
2623
}),
2724
StoreDevtoolsModule.instrument({
2825
maxAge: 25,
2926
logOnly: environment.production,
3027
}),
31-
EffectsModule.forRoot([TodoEffects, ClientItemEffects, ClientListEffects]),
28+
EffectsModule.forRoot([TodoEffects]),
3229
StoreRouterConnectingModule.forRoot(),
3330
NgrxCacheModule,
3431
],
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export const environment = {
22
production: false,
33
hmr: true,
4+
apiUrl: '/api',
45
};
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const environment = {
2-
production: true
2+
production: true,
3+
apiUrl: '/api',
34
};

src/environments/environment.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// The list of file replacements can be found in `angular.json`.
44

55
export const environment = {
6-
production: false
6+
production: false,
7+
apiUrl: '/api',
78
};
89

910
/*

0 commit comments

Comments
 (0)