-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
chelcie de almeida
authored and
chelcie de almeida
committed
Jun 15, 2021
1 parent
b245ba4
commit 35c2c22
Showing
13 changed files
with
731 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "social-network-api", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "server.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/ChelcieDeAlmeida/social-network-api.git" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/ChelcieDeAlmeida/social-network-api/issues" | ||
}, | ||
"homepage": "https://github.com/ChelcieDeAlmeida/social-network-api#readme", | ||
"dependencies": { | ||
"express": "^4.17.1", | ||
"mongoose": "^5.12.13" | ||
} | ||
} |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const express = require('express'); | ||
const mongoose = require('mongoose'); | ||
|
||
const app = express(); | ||
const PORT = process.env.PORT || 3001; | ||
|
||
app.use(express.json()); | ||
app.use(express.urlencoded({ extended: true })); | ||
app.use(express.static('public')); | ||
|
||
// app.use(require('./routes')); | ||
|
||
mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost/social', { | ||
useFindAndModify: false, | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true | ||
}); | ||
|
||
// Use this to log mongo queries being executed! | ||
mongoose.set('debug', true); | ||
|
||
app.listen(PORT, () => console.log(`🌍 Connected on localhost:${PORT}`)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
const addDateSuffix = date => { | ||
let dateStr = date.toString(); | ||
|
||
// get last char of date string | ||
const lastChar = dateStr.charAt(dateStr.length - 1); | ||
|
||
if (lastChar === '1' && dateStr !== '11') { | ||
dateStr = `${dateStr}st`; | ||
} else if (lastChar === '2' && dateStr !== '12') { | ||
dateStr = `${dateStr}nd`; | ||
} else if (lastChar === '3' && dateStr !== '13') { | ||
dateStr = `${dateStr}rd`; | ||
} else { | ||
dateStr = `${dateStr}th`; | ||
} | ||
|
||
return dateStr; | ||
}; | ||
|
||
// function to format a timestamp, accepts the timestamp and an `options` object as optional parameters | ||
module.exports = ( | ||
timestamp, | ||
{ monthLength = 'short', dateSuffix = true } = {} | ||
) => { | ||
let months; | ||
|
||
if (monthLength === 'short') { | ||
months = { | ||
0: 'Jan', | ||
1: 'Feb', | ||
2: 'Mar', | ||
3: 'Apr', | ||
4: 'May', | ||
5: 'Jun', | ||
6: 'Jul', | ||
7: 'Aug', | ||
8: 'Sep', | ||
9: 'Oct', | ||
10: 'Nov', | ||
11: 'Dec' | ||
}; | ||
} else { | ||
months = { | ||
0: 'January', | ||
1: 'February', | ||
2: 'March', | ||
3: 'April', | ||
4: 'May', | ||
5: 'June', | ||
6: 'July', | ||
7: 'August', | ||
8: 'September', | ||
9: 'October', | ||
10: 'November', | ||
11: 'December' | ||
}; | ||
} | ||
|
||
const dateObj = new Date(timestamp); | ||
const formattedMonth = months[dateObj.getMonth()]; | ||
|
||
let dayOfMonth; | ||
|
||
if (dateSuffix) { | ||
dayOfMonth = addDateSuffix(dateObj.getDate()); | ||
} else { | ||
dayOfMonth = dateObj.getDate(); | ||
} | ||
|
||
const year = dateObj.getFullYear(); | ||
|
||
let hour; | ||
// check for 24-hr time | ||
if (dateObj.getHours > 12) { | ||
hour = Math.floor(dateObj.getHours() / 2); | ||
} else { | ||
hour = dateObj.getHours(); | ||
} | ||
// if hour is 0 (12:00am), change it to 12 | ||
if (hour === 0) { | ||
hour = 12; | ||
} | ||
|
||
const minutes = dateObj.getMinutes(); | ||
|
||
// set `am` or `pm` | ||
let periodOfDay; | ||
|
||
if (dateObj.getHours() >= 12) { | ||
periodOfDay = 'pm'; | ||
} else { | ||
periodOfDay = 'am'; | ||
} | ||
|
||
const formattedTimeStamp = `${formattedMonth} ${dayOfMonth}, ${year} at ${hour}:${minutes} ${periodOfDay}`; | ||
|
||
return formattedTimeStamp; | ||
}; | ||
|