Skip to content

Commit

Permalink
✨ new: custom list of cases; resolve #22
Browse files Browse the repository at this point in the history
  • Loading branch information
hueyy committed Jun 16, 2021
1 parent 1b4190e commit 62d3744
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 3 deletions.
18 changes: 16 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"axios": "^0.21.1",
"axios-cache-adapter": "^2.7.3",
"cheerio": "^1.0.0-rc.9",
"fuse.js": "^6.4.6",
"gestalt-pattern-matcher": "^0.0.12",
"memoizee": "^0.4.15",
"qs": "^6.10.1",
Expand Down Expand Up @@ -132,4 +133,4 @@
"wext-manifest-loader": "^2.3.0",
"wext-manifest-webpack-plugin": "^1.2.1"
}
}
}
6 changes: 6 additions & 0 deletions src/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ const MISC_DATABASES = {
name: `CommonLII`,
url: `http://www.commonlii.org`,
},
custom: {
icon: ``,
id: `custom`,
name: `Clerkent`,
url: `#`,
},
}

const INSTITUTIONAL_LOGINS = {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/scraper/UK/UK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type Law from '../../../types/Law'
import BAILII from './BAILII'
import Common from '../common'
import LegislationGovUk from './LegislationGovUk'
import Custom from '../custom'
import Logger from '../../Logger'
import Helpers from '../../Helpers'
import { sortUKCitations } from '../../Finder/CaseCitationFinder/UK'
Expand All @@ -12,6 +13,7 @@ const getLegislation = LegislationGovUk.getLegislation
const getCaseByName = async (caseName: string): Promise<Law.Case[]> => {
try {
const results = (await Promise.allSettled([
Custom.getCaseByName(caseName),
BAILII.getCaseByName(caseName),
Common.CommonLII.getCaseByName(caseName, Constants.JURISDICTIONS.UK.name),
]))
Expand All @@ -35,6 +37,7 @@ const getCaseByName = async (caseName: string): Promise<Law.Case[]> => {
const getCaseByCitation = async (citation: string, court: string): Promise<Law.Case[]> => {
try {
const results = (await Promise.allSettled([
Custom.getCaseByCitation(citation, court),
BAILII.getCaseByCitation(citation),
Common.CommonLII.getCaseByCitation(citation),
])).filter(({ status }) => status === `fulfilled`)
Expand Down
37 changes: 37 additions & 0 deletions src/utils/scraper/custom/Custom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Fuse from 'fuse.js'
import type Law from "../../../types/Law"
import CustomDB from './CustomDB'
import type { RawCase } from './CustomDB'

const { cases: CustomCases } = CustomDB

const toLawCase = ({ citations, ...others }: RawCase): Law.Case => ({
...others,
citation: citations[0],
})

const getCaseByName = async (caseName: string): Promise<Law.Case[]> => {
const fuse = new Fuse(CustomCases.map(({ name }) => name), {})
return fuse
.search(caseName)
.map(({ refIndex }) => CustomCases[refIndex])
.map(rawCase => toLawCase(rawCase))
}

const getCaseByCitation = async (citation: string, court: string): Promise<Law.Case[]> => Promise.resolve(
CustomCases
.filter(({ citations }) =>
citations.some((cit) => (new RegExp(`${citation}`, `i`)).test(cit)),
)
.map(({ citations, ...others }) => ({
...others,
citation: citations[0],
})),
)

const Custom = {
getCaseByCitation,
getCaseByName,
}

export default Custom
36 changes: 36 additions & 0 deletions src/utils/scraper/custom/CustomDB.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type Law from "../../../types/Law"
import Constants from "../../Constants"

export interface RawCase extends Omit<Law.Case, `citation`> {
citations: Law.Case[`citation`][],
}

const CustomDBCases: RawCase[] = [
{
citations: [
`[1957] 1 WLR 582`,
`[1957] 2 All ER 118​`,
],
database: Constants.DATABASES.custom,
jurisdiction: Constants.JURISDICTIONS.UK.id,
links: [
{
doctype: `Judgment`,
filetype: `HTML`,
url: `https://web.archive.org/web/20160122042428/http://oxcheps.new.ox.ac.uk:80/casebook/Resources/BOLAMV_1%20DOC.pdf`,
},
{
doctype: `Judgment`,
filetype: `PDF`,
url: `https://web.archive.org/web/20160122042428if_/http://oxcheps.new.ox.ac.uk:80/casebook/Resources/BOLAMV_1%20DOC.pdf`,
},
],
name: `Bolam v Friern Hospital Management Committee`,
},
]

const CustomDB = {
cases: CustomDBCases,
}

export default CustomDB
1 change: 1 addition & 0 deletions src/utils/scraper/custom/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Custom'

0 comments on commit 62d3744

Please sign in to comment.