Updated to angular 11
Now compiling with strict mode in typescript Need to error checking now
This commit is contained in:
@ -1,4 +1,10 @@
|
||||
export class DiscountReportItem {
|
||||
name: string;
|
||||
amount: number;
|
||||
|
||||
public constructor(init?: Partial<DiscountReportItem>) {
|
||||
this.name = '';
|
||||
this.amount = 0;
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
|
||||
import { DiscountReportComponent } from './discount-report.component';
|
||||
|
||||
@ -6,11 +6,13 @@ describe('DiscountReportComponent', () => {
|
||||
let component: DiscountReportComponent;
|
||||
let fixture: ComponentFixture<DiscountReportComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [DiscountReportComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [DiscountReportComponent],
|
||||
}).compileComponents();
|
||||
}),
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(DiscountReportComponent);
|
||||
|
||||
@ -16,9 +16,9 @@ import { DiscountReportService } from './discount-report.service';
|
||||
styleUrls: ['./discount-report.component.css'],
|
||||
})
|
||||
export class DiscountReportComponent implements OnInit {
|
||||
dataSource: DiscountReportDataSource;
|
||||
info: DiscountReport = new DiscountReport();
|
||||
dataSource: DiscountReportDataSource = new DiscountReportDataSource(this.info.amounts);
|
||||
form: FormGroup;
|
||||
info: DiscountReport;
|
||||
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'amount'];
|
||||
@ -31,11 +31,16 @@ export class DiscountReportComponent implements OnInit {
|
||||
private toaster: ToasterService,
|
||||
private ser: DiscountReportService,
|
||||
) {
|
||||
this.createForm();
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
startDate: '',
|
||||
finishDate: '',
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((data: { info: DiscountReport }) => {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { info: DiscountReport };
|
||||
this.info = data.info;
|
||||
this.form.setValue({
|
||||
startDate: moment(this.info.startDate, 'DD-MMM-YYYY').toDate(),
|
||||
@ -55,20 +60,13 @@ export class DiscountReportComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
startDate: '',
|
||||
finishDate: '',
|
||||
});
|
||||
}
|
||||
|
||||
getInfo(): DiscountReport {
|
||||
const formModel = this.form.value;
|
||||
|
||||
return {
|
||||
return new DiscountReport({
|
||||
startDate: moment(formModel.startDate).format('DD-MMM-YYYY'),
|
||||
finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY'),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
print() {
|
||||
|
||||
@ -16,7 +16,7 @@ const serviceName = 'DiscountReportService';
|
||||
export class DiscountReportService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(startDate: string, finishDate): Observable<DiscountReport> {
|
||||
get(startDate: string | null, finishDate: string | null): Observable<DiscountReport> {
|
||||
const options = { params: new HttpParams() };
|
||||
if (startDate !== null) {
|
||||
options.params = options.params.set('s', startDate);
|
||||
@ -31,7 +31,7 @@ export class DiscountReportService {
|
||||
);
|
||||
}
|
||||
|
||||
print(startDate: string, finishDate): Observable<boolean> {
|
||||
print(startDate: string | null, finishDate: string | null): Observable<boolean> {
|
||||
const printUrl = `${url}/print`;
|
||||
const options = { params: new HttpParams() };
|
||||
if (startDate !== null) {
|
||||
|
||||
@ -3,5 +3,12 @@ import { DiscountReportItem } from './discount-report-item';
|
||||
export class DiscountReport {
|
||||
startDate: string;
|
||||
finishDate: string;
|
||||
amounts?: DiscountReportItem[];
|
||||
amounts: DiscountReportItem[];
|
||||
|
||||
public constructor(init?: Partial<DiscountReport>) {
|
||||
this.startDate = '';
|
||||
this.finishDate = '';
|
||||
this.amounts = [];
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user