Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Tracey thomas practice #7

Draft
wants to merge 9 commits into
base: intern-practice
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "dev",
"problemMatcher": [],
"label": "npm: dev",
"detail": "nodemon server/app",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
14,348 changes: 14,185 additions & 163 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"description": "A natural language string parser",
"main": "server/app.js",
"scripts": {
"start": "node server/app.js",
"test": "echo \"Error: no test specified\" && exit 1"
"start": "node server/app",
"dev": "nodemon server/app",
"test": "jest --watchAll"
},
"engines": {
"node": "8.12.0"
Expand All @@ -15,5 +16,11 @@
"dependencies": {
"express": "^4.16.4",
"moment": "^2.22.2"
},
"devDependencies": {
"axios": "^0.21.1",
"jest": "^26.6.3",
"node-fetch": "^2.6.1",
"nodemon": "^2.0.7"
}
}
33 changes: 33 additions & 0 deletions server/DAO/DatesDAO.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { Dates } = require('../models/Identifier')

class DatesDAO {


getAllDates = () => Dates

getDate = (name) => {
//RETURN SINGLE VALUE
// const formattedName = name.toLowerCase();
// for(const date of Dates){
// if(date.names.includes(formattedName)){
// return [{value: date.value, type: "date"}]
// }
// }
// return []

//RETURN MULTIPLE VALUES
const formatDate = date => {return {value: date.value, type: "date"}}
const matchingDates = Dates.filter(date => {
const formattedName = name.toLowerCase()
return date.names.includes(formattedName)
})
if(!matchingDates) {
return []
}
return matchingDates.map(formatDate)


}

}
module.exports = DatesDAO
30 changes: 30 additions & 0 deletions server/DAO/MealtimeDAO.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const {MealTimes} = require('../models/Identifier')

class MealtimeDAO {
getAllMealtimes = () => MealTimes

getMealtime = (type) => {
//RETURN SINGLE VALUE
// const formattedType = type.toLowerCase();
// for(const mealTime of MealTimes){
// if(mealTime.names.includes(formattedType)){
// return [{value: mealTime.value, type: "mealtime"}]
// }
// }
// return []
// }

//RETURN MULTIPLE VALUES
const formatMealTime = mealTime => { return {value: mealTime.value, type: "mealtime"}}
const matchingMealTimes = MealTimes.filter(mealTime => {
const formattedType = type.toLowerCase();
return mealTime.names.includes(formattedType);
})
if (!matchingMealTimes) {
return []
}
return matchingMealTimes.map(formatMealTime);
}
}

module.exports = MealtimeDAO
30 changes: 30 additions & 0 deletions server/DAO/StopwordDAO.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const stopWordList = require('../models/StopWord')

class StopwordDAO {


getAllStopwords = () => stopWordList


getStopword = (word) => {
//RETURN SINGLE VALUE
// const formattedWord = word.toLowerCase()
// for(const word of stopWordList){
// if(word === formattedWord){
// return [{value: word, type: "stopword" }]
// }
// }
// return []
//RETURN MULTIPLE VALUES{"
const formatStopword = stopWord => {return {value: stopWord, type: "stopword"}}
const matchingStopwords = stopWordList.filter(stopword => {
const formattedWord = word.toLowerCase()
return stopword === formattedWord
})
if(!matchingStopwords) {
return []
}
return matchingStopwords.map(formatStopword)
}
}
module.exports = StopwordDAO
13 changes: 13 additions & 0 deletions server/DAO/__fixtures__/dates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const moment = require('moment');

module.exports = [
{
value: moment().format("L"),
type: "date"
},

{
value: moment().add(1, 'day').format("L"),
type: "date"
}
]
traceythomasww marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 18 additions & 0 deletions server/DAO/__tests__/DatesDAO.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const DateDAOClass = require('../DatesDAO')
const date = new DateDAOClass()
const dateFixtures = require('../__fixtures__/dates')
const { Dates } = require('../../models/Identifier')


describe('Data access getAllDates function test', () => {
it('should return all dates array', () => {
const dates = date.getAllDates()
expect(dates).toEqual(Dates)
})
})

