Skip to content

Commit

Permalink
move logit into submit
Browse files Browse the repository at this point in the history
  • Loading branch information
JEngdahl committed Dec 23, 2020
1 parent ebf955b commit c187fe9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 40 deletions.
65 changes: 36 additions & 29 deletions src/record/index.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
import axios, { AxiosPromise } from 'axios';
import axios, { AxiosPromise, AxiosResponse } from 'axios';
import { RecordSearchType } from '../types/records';

export class PublicRecord {
#baseUrl: string = 'https://pubrec6.hillsclerk.com/Public/ORIUtilities/OverlayWatermark/api/Watermark/';
records: RecordSearchType[] = [];
constructor(records: RecordSearchType | RecordSearchType[]) {
if (Array.isArray(records)) {
this.addMultiple(records);
} else {
this.addOne(records);
#baseUrl: string = 'https://pubrec6.hillsclerk.com/Public/ORIUtilities/OverlayWatermark/api/Watermark/';
records: RecordSearchType[] = [];
constructor(records?: RecordSearchType | RecordSearchType[]) {
if (Array.isArray(records)) {
this.addMultiple(records);
} else if (records !== undefined) {
this.addOne(records);
}
}
}

addOne(record: RecordSearchType): PublicRecord {
this.records.push(record);
return this;
}
addOne(record: RecordSearchType): PublicRecord {
this.records.push(record);
return this;
}

addMultiple(records: RecordSearchType[]): PublicRecord {
this.records = [...this.records, ...records];
return this;
}

private getRecordId(record: RecordSearchType) {
if (typeof record === 'string') {
return record;
}
return record.ID;
}

requestUrls(): string[] {
return this.records
.map(this.getRecordId)
.map(id => this.#baseUrl + id);
}

submit(): Promise<AxiosResponse[]> {
const reqs = this.requestUrls()
.map(url => axios.get(url));

addMultiple(records: RecordSearchType[]): PublicRecord {
this.records = [...this.records, ...records];
return this;
}
return Promise.all(reqs)

private getRecordId(record: RecordSearchType) {
if (typeof record === 'string') {
return record;
}
return record.ID;
}

submit(): AxiosPromise[] {
return this.records
.flat()
.map(this.getRecordId)
.map((id) => axios.get(this.#baseUrl + id));
}
}
22 changes: 11 additions & 11 deletions src/types/records.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { SearchableDocument } from './documents';

export type PublicRecordType = {
Instrument: number;
PartiesOne: string[];
PartiesTwo: string[];
RecordDate: number;
DocType: SearchableDocument;
BookType: string;
BookNum: number;
PageNum: number;
Legal?: string;
SalesPrice: number;
ID: string;
Instrument: number;
PartiesOne: string[];
PartiesTwo: string[];
RecordDate: number;
DocType: SearchableDocument;
BookType: string;
BookNum: number;
PageNum: number;
Legal?: string;
SalesPrice: number;
ID: string;
};

export type RecordSearchType = string | PublicRecordType;

0 comments on commit c187fe9

Please sign in to comment.