Skip to content

Commit

Permalink
file structure set up
Browse files Browse the repository at this point in the history
  • Loading branch information
chelcie de almeida authored and chelcie de almeida committed Jun 15, 2021
1 parent b245ba4 commit 35c2c22
Show file tree
Hide file tree
Showing 13 changed files with 731 additions and 0 deletions.
Empty file.
Empty file added controllers/user-controller.js
Empty file.
Empty file added models/Thought.js
Empty file.
Empty file added models/User.js
Empty file.
Empty file added models/index.js
Empty file.
587 changes: 587 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions package.json
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 added routes/api/index.js
Empty file.
Empty file added routes/api/thought-routes.js
Empty file.
Empty file added routes/api/user-routes.js
Empty file.
Empty file added routes/index.js
Empty file.
22 changes: 22 additions & 0 deletions server.js
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}`));
99 changes: 99 additions & 0 deletions utils/dateFormat.js
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;
};

0 comments on commit 35c2c22

Please sign in to comment.