From b7fad4d7e4da9f8c223e4773dcd9259c9d68678c Mon Sep 17 00:00:00 2001 From: Zoe Snow Date: Mon, 17 Jul 2017 17:25:30 -0600 Subject: [PATCH] Converting to ES2015 --- .gitignore | 1 + app.js | 24 +-- auth.js | 2 + bin/www | 18 +-- eanaEltuMigration/dictionary.js | 223 ++++++++++++++-------------- eanaEltuMigration/eanaEltu.js | 16 +- eanaEltuMigration/entry.js | 14 +- models/dictionaryBlock.js | 2 +- models/dictionaryBuild.js | 2 +- models/dictionaryBuildData.js | 2 +- models/dictionaryTemplate.js | 2 +- models/entry.js | 2 +- models/entryLayout.js | 22 +-- models/entryLayoutTemplates.js | 2 +- models/entryTemplate.js | 2 +- models/entryType.js | 15 +- models/entryTypeEntries.js | 2 +- models/entryTypeTemplates.js | 2 +- models/index.js | 24 ++- models/language.js | 2 +- models/localizedEntryLayout.js | 2 +- models/localizedMetadata.js | 3 +- models/localizedentry.js | 17 ++- models/metadata.js | 2 +- models/partofspeech.js | 2 +- models/source.js | 2 +- routes/apiV1.js | 4 +- routes/dictionary.routes.v1.js | 92 ------------ routes/index.js | 4 +- routes/users.js | 4 +- routes/v1/dictionary/blocks.js | 7 +- routes/v1/dictionary/buildData.js | 8 +- routes/v1/dictionary/builds.js | 8 +- routes/v1/dictionary/templates.js | 8 +- routes/v1/entries.js | 7 +- routes/v1/entry/layoutTemplates.js | 7 +- routes/v1/entry/layouts.js | 8 +- routes/v1/entry/templates.js | 1 - routes/v1/entry/typeEntries.js | 8 +- routes/v1/entry/typeTemplates.js | 7 +- routes/v1/entry/types.js | 8 +- routes/v1/languages.js | 7 +- routes/v1/localized/entries.js | 32 ++-- routes/v1/localized/entryLayouts.js | 7 +- routes/v1/localized/metadata.js | 7 +- routes/v1/metadata.js | 7 +- routes/v1/partsOfSpeech.js | 7 +- routes/v1/sources.js | 7 +- 48 files changed, 279 insertions(+), 383 deletions(-) create mode 100644 auth.js delete mode 100644 routes/dictionary.routes.v1.js diff --git a/.gitignore b/.gitignore index 8586cb4..0079e95 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ MobileDatabase.iml .idea node_modules +.DS_Store diff --git a/app.js b/app.js index 5758b2f..7536ba7 100644 --- a/app.js +++ b/app.js @@ -1,19 +1,19 @@ process.env.NODE_ENV = "development"; -var express = require('express'); -var path = require('path'); -var favicon = require('serve-favicon'); -var logger = require('morgan'); -var cookieParser = require('cookie-parser'); -var bodyParser = require('body-parser'); +const express = require('express'); +const path = require('path'); +const favicon = require('serve-favicon'); +const logger = require('morgan'); +const cookieParser = require('cookie-parser'); +const bodyParser = require('body-parser'); console.log("ENV: " + process.env.NODE_ENV); -var rebuildDatabase = false; +const rebuildDatabase = true; if(rebuildDatabase){ - var dictionary = require('./eanaEltuMigration/dictionary'); + const dictionary = require('./eanaEltuMigration/dictionary'); dictionary.buildDictionary(function(){ // We have a full Dictionary now to do things with :) @@ -28,10 +28,10 @@ if(rebuildDatabase){ -var app = express(); +const app = express(); -var index = require('./routes/index'); -var apiV1 = require('./routes/apiV1'); +const index = require('./routes/index'); +const apiV1 = require('./routes/apiV1'); // view engine setup app.set('views', path.join(__dirname, 'views')); @@ -50,7 +50,7 @@ app.use('/api/v1', apiV1); // catch 404 and forward to error handler app.use(function(req, res, next) { - var err = new Error('Not Found'); + const err = new Error('Not Found'); err.status = 404; next(err); }); diff --git a/auth.js b/auth.js new file mode 100644 index 0000000..fbe5954 --- /dev/null +++ b/auth.js @@ -0,0 +1,2 @@ + +const passport = require('passport'); diff --git a/bin/www b/bin/www index 69d2aea..f260052 100755 --- a/bin/www +++ b/bin/www @@ -4,22 +4,22 @@ * Module dependencies. */ -var app = require('../app'); -var debug = require('debug')('mobiledatabase:server'); -var http = require('http'); +const app = require('../app'); +const debug = require('debug')('mobiledatabase:server'); +const http = require('http'); /** * Get port from environment and store in Express. */ -var port = normalizePort(process.env.PORT || '3000'); +const port = normalizePort(process.env.PORT || '3000'); app.set('port', port); /** * Create HTTP server. */ -var server = http.createServer(app); +const server = http.createServer(app); /** * Listen on provided port, on all network interfaces. @@ -34,7 +34,7 @@ server.on('listening', onListening); */ function normalizePort(val) { - var port = parseInt(val, 10); + const port = parseInt(val, 10); if (isNaN(port)) { // named pipe @@ -58,7 +58,7 @@ function onError(error) { throw error; } - var bind = typeof port === 'string' + const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; @@ -82,8 +82,8 @@ function onError(error) { */ function onListening() { - var addr = server.address(); - var bind = typeof addr === 'string' + const addr = server.address(); + const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; debug('Listening on ' + bind); diff --git a/eanaEltuMigration/dictionary.js b/eanaEltuMigration/dictionary.js index 004e8c1..20246db 100644 --- a/eanaEltuMigration/dictionary.js +++ b/eanaEltuMigration/dictionary.js @@ -1,9 +1,9 @@ -var format = require('string-format'); -var Entry = require('./entry'); -var EanaEltu = require('./eanaEltu'); -var models = require('../models'); -var Promise = require('bluebird'); +const format = require('string-format'); +const Entry = require('./entry'); +const EanaEltu = require('./eanaEltu'); +const models = require('../models'); +const Promise = require('bluebird'); /* * This Module / Section is to export data from Eana Eltu @@ -37,7 +37,7 @@ Dictionary.prototype.buildDictionary = function (callback) { if(this.debug){ console.log("Building Dictionary..."); } - var self = this; + const self = this; this.eanaEltu.fetchData(function(rawEEdata){ self.eanaEltu = rawEEdata; buildDictionaryLanguages(self); @@ -54,8 +54,8 @@ Dictionary.prototype.buildDictionary = function (callback) { Dictionary.prototype.exportDictionaryBuilds = function () { // Insert Dictionary Types - var self = this; - var blocks = [ // Copied out of EE perl script + const self = this; + const blocks = [ // Copied out of EE perl script { id: 0, description: "Main Block" @@ -94,15 +94,15 @@ Dictionary.prototype.exportDictionaryBuilds = function () { description: "Derivational Morph Block" } ]; - var builds = []; - var buildData = []; - for(var type in self.eanaEltu.dictOrder){ + const builds = []; + const buildData = []; + for(let type in self.eanaEltu.dictOrder){ builds.push({ id: type, description: getDictionaryBuildDescription(type) }); - for(var position in self.eanaEltu.dictOrder[type]){ - var data = self.eanaEltu.dictOrder[type][position]; + for(let position in self.eanaEltu.dictOrder[type]){ + const data = self.eanaEltu.dictOrder[type][position]; if(data.type === "raw"){ data.data1 = getDictionaryBuildTemplate(data.data1); @@ -139,10 +139,10 @@ Dictionary.prototype.exportDictionaryBuilds = function () { Dictionary.prototype.exportLanguages = function (){ "use strict"; // Insert Languages - var self = this; - var languages = []; - for(var langId in self.languages){ - var language = self.languages[langId]; + const self = this; + const languages = []; + for(let langId in self.languages){ + const language = self.languages[langId]; languages.push({ isoCode: langId, isoName: language.engName, @@ -164,9 +164,9 @@ Dictionary.prototype.exportLanguages = function (){ Dictionary.prototype.exportSources = function(){ "use strict"; // Insert Sources - var self = this; - var sources = []; - for(var source in self.sources){ + const self = this; + const sources = []; + for(let source in self.sources){ sources.push({ name: source, description: getSourceDescription(source) @@ -184,8 +184,8 @@ Dictionary.prototype.exportSources = function(){ Dictionary.prototype.exportDictionaryTemplates = function () { // Insert Templates - var self = this; - var templates = [ + const self = this; + const templates = [ { id: "localized_end", latex: "__END__", @@ -212,8 +212,8 @@ Dictionary.prototype.exportDictionaryTemplates = function () { html: "" }]; - for(var id in self.eanaEltu.dictLayout){ - var layout = self.eanaEltu.dictLayout[id]; + for(let id in self.eanaEltu.dictLayout){ + const layout = self.eanaEltu.dictLayout[id]; if(layout.id === "changelog"){ layout.value += "\n\\begin{itemize}\n<>\n\\end{itemize}\n\\end{document}"; } @@ -232,8 +232,8 @@ Dictionary.prototype.exportDictionaryTemplates = function () { Dictionary.prototype.exportEntryTemplates = function () { // Insert Templates - var self = this; - var templates = [ + const self = this; + const templates = [ { id: "PAR", latex: "\\par#", @@ -276,10 +276,10 @@ Dictionary.prototype.exportEntryTemplates = function () { Dictionary.prototype.createLayoutWithTemplates = function(layout){ "use strict"; - var self = this; + const self = this; return models.EntryLayout.create(layout).then(function(entryLayout){ - for(var i = 0; i < layout.templates.length; i++) { - var template = layout.templates[i]; + for(let i = 0; i < layout.templates.length; i++) { + const template = layout.templates[i]; entryLayout.addEntryTemplate(self.entryTemplates[template.id], { through: { position: template.position, @@ -295,15 +295,15 @@ Dictionary.prototype.createLayoutWithTemplates = function(layout){ Dictionary.prototype.createLayoutsWithTemplates = function(layouts) { "use strict"; - var self = this; + const self = this; return new Promise(function(externalResolve, externalReject){ - var externalPromises = []; + const externalPromises = []; if(layouts === undefined || layouts.length === 0){ // Nothing to do... resolve/return externalResolve(); return; } - for(var k = 0; k < layouts.length; k++){ + for(let k = 0; k < layouts.length; k++){ externalPromises.push(self.createLayoutWithTemplates(layouts[k])); } @@ -313,9 +313,9 @@ Dictionary.prototype.createLayoutsWithTemplates = function(layouts) { Dictionary.prototype.createEntryTypeWithMetada = function(entryType, metadata){ "use strict"; - var self = this; + const self = this; return models.EntryType.create(entryType).then(function(newEntryType){ - for(var i = 0; i < metadata.length; i++) { + for(let i = 0; i < metadata.length; i++) { console.log(metadata[i]); newEntryType.addMetadata(self.metadata[metadata[i]]); } @@ -325,9 +325,9 @@ Dictionary.prototype.createEntryTypeWithMetada = function(entryType, metadata){ Dictionary.prototype.exportEntryLayouts = function () { // Insert Templates - var self = this; + const self = this; - var data = [ + const data = [ { id: 'ENTRY', layout: '{entry}', @@ -429,7 +429,7 @@ Dictionary.prototype.exportEntryLayouts = function () { "use strict"; - var validLayouts = [ + const validLayouts = [ 'affixN', 'alloffixN', 'cw', @@ -447,12 +447,12 @@ Dictionary.prototype.exportEntryLayouts = function () { 'note', 'word' ]; - var layouts = []; - var localizedLayouts = []; - for(var lang in self.templates){ - for(var templateId in self.templates[lang]){ + const layouts = []; + const localizedLayouts = []; + for(let lang in self.templates){ + for(let templateId in self.templates[lang]){ if(validLayouts.indexOf(templateId) !== -1){ - var template = self.templates[lang][templateId]; + const template = self.templates[lang][templateId]; if(lang === "raw"){ layouts.push({ @@ -479,8 +479,8 @@ Dictionary.prototype.exportEntryLayouts = function () { } } - var layoutPromises = []; - for(var i = 0; i < layouts.length; i++){ + const layoutPromises = []; + for(let i = 0; i < layouts.length; i++){ layoutPromises.push(self.createEntryTypeWithMetada(layouts[i], layouts[i].metadata)); } @@ -493,12 +493,12 @@ Dictionary.prototype.exportEntryLayouts = function () { Dictionary.prototype.exportMetadata = function () { // Insert Metadata (Including New entries that we need added for other refactorings elsewhere - var self = this; - var metadata = [{ + const self = this; + const metadata = [{ id: "__STANDARD_IPA_ENTRY_TEMPLATE__" }]; - var localizedMetadata = []; - for(var isoCode in self.languages){ + const localizedMetadata = []; + for(let isoCode in self.languages){ localizedMetadata.push({ LanguageIsoCode: isoCode, MetadatumId: "__STANDARD_IPA_ENTRY_TEMPLATE__", @@ -506,8 +506,8 @@ Dictionary.prototype.exportMetadata = function () { }); } - for(var index in self.metadata){ - for(var lc in self.metadata[index]){ + for(let index in self.metadata){ + for(let lc in self.metadata[index]){ if(lc === "en"){ metadata.push({ @@ -537,10 +537,10 @@ Dictionary.prototype.exportMetadata = function () { Dictionary.prototype.exportPartsOfSpeech = function () { // Insert Parts of Speech - var self = this; - var partsOfSpeech = []; - for (var langId in self.partsOfSpeech) { - for (var pos in self.partsOfSpeech[langId]) { + const self = this; + const partsOfSpeech = []; + for (let langId in self.partsOfSpeech) { + for (let pos in self.partsOfSpeech[langId]) { if (pos === "") { continue; } @@ -556,11 +556,11 @@ Dictionary.prototype.exportPartsOfSpeech = function () { Dictionary.prototype.exportEntries = function () { // Insert Entries - var self = this; - var entries = []; - var localizedEntries = []; - for(var id in self.entries){ - var entry = self.entries[id]; + const self = this; + const entries = []; + const localizedEntries = []; + for(let id in self.entries){ + const entry = self.entries[id]; entries.push({ id: entry.id, pubId: entry.pubId, @@ -575,8 +575,8 @@ Dictionary.prototype.exportEntries = function () { createdAt: entry.editTime * 1000 }); - for(var lc in entry.localizations){ - var localizedEntry = entry.localizations[lc]; + for(let lc in entry.localizations){ + const localizedEntry = entry.localizations[lc]; localizedEntries.push({ EntryId: entry.id, LanguageIsoCode: lc, @@ -595,12 +595,12 @@ Dictionary.prototype.export = function (callback) { if(this.debug){ console.log("Exporting Dictionary to new Database..."); } - var self = this; + const self = this; // Using force: true to drop all tables first models.sequelize.sync({force: true}).then(function() { - var topLayerPromises = []; + const topLayerPromises = []; topLayerPromises.push(self.exportLanguages()); topLayerPromises.push(self.exportSources()); topLayerPromises.push(self.exportDictionaryTemplates()); @@ -609,20 +609,20 @@ Dictionary.prototype.export = function (callback) { Promise.all(topLayerPromises).then(function(){ "use strict"; // These need the topLayerPromises to be resolved first, as they require data that they provide - var secondLayerPromises = []; + const secondLayerPromises = []; secondLayerPromises.push(self.exportDictionaryBuilds()); secondLayerPromises.push(self.exportMetadata()); //secondLayerPromises.push(self.exportPartsOfSpeech()); Promise.all(secondLayerPromises).then(function(){ - var thirdLayerPromises = []; + const thirdLayerPromises = []; thirdLayerPromises.push(self.exportEntryLayouts()); Promise.all(thirdLayerPromises).then(function(){ self.exportEntries().then(function () { models.EntryType.findAll().then(function(entryTypes) { - var promises = []; + const promises = []; entryTypes.forEach(function(entryType){ promises.push(entryType.getHtml().then(function(html){ console.log(entryType.id, "HTML ", html); @@ -727,7 +727,7 @@ function getDictionaryBuildDescription(type){ } function getSourceDescription(source) { - var result = source.replace("PF", "Dr. Paul Frommer"); + let result = source.replace("PF", "Dr. Paul Frommer"); if(source === "G"){ result = result.replace("G", "The Avatar Games"); } @@ -758,8 +758,8 @@ function getSourceDescription(source) { } function buildDictionaryLanguages(self) { - for(var index in self.eanaEltu.dictLanguages){ - var language = self.eanaEltu.dictLanguages[index]; + for(let index in self.eanaEltu.dictLanguages){ + const language = self.eanaEltu.dictLanguages[index]; self.languages[index] = { engName: language.engName, nativeName: language.nativeName, @@ -774,7 +774,7 @@ function buildActiveLanguages (self) { return []; } - for(var index in self.languages){ + for(let index in self.languages){ if(self.languages[index].active){ self.activeLanguages.push(index); } @@ -782,15 +782,16 @@ function buildActiveLanguages (self) { } function buildDictionaryMetadata(self) { - for(var index in self.eanaEltu.dictMeta){ + for(let index in self.eanaEltu.dictMeta){ self.metadata[index] = { en: { value: self.eanaEltu.dictMeta[index].value, editTime: self.eanaEltu.dictMeta[index].editTime } }; - var localization = self.eanaEltu.dictLoc[index]; - for(var lc in localization){ + + const localization = self.eanaEltu.dictLoc[index]; + for(let lc in localization){ if(localization[lc].value === '' || localization[lc].value === null || localization[lc].value === undefined){ if(self.debug){ console.log("Missing " + lc + " translation for [" + index + "]"); @@ -940,7 +941,7 @@ function buildDictionaryTemplates(self) { 'derivingaffixNN', 'markerNN', 'eanaInfix']; - var validLayouts = [ + const validLayouts = [ 'affixN', 'alloffixN', 'cw', @@ -959,15 +960,15 @@ function buildDictionaryTemplates(self) { 'word' ]; // Need to get list of languages - for(var lcCode in self.languages){ + for(let lcCode in self.languages){ self.templates[lcCode] = {}; } self.templates['raw'] = {}; - var regex = /__(.*)__/; - var generic_template = "\\par\\textbf{#LEMMA}: [\\textipa{#IPA}] $_{#SOURCE}$ #PART_OF_SPEECH"; + const regex = /__(.*)__/; + const generic_template = "\\par\\textbf{#LEMMA}: [\\textipa{#IPA}] $_{#SOURCE}$ #PART_OF_SPEECH"; - for(var index in self.eanaEltu.dictWordTemplate){ + for(let index in self.eanaEltu.dictWordTemplate){ // Template Cleanup... if(nonIpaTypes.indexOf(index) !== -1 || validLayouts.indexOf(index) === -1){ @@ -976,7 +977,7 @@ function buildDictionaryTemplates(self) { } self.eanaEltu.dictWordTemplate[index].parentId = "IPA_ENTRY"; - var format = self.eanaEltu.dictWordTemplate[index].format; + let format = self.eanaEltu.dictWordTemplate[index].format; format = format.replace("#1", "#LEMMA"); format = format.replace("#2", "#IPA"); @@ -1008,17 +1009,17 @@ function buildDictionaryTemplates(self) { self.eanaEltu.dictWordTemplate[index].parentId += "_PARENS"; } - var sub_entry_lemma_def = "{LAYOUTS.SUB_ENTRY_LEMMA_DEF}"; + const sub_entry_lemma_def = "{LAYOUTS.SUB_ENTRY_LEMMA_DEF}"; format = format.replace("\\textbf{#5} \\textit{#6}", sub_entry_lemma_def); format = format.replace("\\textbf{#6} \\textit{#7}", sub_entry_lemma_def); format = format.replace("\\textbf{#7} \\textit{#8}", sub_entry_lemma_def); - var layout = format; + let layout = format; - var metadataReferences = []; + const metadataReferences = []; - var result; + let result; while(result = layout.match(regex)){ layout = layout.replace(result[0], "{METADATA." + result[1] + "}"); metadataReferences.push(result[1]); @@ -1034,11 +1035,11 @@ function buildDictionaryTemplates(self) { metadataReferences.push("DERIVE_AND_TEXT"); } - for(var lc in self.languages){ + for(let lc in self.languages){ result = format.match(regex); - var localizedFormat = format; + let localizedFormat = format; if(result !== null) { - var meta = self.metadata[result[1]]; + const meta = self.metadata[result[1]]; if(meta[lc] === undefined){ if(self.languages[lc].active){ console.log("MISSING TRANSLATION FOR [" + result[1] + "] in " + lc); @@ -1046,7 +1047,7 @@ function buildDictionaryTemplates(self) { continue; } - var metadata = meta[lc].value; + let metadata = meta[lc].value; metadata = metadata.replace("\\textbf{#5} \\textit{#6}", sub_entry_lemma_def); metadata = metadata.replace("\\textbf{#6} \\textit{#7}", sub_entry_lemma_def); @@ -1071,16 +1072,16 @@ function buildDictionaryTemplates(self) { } else if(index === "cw" || index === "derive"){ - var firstOpenBraceIndex = metadata.indexOf('{'); - var firstCloseBraceIndex = metadata.indexOf('} '); - var secondOpenBraceIndex = metadata.indexOf('{', firstCloseBraceIndex); - var firstMetadataPart = metadata.substring(0, firstOpenBraceIndex); - var secondMetadataPart = metadata.substring(firstCloseBraceIndex + 2, secondOpenBraceIndex); + const firstOpenBraceIndex = metadata.indexOf('{'); + const firstCloseBraceIndex = metadata.indexOf('} '); + const secondOpenBraceIndex = metadata.indexOf('{', firstCloseBraceIndex); + const firstMetadataPart = metadata.substring(0, firstOpenBraceIndex); + const secondMetadataPart = metadata.substring(firstCloseBraceIndex + 2, secondOpenBraceIndex); console.log(firstMetadataPart, secondMetadataPart); metadata = firstMetadataPart; //localizedFormat = metadata; - var key; + let key; if(index === "cw"){ key = "CW_AND_TEXT"; } else if(index === "derive"){ @@ -1137,10 +1138,10 @@ function buildDictionaryTemplates(self) { } function buildDictionaryEntries(self) { - for(var id in self.eanaEltu.dictWordMeta){ - var rawEntry = self.eanaEltu.dictWordMeta[id]; + for(let id in self.eanaEltu.dictWordMeta){ + const rawEntry = self.eanaEltu.dictWordMeta[id]; - var entry = new Entry(rawEntry); + const entry = new Entry(rawEntry); self.sources[entry.source] = entry.source; if(entry.source === "") { @@ -1150,13 +1151,13 @@ function buildDictionaryEntries(self) { self.missingSources.push({id: entry.id, lemma: entry.lemma}); } - for(var lc in self.languages){ + for(let lc in self.languages){ if(self.eanaEltu.dictWordLoc[id] === undefined){ // No localizations have been added yet... // adding an empty object to keep from failing out self.eanaEltu.dictWordLoc[id] = {}; } - var localizedEntry = self.eanaEltu.dictWordLoc[id][lc]; + let localizedEntry = self.eanaEltu.dictWordLoc[id][lc]; if (lc === 'en') { localizedEntry = rawEntry; @@ -1172,7 +1173,7 @@ function buildDictionaryEntries(self) { self.missingEntryTranslations[lc].push({id: id, lemma: entry.lemma}); } else { - var processedLocalizedEntry = entry.addLocalization(localizedEntry, lc); + const processedLocalizedEntry = entry.addLocalization(localizedEntry, lc); if(entry.block === 0){ if(self.partsOfSpeech[processedLocalizedEntry.lc] === undefined){ @@ -1190,10 +1191,10 @@ function buildDictionaryEntries(self) { entry.finalizeEntry(); self.entries[entry.id] = entry; } - var keys = Object.keys(self.partsOfSpeech); + const keys = Object.keys(self.partsOfSpeech); - for(var j = 0; j < keys.length; j++){ - var types = Object.keys(self.partsOfSpeech[keys[j]]).sort(); + for(let j = 0; j < keys.length; j++){ + const types = Object.keys(self.partsOfSpeech[keys[j]]).sort(); if(self.debug){ console.log(keys[j] + " <|> " + types.join(" | ")); } @@ -1201,7 +1202,7 @@ function buildDictionaryEntries(self) { } function processRegexReplace(regex, text, replacementTextStart, replacementTextEnd) { - var result = text.match(regex); + let result = text.match(regex); while(result !== null){ text = text.replace(result[0], replacementTextStart + result[1] + replacementTextEnd); @@ -1212,13 +1213,13 @@ function processRegexReplace(regex, text, replacementTextStart, replacementTextE function processTemplate(template) { - var ipaRegex = /\\textipa\s*\{#(\d*)\}/; - var boldRegex = /\\textbf\s*\{#(\d*)\}/; - var italicRegex = /\\textit\s*\{#(\d*)\}/; - var subscriptRegex = /\$_\{#(\d*)\}\$/; - var smallCapsRegex = /\{\\sc\s*\#(\d*)\}/; - var numRegex = /#(\d*)/; - var parRegex = /\\par(.*)/; + const ipaRegex = /\\textipa\s*\{#(\d*)\}/; + const boldRegex = /\\textbf\s*\{#(\d*)\}/; + const italicRegex = /\\textit\s*\{#(\d*)\}/; + const subscriptRegex = /\$_\{#(\d*)\}\$/; + const smallCapsRegex = /\{\\sc\s*\#(\d*)\}/; + const numRegex = /#(\d*)/; + const parRegex = /\\par(.*)/; template = processRegexReplace(ipaRegex, template, "{", "}"); template = processRegexReplace(boldRegex, template, "{", "}"); @@ -1243,7 +1244,7 @@ function processTemplate(template) { audio: primaryEntry.audio */ -var dictionary = new Dictionary(); +const dictionary = new Dictionary(); module.exports = dictionary; diff --git a/eanaEltuMigration/eanaEltu.js b/eanaEltuMigration/eanaEltu.js index 97bd97a..4446b17 100644 --- a/eanaEltuMigration/eanaEltu.js +++ b/eanaEltuMigration/eanaEltu.js @@ -1,9 +1,9 @@ -var mysql = require('mysql'); +const mysql = require('mysql'); // vault.js is an encrypted module that contains connection info for the db. -var env = process.env.NODE_ENV || "development"; -var vault = require('../vault'); +const env = process.env.NODE_ENV || "development"; +const vault = require('../vault'); function EanaEltu() { this.debug = false; @@ -19,13 +19,13 @@ function EanaEltu() { EanaEltu.prototype.fetchHashTableData = function (query, id, group, callback) { this.dbConnection.query(query, function (err, rows, fields) { if (err) throw err; - var data; + let data; if (id !== undefined) { data = {}; } else { data = []; } - for (var i = 0; i < rows.length; i++) { + for (let i = 0; i < rows.length; i++) { if (id !== undefined) { if (data[rows[i][id]] === undefined) { data[rows[i][id]] = {}; @@ -34,11 +34,11 @@ EanaEltu.prototype.fetchHashTableData = function (query, id, group, callback) { if (data[rows[i][id]][rows[i][group]] === undefined) { data[rows[i][id]][rows[i][group]] = {}; } - for (var j = 0; j < fields.length; j++) { + for (let j = 0; j < fields.length; j++) { data[rows[i][id]][rows[i][group]][fields[j].name] = rows[i][fields[j].name]; } } else { - for (var j = 0; j < fields.length; j++) { + for (let j = 0; j < fields.length; j++) { data[rows[i][id]][fields[j].name] = rows[i][fields[j].name]; } } @@ -53,7 +53,7 @@ EanaEltu.prototype.fetchHashTableData = function (query, id, group, callback) { }; EanaEltu.prototype.fetchData = function (callback) { - var self = this; + const self = this; if(this.debug){ console.log("Fetching EanaEltu Data..."); } diff --git a/eanaEltuMigration/entry.js b/eanaEltuMigration/entry.js index 3875725..3891a12 100644 --- a/eanaEltuMigration/entry.js +++ b/eanaEltuMigration/entry.js @@ -1,5 +1,5 @@ -var format = require('string-format'); +const format = require('string-format'); const nonIpaTypes = [ 'infixNN', @@ -64,7 +64,7 @@ function Entry(rawEntry) { Entry.prototype.addLocalization = function (localizedEntry, lc) { // Pull out each of the 10 args, if the arg is missing from the localized version, use the primary instead - var entry = { + const entry = { odd: localizedEntry.odd, editTime: localizedEntry.editTime, lc: localizedEntry.lc, @@ -92,7 +92,7 @@ Entry.prototype.finalizeEntry = function () { Entry.prototype.parsePartOfSpeech = function(localization) { // Part of Speech - var result = ""; + let result = ""; switch(this.type){ // arg 3 case 'affect': @@ -151,7 +151,7 @@ Entry.prototype.parsePartOfSpeech = function(localization) { function parseSource(entry) { // Source - var source = ""; + let source = ""; switch(entry.type){ // Arg 4 case 'affect': @@ -221,7 +221,7 @@ function parseSource(entry) { function parseIpa(entry) { if(nonIpaTypes.indexOf(entry.type) === -1){ - var rawIpa = entry.arg2; + let rawIpa = entry.arg2; // Need to do some string manipulation to get the correct IPA value out //rawIpa = processRegexReplace(/(\\\\)/g, rawIpa, "\\"); @@ -249,7 +249,7 @@ function parseIpa(entry) { rawIpa = processRegexReplace(/(\$\\cdot\$)/, rawIpa, "\u22C5"); rawIpa = processRegexReplace(/(\$\\_\$)/, rawIpa, "_"); - var missed = rawIpa.match(/(\\)/); + const missed = rawIpa.match(/(\\)/); if(missed !== null){ console.log(missed, entry.arg1, rawIpa, entry.arg2); } @@ -263,7 +263,7 @@ function parseIpa(entry) { } function processRegexReplace(regex, text, replacementText) { - var result = text.match(regex); + let result = text.match(regex); while(result !== null){ text = text.replace(result[0], replacementText); diff --git a/models/dictionaryBlock.js b/models/dictionaryBlock.js index 9f477f4..d6667a0 100644 --- a/models/dictionaryBlock.js +++ b/models/dictionaryBlock.js @@ -1,6 +1,6 @@ 'use strict'; module.exports = function (sequelize, DataTypes) { - var DictionaryBlock = sequelize.define('DictionaryBlock', { + const DictionaryBlock = sequelize.define('DictionaryBlock', { id: { type: DataTypes.INTEGER, primaryKey: true }, description: { type: DataTypes.STRING } }); diff --git a/models/dictionaryBuild.js b/models/dictionaryBuild.js index 87af4b9..44a9fa1 100644 --- a/models/dictionaryBuild.js +++ b/models/dictionaryBuild.js @@ -1,6 +1,6 @@ 'use strict'; module.exports = function (sequelize, DataTypes) { - var DictionaryBuild = sequelize.define('DictionaryBuild', { + const DictionaryBuild = sequelize.define('DictionaryBuild', { id: { type: DataTypes.STRING, primaryKey: true }, description: { type: DataTypes.STRING } }); diff --git a/models/dictionaryBuildData.js b/models/dictionaryBuildData.js index 2949994..f2735b5 100644 --- a/models/dictionaryBuildData.js +++ b/models/dictionaryBuildData.js @@ -1,6 +1,6 @@ 'use strict'; module.exports = function (sequelize, DataTypes) { - var DictionaryBuildData = sequelize.define('DictionaryBuildData', { + const DictionaryBuildData = sequelize.define('DictionaryBuildData', { position: { type: DataTypes.INTEGER, primaryKey: true }, type: { type: DataTypes.STRING}, data: { type: DataTypes.TEXT, allowNull: true } diff --git a/models/dictionaryTemplate.js b/models/dictionaryTemplate.js index 301b5cb..16dd760 100644 --- a/models/dictionaryTemplate.js +++ b/models/dictionaryTemplate.js @@ -1,6 +1,6 @@ 'use strict'; module.exports = function (sequelize, DataTypes) { - var DictionaryTemplate = sequelize.define('DictionaryTemplate', { + const DictionaryTemplate = sequelize.define('DictionaryTemplate', { id: { type: DataTypes.STRING, primaryKey: true }, latex: { type: DataTypes.TEXT, allowNull: false }, html: { type: DataTypes.TEXT, allowNull: false }, diff --git a/models/entry.js b/models/entry.js index 82c9b9b..2a78e13 100644 --- a/models/entry.js +++ b/models/entry.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = function (sequelize, DataTypes) { - var Entry = sequelize.define('Entry', { + const Entry = sequelize.define('Entry', { pubId: { type: DataTypes.INTEGER }, lemma: { type: DataTypes.STRING, allowNull: false }, ipa: { type: DataTypes.STRING }, diff --git a/models/entryLayout.js b/models/entryLayout.js index e3f8bb1..be3da9a 100644 --- a/models/entryLayout.js +++ b/models/entryLayout.js @@ -1,9 +1,9 @@ 'use strict'; -var format = require('string-format'); -var Promise = require('bluebird'); +const format = require('string-format'); +const Promise = require('bluebird'); module.exports = function (sequelize, DataTypes) { - var EntryLayout = sequelize.define('EntryLayout', { + const EntryLayout = sequelize.define('EntryLayout', { id: { type: DataTypes.STRING, primaryKey: true }, layout: { type: DataTypes.STRING, allowNull: false } }); @@ -27,19 +27,19 @@ module.exports = function (sequelize, DataTypes) { }; EntryLayout.prototype.getFormattedLayout = function(type, data) { - var self = this; + const self = this; return new Promise(function (resolve, reject) { self.getEntryTemplates().then(function(templates){ - var stuff = {}; + const stuff = {}; - for(var i = 0; i < templates.length; i++){ - var template = templates[i]; - var layoutTemplate = template.getDataValue('EntryLayoutTemplates'); - var typeTemplate = template.getDataValue(type); + for(let i = 0; i < templates.length; i++){ + const template = templates[i]; + const layoutTemplate = template.getDataValue('EntryLayoutTemplates'); + let typeTemplate = template.getDataValue(type); typeTemplate = typeTemplate.replace("{", "{{"); typeTemplate = typeTemplate.replace("}", "}}"); - var field = layoutTemplate.getDataValue('field'); + const field = layoutTemplate.getDataValue('field'); stuff[field] = typeTemplate.replace("#", "{" + field + "}"); if(field === "entry"){ @@ -53,7 +53,7 @@ module.exports = function (sequelize, DataTypes) { } - var layout = format(self.layout, stuff); + const layout = format(self.layout, stuff); //console.log(self.layout, layout, data, stuff['entry']); if(data !== undefined){ diff --git a/models/entryLayoutTemplates.js b/models/entryLayoutTemplates.js index d1c907b..eac3adc 100644 --- a/models/entryLayoutTemplates.js +++ b/models/entryLayoutTemplates.js @@ -1,6 +1,6 @@ 'use strict'; module.exports = function (sequelize, DataTypes) { - var EntryLayoutTemplates = sequelize.define('EntryLayoutTemplates', { + const EntryLayoutTemplates = sequelize.define('EntryLayoutTemplates', { position: { type: DataTypes.INTEGER, primaryKey: true, defaultValue: 0 }, field: { type: DataTypes.STRING, primaryKey: true } }); diff --git a/models/entryTemplate.js b/models/entryTemplate.js index c8fccc0..b8bb771 100644 --- a/models/entryTemplate.js +++ b/models/entryTemplate.js @@ -1,6 +1,6 @@ 'use strict'; module.exports = function (sequelize, DataTypes) { - var EntryTemplate = sequelize.define('EntryTemplate', { + const EntryTemplate = sequelize.define('EntryTemplate', { id: { type: DataTypes.STRING, primaryKey: true }, latex: { type: DataTypes.STRING, allowNull: false, defaultValue: "" }, html: { type: DataTypes.STRING, allowNull: false, defaultValue: "" } diff --git a/models/entryType.js b/models/entryType.js index b3a69b4..04b658a 100644 --- a/models/entryType.js +++ b/models/entryType.js @@ -1,8 +1,8 @@ 'use strict'; -var Promise = require('bluebird'); +const Promise = require('bluebird'); module.exports = function (sequelize, DataTypes) { - var EntryType = sequelize.define('EntryType', { + const EntryType = sequelize.define('EntryType', { id: { type: DataTypes.STRING, primaryKey: true }, layout: { type: DataTypes.STRING, allowNull: true }, argc: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0 }, @@ -33,11 +33,20 @@ module.exports = function (sequelize, DataTypes) { }; EntryType.prototype.getFormattedLayout = function(type){ - var self = this; + const self = this; return new Promise(function(resolve, reject){ self.getEntryLayout().then(function(layout){ // Todo: Insert extra layout templates + if(self.layout !== undefined && self.layout !== null){ + const regex = /{LAYOUTS\.(.*)}/; + let result; + while(result = self.layout.match(regex)){ + console.log(result); + self.layout = self.layout.replace(result[0], "{TEST}"); + } + } + layout.getFormattedLayout(type, self.layout).then(function(data){ resolve(data); }); diff --git a/models/entryTypeEntries.js b/models/entryTypeEntries.js index 12f5295..4f4acec 100644 --- a/models/entryTypeEntries.js +++ b/models/entryTypeEntries.js @@ -1,6 +1,6 @@ 'use strict'; module.exports = function (sequelize, DataTypes) { - var EntryTypeEntries = sequelize.define('EntryTypeEntries', { + const EntryTypeEntries = sequelize.define('EntryTypeEntries', { position: { type: DataTypes.INTEGER, primaryKey: true, defaultValue: 0 } }); diff --git a/models/entryTypeTemplates.js b/models/entryTypeTemplates.js index cba6e2f..8c4262d 100644 --- a/models/entryTypeTemplates.js +++ b/models/entryTypeTemplates.js @@ -1,6 +1,6 @@ 'use strict'; module.exports = function (sequelize, DataTypes) { - var EntryTypeTemplates = sequelize.define('EntryTypeTemplates', { + const EntryTypeTemplates = sequelize.define('EntryTypeTemplates', { position: { type: DataTypes.INTEGER, primaryKey: true, defaultValue: 0 }, field: { type: DataTypes.STRING, primaryKey: true } }); diff --git a/models/index.js b/models/index.js index 3b74ff5..59aaee3 100644 --- a/models/index.js +++ b/models/index.js @@ -1,17 +1,15 @@ "use strict"; -var fs = require("fs"); -var path = require("path"); -var Sequelize = require("sequelize"); -var env = process.env.NODE_ENV || "development"; -var vault = require('../vault'); - -if (process.env.DATABASE_URL) { - var sequelize = new Sequelize(process.env.DATABASE_URL,vault[env].ln_dictionary); -} else { - var sequelize = new Sequelize(vault[env].ln_dictionary.database, vault[env].ln_dictionary.username, vault[env].ln_dictionary.password, vault[env].ln_dictionary); -} -var db = {}; +const fs = require("fs"); +const path = require("path"); +const Sequelize = require("sequelize"); +const env = process.env.NODE_ENV || "development"; +const vault = require('../vault'); + + +const sequelize = new Sequelize(vault[env].ln_dictionary.database, vault[env].ln_dictionary.username, vault[env].ln_dictionary.password, vault[env].ln_dictionary); + +const db = {}; fs .readdirSync(__dirname) @@ -19,7 +17,7 @@ fs return (file.indexOf(".") !== 0) && (file !== "index.js"); }) .forEach(function(file) { - var model = sequelize.import(path.join(__dirname, file)); + const model = sequelize.import(path.join(__dirname, file)); db[model.name] = model; }); diff --git a/models/language.js b/models/language.js index 3dc5b95..bc35a93 100644 --- a/models/language.js +++ b/models/language.js @@ -1,6 +1,6 @@ 'use strict'; module.exports = function (sequelize, DataTypes) { - var Language = sequelize.define('Language', { + const Language = sequelize.define('Language', { isoCode: { type: DataTypes.STRING, allowNull: false, primaryKey: true }, isoName: { type: DataTypes.STRING, allowNull: false }, nativeName: { type: DataTypes.STRING, allowNull: false }, diff --git a/models/localizedEntryLayout.js b/models/localizedEntryLayout.js index afc8929..1808b6f 100644 --- a/models/localizedEntryLayout.js +++ b/models/localizedEntryLayout.js @@ -1,6 +1,6 @@ 'use strict'; module.exports = function (sequelize, DataTypes) { - var LocalizedEntryLayout = sequelize.define('LocalizedEntryLayout', { + const LocalizedEntryLayout = sequelize.define('LocalizedEntryLayout', { layout: { type: DataTypes.STRING, allowNull: false }, argc: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0 }, changeable: { type: DataTypes.STRING, allowNull: false, defaultValue: "" } diff --git a/models/localizedMetadata.js b/models/localizedMetadata.js index c751d46..a0e4625 100644 --- a/models/localizedMetadata.js +++ b/models/localizedMetadata.js @@ -1,6 +1,7 @@ 'use strict'; module.exports = function (sequelize, DataTypes) { - var LocalizedMetadata = sequelize.define('LocalizedMetadata', { + + const LocalizedMetadata = sequelize.define('LocalizedMetadata', { value: { type: DataTypes.TEXT, allowNull: false } }); diff --git a/models/localizedentry.js b/models/localizedentry.js index 3e17165..68b0cef 100644 --- a/models/localizedentry.js +++ b/models/localizedentry.js @@ -1,10 +1,11 @@ 'use strict'; -var format = require('string-format'); -var Promise = require('bluebird'); -var models = require('./index'); +const format = require('string-format'); +const Promise = require('bluebird'); +const models = require('./index'); module.exports = function (sequelize, DataTypes) { - var LocalizedEntry = sequelize.define('LocalizedEntry', { + + const LocalizedEntry = sequelize.define('LocalizedEntry', { odd: DataTypes.TEXT }); @@ -34,14 +35,14 @@ module.exports = function (sequelize, DataTypes) { }; LocalizedEntry.prototype.getFormattedlayout = function(type){ - var self = this; + const self = this; return new Promise(function (resolve, reject) { self.getEntry().then(function(entry){ entry.getSource().then(function(source){ entry.getEntryType().then(function(entryType) { entryType.getMetadata().then(function(metadata){ - var promises = []; - var localMetadata = {}; + const promises = []; + const localMetadata = {}; metadata.forEach(function(m){ promises.push(m.getLocalizedMetadata({where: {LanguageIsoCode: self.LanguageIsoCode}}).then(function(localizedMetadata){ localizedMetadata.forEach(function(l){ @@ -53,7 +54,7 @@ module.exports = function (sequelize, DataTypes) { Promise.all(promises).then(function(){ entryType.getFormattedLayout(type).then(function (formatString) { //console.log(formatString); - var formatData = { + const formatData = { lemma: entry.lemma, ipa: entry.ipa, source: source.name, diff --git a/models/metadata.js b/models/metadata.js index b84323e..bee106f 100644 --- a/models/metadata.js +++ b/models/metadata.js @@ -1,6 +1,6 @@ 'use strict'; module.exports = function (sequelize, DataTypes) { - var Metadata = sequelize.define('Metadata', { + const Metadata = sequelize.define('Metadata', { id: { type: DataTypes.STRING, primaryKey: true } }); diff --git a/models/partofspeech.js b/models/partofspeech.js index c6b87a8..5fd048a 100644 --- a/models/partofspeech.js +++ b/models/partofspeech.js @@ -1,6 +1,6 @@ 'use strict'; module.exports = function (sequelize, DataTypes) { - var PartOfSpeech = sequelize.define('PartOfSpeech', { + const PartOfSpeech = sequelize.define('PartOfSpeech', { type: { type: DataTypes.STRING, allowNull: false, primaryKey: true }, description: { type: DataTypes.STRING, allowNull: true } }, { diff --git a/models/source.js b/models/source.js index ad83143..59d0658 100644 --- a/models/source.js +++ b/models/source.js @@ -1,6 +1,6 @@ 'use strict'; module.exports = function (sequelize, DataTypes) { - var Source = sequelize.define('Source', { + const Source = sequelize.define('Source', { name: { type: DataTypes.STRING, unique: true }, description: DataTypes.STRING }); diff --git a/routes/apiV1.js b/routes/apiV1.js index 312f9b4..f14ef56 100644 --- a/routes/apiV1.js +++ b/routes/apiV1.js @@ -1,6 +1,6 @@ -var express = require('express'); -var router = express.Router(); +const express = require('express'); +const router = express.Router(); router.use('/dictionary/blocks', require('./v1/dictionary/blocks')); router.use('/dictionary/builds', require('./v1/dictionary/builds')); diff --git a/routes/dictionary.routes.v1.js b/routes/dictionary.routes.v1.js deleted file mode 100644 index 2c5d077..0000000 --- a/routes/dictionary.routes.v1.js +++ /dev/null @@ -1,92 +0,0 @@ -var express = require('express'); -var router = express.Router(); - -/* GET users listing. */ -router.get('/', function(req, res, next) { - res.send('Mobile App Database System V1'); -}); - -module.exports = router; - - -//We need a function which handles requests and send response -function handleRequest(request, response){ - console.log(request.url); - switch(request.url) { - - case "/dictionary/templates": - var htmlText = ""; - //for(var lc in dictionary.templates){ - htmlText += "

" + 'en' + "

"; - var lcKeys = Object.keys(dictionary.templates['en']).sort(); - console.log(lcKeys); - for(var i = 0; i < lcKeys.length; i++){ - var type = lcKeys[i]; - console.log(type); - htmlText += type + "
\n"; - htmlText += dictionary.templates['en'][type]; - } - //} - response.end(htmlText); - //response.end(JSON.stringify(dictionary.templates)); - break; - - case "/dictionary/languages": - response.end(JSON.stringify(dictionary.languages)); - break; - - case "/dictionary/metadata": - response.end(JSON.stringify(dictionary.metadata)); - break; - - case "/dictionary/entries": - response.writeHead(200, {"Content-Type": "application/json; charset=utf-8"}); - response.end(JSON.stringify(dictionary.entries), 'utf8'); - break; - - // Fetch dictLanguages - case "/eanaEltu/dictLanguages": - response.end(JSON.stringify(eanaEltu.dictLanguages)); - break; - - // Fetch dictLayout - case "/eanaEltu/dictLayout": - response.end(JSON.stringify(eanaEltu.dictLayout)); - break; - - // Fetch dictLoc - case "/eanaEltu/dictLoc": - response.end(JSON.stringify(eanaEltu.dictLoc)); - break; - - // Fetch dictMeta - case "/eanaEltu/dictMeta": - response.end(JSON.stringify(eanaEltu.dictMeta)); - break; - - // Fetch dictOrder - case "/eanaEltu/dictOrder": - response.end(JSON.stringify(eanaEltu.dictOrder)); - break; - - // Fetch dictWordLoc - case "/eanaEltu/dictWordLoc": - response.end(JSON.stringify(eanaEltu.dictWordLoc)); - break; - - // Fetch dictWordMeta - case "/eanaEltu/dictWordMeta": - response.end(JSON.stringify(eanaEltu.dictWordMeta)); - break; - - // Fetch dictWordTemplate - case "/eanaEltu/dictWordTemplate": - response.end(JSON.stringify(eanaEltu.dictWordTemplate)); - break; - - default: - response.end("This path doesn't exist: " + request.url); - } - -} - diff --git a/routes/index.js b/routes/index.js index ecca96a..6e84977 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,5 +1,5 @@ -var express = require('express'); -var router = express.Router(); +const express = require('express'); +const router = express.Router(); /* GET home page. */ router.get('/', function(req, res, next) { diff --git a/routes/users.js b/routes/users.js index 623e430..f15a20d 100644 --- a/routes/users.js +++ b/routes/users.js @@ -1,5 +1,5 @@ -var express = require('express'); -var router = express.Router(); +const express = require('express'); +const router = express.Router(); /* GET users listing. */ router.get('/', function(req, res, next) { diff --git a/routes/v1/dictionary/blocks.js b/routes/v1/dictionary/blocks.js index 0094f9a..7f384d5 100644 --- a/routes/v1/dictionary/blocks.js +++ b/routes/v1/dictionary/blocks.js @@ -1,7 +1,6 @@ -var express = require('express'); -var router = express.Router(); -var models = require('../../../models/index'); -var Promise = require('bluebird'); +const express = require('express'); +const router = express.Router(); +const models = require('../../../models/index'); /* GET languages listing. */ router.get('/', function(req, res, next) { diff --git a/routes/v1/dictionary/buildData.js b/routes/v1/dictionary/buildData.js index d4e70fe..3858bae 100644 --- a/routes/v1/dictionary/buildData.js +++ b/routes/v1/dictionary/buildData.js @@ -1,7 +1,7 @@ -var express = require('express'); -var router = express.Router(); -var models = require('../../../models/index'); -var Promise = require('bluebird'); +const express = require('express'); +const router = express.Router(); +const models = require('../../../models/index'); +const Promise = require('bluebird'); /* GET languages listing. */ router.get('/', function(req, res, next) { diff --git a/routes/v1/dictionary/builds.js b/routes/v1/dictionary/builds.js index 58cba0a..2eb6f29 100644 --- a/routes/v1/dictionary/builds.js +++ b/routes/v1/dictionary/builds.js @@ -1,7 +1,7 @@ -var express = require('express'); -var router = express.Router(); -var models = require('../../../models/index'); -var Promise = require('bluebird'); +const express = require('express'); +const router = express.Router(); +const models = require('../../../models/index'); +const Promise = require('bluebird'); /* GET languages listing. */ router.get('/', function(req, res, next) { diff --git a/routes/v1/dictionary/templates.js b/routes/v1/dictionary/templates.js index 3ea13d9..01c7daf 100644 --- a/routes/v1/dictionary/templates.js +++ b/routes/v1/dictionary/templates.js @@ -1,7 +1,7 @@ -var express = require('express'); -var router = express.Router(); -var models = require('../../../models/index'); -var Promise = require('bluebird'); +const express = require('express'); +const router = express.Router(); +const models = require('../../../models/index'); +const Promise = require('bluebird'); /* GET languages listing. */ router.get('/', function(req, res, next) { diff --git a/routes/v1/entries.js b/routes/v1/entries.js index ddcfe53..e025b65 100644 --- a/routes/v1/entries.js +++ b/routes/v1/entries.js @@ -1,7 +1,6 @@ -var express = require('express'); -var router = express.Router(); -var models = require('../../models/index'); -var Promise = require('bluebird'); +const express = require('express'); +const router = express.Router(); +const models = require('../../models/index'); /* GET languages listing. */ router.get('/', function(req, res, next) { diff --git a/routes/v1/entry/layoutTemplates.js b/routes/v1/entry/layoutTemplates.js index 30bd549..493dba1 100644 --- a/routes/v1/entry/layoutTemplates.js +++ b/routes/v1/entry/layoutTemplates.js @@ -1,7 +1,6 @@ -var express = require('express'); -var router = express.Router(); -var models = require('../../../models/index'); -var Promise = require('bluebird'); +const express = require('express'); +const router = express.Router(); +const models = require('../../../models/index'); /* GET languages listing. */ router.get('/', function(req, res, next) { diff --git a/routes/v1/entry/layouts.js b/routes/v1/entry/layouts.js index 4be2b64..1f93142 100644 --- a/routes/v1/entry/layouts.js +++ b/routes/v1/entry/layouts.js @@ -1,7 +1,7 @@ -var express = require('express'); -var router = express.Router(); -var models = require('../../../models/index'); -var Promise = require('bluebird'); +const express = require('express'); +const router = express.Router(); +const models = require('../../../models/index'); +const Promise = require('bluebird'); /* GET languages listing. */ router.get('/', function(req, res, next) { diff --git a/routes/v1/entry/templates.js b/routes/v1/entry/templates.js index 04722f4..d7fd33e 100644 --- a/routes/v1/entry/templates.js +++ b/routes/v1/entry/templates.js @@ -1,7 +1,6 @@ var express = require('express'); var router = express.Router(); var models = require('../../../models/index'); -var Promise = require('bluebird'); /* GET languages listing. */ router.get('/', function(req, res, next) { diff --git a/routes/v1/entry/typeEntries.js b/routes/v1/entry/typeEntries.js index 2ca3318..916a200 100644 --- a/routes/v1/entry/typeEntries.js +++ b/routes/v1/entry/typeEntries.js @@ -1,7 +1,7 @@ -var express = require('express'); -var router = express.Router(); -var models = require('../../../models/index'); -var Promise = require('bluebird'); +const express = require('express'); +const router = express.Router(); +const models = require('../../../models/index'); +const Promise = require('bluebird'); /* GET languages listing. */ router.get('/', function(req, res, next) { diff --git a/routes/v1/entry/typeTemplates.js b/routes/v1/entry/typeTemplates.js index ece897a..6d03a65 100644 --- a/routes/v1/entry/typeTemplates.js +++ b/routes/v1/entry/typeTemplates.js @@ -1,7 +1,6 @@ -var express = require('express'); -var router = express.Router(); -var models = require('../../../models/index'); -var Promise = require('bluebird'); +const express = require('express'); +const router = express.Router(); +const models = require('../../../models/index'); /* GET languages listing. */ router.get('/', function(req, res, next) { diff --git a/routes/v1/entry/types.js b/routes/v1/entry/types.js index 3cba43e..fac0502 100644 --- a/routes/v1/entry/types.js +++ b/routes/v1/entry/types.js @@ -1,7 +1,7 @@ -var express = require('express'); -var router = express.Router(); -var models = require('../../../models/index'); -var Promise = require('bluebird'); +const express = require('express'); +const router = express.Router(); +const models = require('../../../models/index'); +const Promise = require('bluebird'); /* GET languages listing. */ router.get('/', function(req, res, next) { diff --git a/routes/v1/languages.js b/routes/v1/languages.js index fb29e1e..72e4ec2 100644 --- a/routes/v1/languages.js +++ b/routes/v1/languages.js @@ -1,7 +1,6 @@ -var express = require('express'); -var router = express.Router(); -var models = require('../../models/index'); -var Promise = require('bluebird'); +const express = require('express'); +const router = express.Router(); +const models = require('../../models/index'); /* GET languages listing. */ router.get('/', function(req, res, next) { diff --git a/routes/v1/localized/entries.js b/routes/v1/localized/entries.js index bebf1be..82e2a86 100644 --- a/routes/v1/localized/entries.js +++ b/routes/v1/localized/entries.js @@ -1,11 +1,14 @@ -var express = require('express'); -var router = express.Router(); -var models = require('../../../models/index'); -var Promise = require('bluebird'); +const express = require('express'); +const router = express.Router(); +const models = require('../../../models/index'); /* GET languages listing. */ -router.get('/', function(req, res, next) { - models.LocalizedEntry.findAll().then(function (entries) { +router.get('/:lc', function(req, res, next) { + models.LocalizedEntry.findAll({ where: + { + LanguageIsoCode: req.params.lc + } + }).then(function (entries) { "use strict"; res.send(entries); }); @@ -29,21 +32,4 @@ router.get('/:lc/:entryId/:type', function(req, res, next){ }); }); -router.get('/:lc/:entryId/html', function(req, res, next){ - "use strict"; - models.LocalizedEntry.findOne({ where: - { - EntryId: req.params.entryId, - LanguageIsoCode: req.params.lc - } - }).then(function (entry) { - "use strict"; - entry.getHtml().then(function(html){ - res.send(html); - }); - - //res.send(entries); - }); -}); - module.exports = router; diff --git a/routes/v1/localized/entryLayouts.js b/routes/v1/localized/entryLayouts.js index e7ab908..bd8c519 100644 --- a/routes/v1/localized/entryLayouts.js +++ b/routes/v1/localized/entryLayouts.js @@ -1,7 +1,6 @@ -var express = require('express'); -var router = express.Router(); -var models = require('../../../models/index'); -var Promise = require('bluebird'); +const express = require('express'); +const router = express.Router(); +const models = require('../../../models/index'); /* GET languages listing. */ router.get('/', function(req, res, next) { diff --git a/routes/v1/localized/metadata.js b/routes/v1/localized/metadata.js index cbe0bde..8001faf 100644 --- a/routes/v1/localized/metadata.js +++ b/routes/v1/localized/metadata.js @@ -1,7 +1,6 @@ -var express = require('express'); -var router = express.Router(); -var models = require('../../../models/index'); -var Promise = require('bluebird'); +const express = require('express'); +const router = express.Router(); +const models = require('../../../models/index'); /* GET languages listing. */ router.get('/', function(req, res, next) { diff --git a/routes/v1/metadata.js b/routes/v1/metadata.js index 1ce4fdf..79d350d 100644 --- a/routes/v1/metadata.js +++ b/routes/v1/metadata.js @@ -1,7 +1,6 @@ -var express = require('express'); -var router = express.Router(); -var models = require('../../models/index'); -var Promise = require('bluebird'); +const express = require('express'); +const router = express.Router(); +const models = require('../../models/index'); /* GET languages listing. */ router.get('/', function(req, res, next) { diff --git a/routes/v1/partsOfSpeech.js b/routes/v1/partsOfSpeech.js index 428836d..9961d8d 100644 --- a/routes/v1/partsOfSpeech.js +++ b/routes/v1/partsOfSpeech.js @@ -1,7 +1,6 @@ -var express = require('express'); -var router = express.Router(); -var models = require('../../models/index'); -var Promise = require('bluebird'); +const express = require('express'); +const router = express.Router(); +const models = require('../../models/index'); /* GET languages listing. */ router.get('/', function(req, res, next) { diff --git a/routes/v1/sources.js b/routes/v1/sources.js index 5bd93b0..132f145 100644 --- a/routes/v1/sources.js +++ b/routes/v1/sources.js @@ -1,7 +1,6 @@ -var express = require('express'); -var router = express.Router(); -var models = require('../../models/index'); -var Promise = require('bluebird'); +const express = require('express'); +const router = express.Router(); +const models = require('../../models/index'); /* GET languages listing. */ router.get('/', function(req, res, next) {