describe('Data access getDate function test', () => {
it('should return all matching dates given named param', () => {
expect(date.getDate('currently')).toEqual(dateFixtures)
})
})
17 changes: 17 additions & 0 deletions server/DAO/__tests__/MealtimeDAO.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const MealtimeDAOClass = require('../MealtimeDAO')
const meal = new MealtimeDAOClass()
const { MealTimes } = require('../../models/Identifier')

describe('Data access getAllMealtimes function test', () => {
it('should return all mealtimes array', () => {
const mealtimes = meal.getAllMealtimes()
expect(mealtimes).toEqual(MealTimes)
})
})

describe('Data access getMealtime function test', () => {
it('should return all mealtimes matching given param', () => {
const mealtimesArr = [{value: "morning", type: "mealtime"}, {value: "anytime", type: "mealtime"}]
traceythomasww marked this conversation as resolved.
Show resolved Hide resolved
expect(meal.getMealtime("breakfast")).toEqual(mealtimesArr)
})
})
19 changes: 19 additions & 0 deletions server/DAO/__tests__/StopwordDAO.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const StopwordDAOClass = require('../StopwordDAO')
const stopWordList = require('../../models/StopWord')
const stopword = new StopwordDAOClass()


describe('Data access getAllStopwords function test', () => {
it('should return all stopwords array', () => {
const stopwords = stopword.getAllStopwords()
expect(stopwords).toEqual(stopWordList)
})
})

describe('Data access getStopword function test', () => {
it('should return all stopwords matching given param ', () => {
const stopwordsArr = [{value: 'on', type: 'stopword'}, {value: 'on', type: 'stopword'}]
expect(stopword.getStopword('on')).toEqual(stopwordsArr)
})

})
20 changes: 18 additions & 2 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
const express = require('express');

const app = express();
const PORT = process.env.PORT || 3000;

//import routers
const mealtimesRouter = require('./routes/mealtimeRoutes')
const datesRouter = require('./routes/datesRoutes')
const stopwordsRouter = require('./routes/stopwordRoutes')
const postQueryRouter = require('./routes/PostQueryAnalysisRoute')

//use routers middleware
app.use('/mealtimes', mealtimesRouter)
app.use('/dates', datesRouter)
app.use('/stopwords', stopwordsRouter)
app.use('/', postQueryRouter)





//TODO: Add an express router
app.listen(PORT, 'localhost')
31 changes: 31 additions & 0 deletions server/controllers/__fixtures__/dates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const moment = require('moment')

module.exports = [
{
"status": "success",
"data": [
{
"value": moment().format("L"),
"names": [
"today",
"now",
"currently"
]
},
{
"value": moment().add(-1, 'day').format("L"),
"names": [
"yesterday"
]
},
{
"value": moment().add(1, 'day').format("L"),
"names": [
"tomorrow",
"currently"
]
}
]
}

]
39 changes: 39 additions & 0 deletions server/controllers/__fixtures__/mealtimes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = [
{
"status": "success",
"data": [
{
"value": "morning",
"names": [
"morning",
"breakfast",
"brunch"
]
},
{
"value": "midday",
"names": [
"midday",
"mid day",
"lunch"
]
},
{
"value": "evening",
"names": [
"evening",
"dinner",
"supper"
]
},
{
"value": "anytime",
"names": [
"anytime",
"snack",
"breakfast"
]
}
]
}
]
57 changes: 57 additions & 0 deletions server/controllers/__fixtures__/postQuery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module.exports = [
{
"status": "success",
"data": [
{
"matchedWord": "This",
"type": "stopword",
"value": "this"
},
{
"matchedWord": "is",
"type": "stopword",
"value": "is"
},
{
"matchedWord": "it",
"type": "stopword",
"value": "it"
},
{
"matchedWord": "i",
"type": "stopword",
"value": "i"
},
{
"matchedWord": "am",
"type": "stopword",
"value": "am"
},
{
"matchedWord": "not",
"type": "stopword",
"value": "not"
},
{
"matchedWord": "on",
"type": "stopword",
"value": "on"
},
{
"matchedWord": "on",
"type": "stopword",
"value": "on"
},
{
"matchedWord": "lunch",
"type": "mealtime",
"value": "midday"
},
{
"matchedWord": "today",
"type": "date",
"value": "05/15/2021"
}
]
}
]
Loading