Skip to content
This repository was archived by the owner on Oct 27, 2025. It is now read-only.

Commit 3d60286

Browse files
authored
Create models for different page types (#123)
thanks!
1 parent fa2ca75 commit 3d60286

File tree

5 files changed

+283
-0
lines changed

5 files changed

+283
-0
lines changed

src/models/company.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { Page } from './page';
2+
3+
export interface ICompanyEntry {
4+
PageID: string;
5+
PageName: string;
6+
7+
Description: string;
8+
Industry: string;
9+
ParentCompany: string;
10+
Type: string;
11+
Website: string;
12+
}
13+
14+
export interface ICompany {
15+
description: string;
16+
industries: string[];
17+
parentCompany: string;
18+
type: string;
19+
websites: string[];
20+
}
21+
22+
export class Company extends Page implements ICompany {
23+
private _description: string;
24+
private _industries: string[];
25+
private _parentCompany: string;
26+
private _type: string;
27+
private _websites: string[];
28+
29+
constructor(companyEntry: ICompanyEntry) {
30+
super({ PageID: companyEntry.PageID, PageName: companyEntry.PageName });
31+
32+
this._description = companyEntry.Description;
33+
this._industries = companyEntry.Industry.split(',').map((industry) => industry.trim());
34+
this._parentCompany = companyEntry.ParentCompany;
35+
this._type = companyEntry.Type;
36+
this._websites = companyEntry.Website.split(',').map((website) => website.trim());
37+
}
38+
39+
get description(): string {
40+
return this._description;
41+
}
42+
43+
get industries(): string[] {
44+
return this._industries;
45+
}
46+
47+
get parentCompany(): string {
48+
return this._parentCompany;
49+
}
50+
51+
get type(): string {
52+
return this._type;
53+
}
54+
55+
get websites(): string[] {
56+
return this._websites;
57+
}
58+
}

src/models/incident.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { Page } from './page';
2+
3+
export interface IIncidentEntry {
4+
PageID: string;
5+
PageName: string;
6+
7+
Company: string;
8+
Description: string;
9+
EndDate: string;
10+
Product: string;
11+
ProductLine: string;
12+
StartDate: string;
13+
Status: string;
14+
Type: string;
15+
}
16+
17+
export interface IIncident {
18+
company: string;
19+
description: string;
20+
endDate: Date;
21+
product: string;
22+
productLine: string;
23+
startDate: Date;
24+
status: 'Active' | 'Pending Resolution' | 'Resolved' | null;
25+
type: string;
26+
}
27+
28+
export class Incident extends Page implements IIncident {
29+
private _company: string;
30+
private _description: string;
31+
private _endDate: Date;
32+
private _product: string;
33+
private _productLine: string;
34+
private _startDate: Date;
35+
private _status: 'Active' | 'Pending Resolution' | 'Resolved' | null;
36+
private _type: string;
37+
38+
constructor(incidentEntry: IIncidentEntry) {
39+
super({ PageID: incidentEntry.PageID, PageName: incidentEntry.PageName });
40+
41+
this._company = incidentEntry.Company;
42+
this._description = incidentEntry.Description;
43+
this._endDate = new Date(incidentEntry.EndDate);
44+
this._product = incidentEntry.Product;
45+
this._productLine = incidentEntry.ProductLine;
46+
this._startDate = new Date(incidentEntry.StartDate);
47+
this._status = ['Active', 'Pending Resolution', 'Resolved'].includes(incidentEntry.Status)
48+
? (incidentEntry.Status as 'Active' | 'Pending Resolution' | 'Resolved')
49+
: null;
50+
this._type = incidentEntry.Type;
51+
}
52+
53+
get company(): string {
54+
return this._company;
55+
}
56+
57+
get description(): string {
58+
return this._description;
59+
}
60+
61+
get endDate(): Date {
62+
return this._endDate;
63+
}
64+
65+
get product(): string {
66+
return this._product;
67+
}
68+
69+
get productLine(): string {
70+
return this._productLine;
71+
}
72+
73+
get startDate(): Date {
74+
return this._startDate;
75+
}
76+
77+
get status(): 'Active' | 'Pending Resolution' | 'Resolved' | null {
78+
return this._status;
79+
}
80+
81+
get type(): string {
82+
return this._type;
83+
}
84+
}

src/models/page.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
export interface IPageEntry {
2+
PageName: string;
3+
PageID: string;
4+
}
5+
6+
export interface IPage {
7+
pageName: string;
8+
pageId: number;
9+
}
10+
11+
export class Page implements IPage {
12+
private static readonly BASE_WIKI_URL: string = 'https://consumerrights.wiki';
13+
14+
private _pageName: string;
15+
private _pageId: number;
16+
17+
constructor(pageEntry: IPageEntry) {
18+
this._pageName = pageEntry.PageName;
19+
this._pageId = Number(pageEntry.PageID);
20+
}
21+
22+
get pageName(): string {
23+
return this._pageName;
24+
}
25+
26+
get pageId(): number {
27+
return this._pageId;
28+
}
29+
30+
public url(): string {
31+
return `${Page.BASE_WIKI_URL}/index.php?curid=${this.pageId.toString()}`;
32+
}
33+
}

src/models/product-line.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Page } from './page';
2+
3+
export interface IProductLineEntry {
4+
PageID: string;
5+
PageName: string;
6+
7+
Category: string;
8+
Company: string;
9+
Description: string;
10+
Website: string;
11+
}
12+
13+
export interface IProductLine {
14+
categories: string[];
15+
company: string;
16+
description: string;
17+
websites: string[];
18+
}
19+
20+
export class ProductLine extends Page implements IProductLine {
21+
private _categories: string[];
22+
private _company: string;
23+
private _description: string;
24+
private _websites: string[];
25+
26+
constructor(entry: IProductLineEntry) {
27+
super({ PageID: entry.PageID, PageName: entry.PageName });
28+
29+
this._categories = entry.Category.split(',').map((category) => category.trim());
30+
this._company = entry.Company;
31+
this._description = entry.Description;
32+
this._websites = entry.Website.split(',').map((website) => website.trim());
33+
}
34+
35+
get categories(): string[] {
36+
return this._categories;
37+
}
38+
39+
get company(): string {
40+
return this._company;
41+
}
42+
43+
get description(): string {
44+
return this._description;
45+
}
46+
47+
get websites(): string[] {
48+
return this._websites;
49+
}
50+
}

