Skip to content

Commit

Permalink
reads _id's from incoming customers
Browse files Browse the repository at this point in the history
  • Loading branch information
dieharders committed Oct 3, 2018
1 parent e0df79f commit 02774a9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
4 changes: 1 addition & 3 deletions src/app/add-customer/add-customer.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,14 @@ <h3>Add Customer</h3>
</div>

<div class="btn-group btn-group-sm">
<button type="button" class="btn btn-dark" (click)="goBack()">Back</button>
<button type="button" class="btn btn-dark" (click)="addCustomer()" [disabled]="!addCustomerForm.form.valid">Add</button>
<button type="button" class="btn btn-dark" (click)="addCustomer()" [disabled]="!addCustomerForm.form.valid">Add</button>
</div>
</form>
</div>

<div [hidden]="!submitted">
<p>Submitted Successfully! -> <span class="badge badge-light">{{customer.firstname}} {{customer.lastname}}</span></p>
<div class="btn-group btn-group-sm">
<button type="button" class="btn btn-dark" (click)="goBack()">Back</button>
<button type="button" class="btn btn-dark" (click)="newCustomer(); addCustomerForm.reset()">Continue</button>
</div>
</div>
8 changes: 4 additions & 4 deletions src/app/add-customer/add-customer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export class AddCustomerComponent{
this.customer = new Customer();
}

addCustomer() {
this.submitted = true;
this.save();
}
addCustomer() {
this.submitted = true;
this.save();
}

goBack(): void {
this.location.back();
Expand Down
2 changes: 1 addition & 1 deletion src/app/customer-details/customer-details.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h5><span class="badge badge-light ">{{customer._id}}</span> -> {{customer.firstname}}</h5>
<h5><span class="badge badge-light ">ID: {{customer._id}}</span> -> {{customer.firstname}}</h5>
<div [hidden]="submitted">
<form #detailCustomerForm="ngForm">
<div class="form-group">
Expand Down
4 changes: 2 additions & 2 deletions src/app/customer-details/customer-details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class CustomerDetailsComponent implements OnInit {

ngOnInit(): void {
const id = this.route.snapshot.paramMap.get('id');
// Get the customer via id in url from server
this.customerService.getCustomer(id)
.subscribe(customer => this.customer = customer);
}
Expand All @@ -36,8 +37,7 @@ export class CustomerDetailsComponent implements OnInit {

delete(): void {
this.submitted = true;
//this.customerService.deleteCustomer(this.customer._id)
this.customerService.deleteCustomer('0')
this.customerService.deleteCustomer(this.customer._id)
.subscribe(result => this.message = "Customer Deleted Successfully!");
}

Expand Down
9 changes: 4 additions & 5 deletions src/app/customer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@ const httpOptions = {
})
export class CustomerService {
private customersUrl = 'https://localhost:8080/api/customers'; // URL to web api
constructor(
constructor(
private http: HttpClient
) { }

getCustomers (): Observable<Customer[]> {
return this.http.get<Customer[]>(this.customersUrl)
}

getCustomer(id: string): Observable<Customer> {
getCustomer (id: string): Observable<Customer> {
const url = `${this.customersUrl}/${id}`;
return this.http.get<Customer>(url);
}

addCustomer (customer: Customer): Observable<Customer> {
addCustomer (customer: Customer): Observable<any> {
return this.http.post<Customer>(this.customersUrl, customer, httpOptions);
}

deleteCustomer (customer: Customer | string): Observable<Customer> {
//const id = typeof customer === 'string' ? customer : customer._id;
const id = '0';
const id = typeof customer === 'string' ? customer : customer._id;
const url = `${this.customersUrl}/${id}`;

return this.http.delete<Customer>(url, httpOptions);
Expand Down
12 changes: 6 additions & 6 deletions src/app/customer/customer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export class CustomerComponent implements OnInit {

getCustomers() {
return this.customerService.getCustomers()
.subscribe(
customers => {
console.log(customers);
this.customers = customers
}
);
.subscribe(
customers => {
console.log(customers);
this.customers = customers
}
);
}
}

0 comments on commit 02774a9

Please sign in to comment.