Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
126 changes: 126 additions & 0 deletions package-lock.json

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

7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"license": "ISC",
"dependencies": {
"compression": "^1.7.4",
"connect-mongo": "^5.1.0",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"cron": "^3.1.6",
Expand All @@ -39,15 +40,21 @@
"passport": "^0.7.0",
"passport-github2": "^0.1.12",
"pm2": "^5.3.1",
"short-uuid": "^5.2.0",
"ulid": "^2.3.0",
"validator": "^13.11.0",
"winston": "^3.13.0",
"winston-daily-rotate-file": "^5.0.0",
"winston-loggly-bulk": "^3.3.0"
},
"devDependencies": {
"@faker-js/faker": "^8.4.1",
"jest": "^29.7.0",
"mongodb-memory-server": "^9.1.8",
"supertest": "^6.3.4",
"zx": "^8.0.1"
},
"volta": {
"node": "20.12.2"
}
}
46 changes: 46 additions & 0 deletions scripts/dev/data-generators/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const mongoose = require('mongoose');
const { faker } = require('@faker-js/faker');
const short = require('short-uuid');
const User = require('../../../src/domains/user/schema');


async function populateUsers() {
console.log('Populating users...');
for(let i = 0; i < 100; i++) {
const user = new User({
githubId: short.generate(),
nodeId: short.generate(),
displayName: faker.person.fullName(),
username: faker.internet.userName(),
profileUrl: faker.internet.url(),
avatarUrl: faker.image.avatar(),
apiUrl: faker.internet.url(),
company: faker.company.name(),
blog: faker.internet.url(),
location: faker.location.city(),
email: faker.internet.email(),

bio: faker.lorem.sentence(),
public_repos: faker.number.int({min: 0, max: 100}),
public_gists: faker.number.int({min: 0, max: 100}),
followers: faker.number.int({min: 0, max: 100}),
following: faker.number.int(),
created_at: faker.date.past(),
updated_at: faker.date.recent(),
isDemo: true,
isVerified: false
});

await user.save();
console.log(`User ${i} created`);
}

console.log('Data populated');
}

mongoose.connect('mongodb://localhost:27017/commitstreams').then(() => {
console.log('Connected to MongoDB');
populateUsers().then(() => {
mongoose.connection.close();
});
});
13 changes: 12 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@ function defineRoutes(expressApp) {

domainRoutes(router);

expressApp.use('/api/v1', router);
// Authentication Middleware
function isAuthenticated(req, res, next) {
if (req.isAuthenticated()) {
// Passport's built-in method
return next(); // User is authenticated, proceed
} else {
logger.warn('User is not authenticated');
return res.status(401).json({ message: 'Unauthorized' });
}
}

expressApp.use('/api/v1', isAuthenticated, router);
// health check
expressApp.get('/health', (req, res) => {
const healthCheck = {
Expand Down
Loading