src/models/product.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { Page } from './page';
2+
3+
export interface IProductEntry {
4+
PageID: string;
5+
PageName: string;
6+
7+
Category: string;
8+
Company: string;
9+
Description: string;
10+
ProductLine: string;
11+
Website: string;
12+
}
13+
14+
export interface IProduct {
15+
categories: string[];
16+
company: string;
17+
description: string;
18+
productLine: string;
19+
websites: string[];
20+
}
21+
22+
export class Product extends Page implements IProduct {
23+
private _categories: string[];
24+
private _company: string;
25+
private _description: string;
26+
private _productLine: string;
27+
private _websites: string[];
28+
29+
constructor(productEntry: IProductEntry) {
30+
super({ PageID: productEntry.PageID, PageName: productEntry.PageName });
31+
32+
this._categories = productEntry.Category.split(',').map((category) => category.trim());
33+
this._company = productEntry.Company;
34+
this._description = productEntry.Description;
35+
this._productLine = productEntry.ProductLine;
36+
this._websites = productEntry.Website.split(',').map((website) => website.trim());
37+
}
38+
39+
get categories(): string[] {
40+
return this._categories;
41+
}
42+
43+
get company(): string {
44+
return this._company;
45+
}
46+
47+
get description(): string {
48+
return this._description;
49+
}
50+
51+
get productLine(): string {
52+
return this._productLine;
53+
}
54+
55+
get websites(): string[] {
56+
return this._websites;
57+
}
58+
}

0 commit comments

Comments
 (0)