Skip to content

Commit

Permalink
Convert all files to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
eriknovak committed Mar 19, 2020
1 parent 520fea9 commit dcdc4df
Show file tree
Hide file tree
Showing 9 changed files with 313 additions and 239 deletions.
11 changes: 1 addition & 10 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"@types/cookie-parser": "^1.4.2",
"@types/elasticsearch": "^5.0.36",
"@types/express": "^4.17.3",
"@types/express-validator": "^3.0.0",
"@types/express-winston": "^4.0.0",
"@types/node": "^13.9.2",
"mocha": "^7.1.1",
Expand Down
66 changes: 66 additions & 0 deletions src/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,70 @@ export interface IConfiguration {
elasticsearch: {
node: string
}
}

////////////////////////////////////////////////////////////////////////
// Elasticsearch records

export interface IContent {
content_id: number
}

export interface IWikipedia {
uri: string,
name: string,
sec_uri: string,
sec_name: string
}

export interface IElasticsearchHit {
_score: number,
_source: {
material_id: number,
title: string,
description: string,
creation_date: string,
retrieved_date: string,
type: string,
mimetype: string,
material_url: string,
website_url: string,
language: string,
license: {
short_name: string,
typed_name?: string[],
disclaimer: string,
url: string
},
contents?: IContent[],
provider_id: number,
provider_name: string,
provider_url: string,
wikipedia: IWikipedia[]
}
}


////////////////////////////////////////////////////////////////////////
// Express API routes

export interface ISearch {
text?: string,
url?: string,
types?: string,
licenses?: string,
languages?: string,
content_languages?: string,
provider_ids?: string,
wikipedia?: boolean,
wikipedia_limit?: number,
limit?: number,
page?: number
}

export interface IQueryElement {
term?: object,
terms?: object,
regexp?: object,
exists?: object
}
22 changes: 11 additions & 11 deletions src/load/create-elasticsearch-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function materialType(mimetype) {
}

// merges all of the material information into a single line
const pg_command = `
const pgCommand = `
WITH URLS AS (
SELECT
COALESCE(m.material_id, c.material_id) AS material_id,
Expand Down Expand Up @@ -162,7 +162,7 @@ async function populate() {

console.log("executing pg-command");

pg.executeLarge(pg_command, [], 100,
pg.executeLarge(pgCommand, [], 100,
(error, records, callback) => {
if (error) { console.log(error); return; }

Expand All @@ -179,26 +179,26 @@ async function populate() {

// modify the license attribute when sending to elasticsearch
const url = record.license;
let short_name;
let typed_name;
let shortName;
let typedName;
let disclaimer = DEFAULT_DISCLAIMER;

if (url) {
const regex = /\/licen[sc]es\/([\w\-]+)\//;
short_name = url.match(regex)[1];
typed_name = short_name.split("-");
shortName = url.match(regex)[1];
typedName = shortName.split("-");
} else {
short_name = NO_LICENSE_DISCLAIMER;
shortName = NO_LICENSE_DISCLAIMER;
}
record.license = {
short_name,
typed_name,
short_name: shortName,
typed_name: typedName,
disclaimer,
url
};

// modify the wikipedia array
for (let value of record.wikipedia) {
for (const value of record.wikipedia) {
// rename the wikipedia concepts
value.sec_uri = value.secUri;
value.sec_name = value.secName;
Expand All @@ -221,7 +221,7 @@ async function populate() {
count++;
xcallback(null);
})
.catch((error) => xcallback);
.catch(xcallback);
});
}

Expand Down
7 changes: 5 additions & 2 deletions src/routes/v1/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Express } from "express";
import { IConfiguration } from "../../Interfaces";

import search from "./oer_materials";
import recommend from "./recommend";

// join all routers in a single function
export default function index(app: Express, config: IConfiguration) {
// setup the microservices API routes
app.use("/api/v1", require("./oer_materials")(config));
app.use("/api/v1", require("./recommend")(config));
app.use("/api/v1", search(config));
app.use("/api/v1", recommend(config));
};
Loading

0 comments on commit dcdc4df

Please sign in to comment.