Skip to content
This repository was archived by the owner on Mar 9, 2021. It is now read-only.

Commit 3363429

Browse files
committed
Made changes to base user model and documented necessary parts of code
1 parent 922b008 commit 3363429

File tree

20 files changed

+269
-258
lines changed

20 files changed

+269
-258
lines changed

.env.example

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
# Env modes
2+
PRODUCTION=
3+
TEST=
4+
15
# Database credentials
26
DB_USER=root
37
DB_PASSWORD=null
48
DB_HOST=localhost
59
DB_PORT=5432
610
DB_NAME=coderplex-org
11+
712
# JWT secret
8-
JWT_SECRET=jwt-secret
13+
JWT_SECRET=
14+
915
# Github OAuth
1016
GITHUB_CLIENT_ID=
1117
GITHUB_CLIENT_SECRET=

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vscode/*
2+
bin/*

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
"extends": "standard"
2+
extends: "standard"
33
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"makemigrations": "sequelize migration:create",
1111
"migrate": "sequelize db:migrate",
1212
"build": "mkdir dist && babel src -s -d dist",
13-
"lint": "eslint"
13+
"lint": "eslint --fix --ext js src"
1414
},
1515
"dependencies": {
1616
"apollo-server": "^2.0.0",
@@ -21,6 +21,7 @@
2121
"dataloader": "^1.4.0",
2222
"dotenv": "^6.0.0",
2323
"express": "^4.17.1",
24+
"express-session": "^1.17.0",
2425
"graphql": "^14.5.8",
2526
"graphql-relay": "^0.6.0",
2627
"graphql-resolvers": "^0.3.3",

src/index.js

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ app.use(cors())
1919

2020
app.use(morgan('dev'))
2121

22+
// This adds handlers for routes related to auth
2223
addAuthRoutes(app)
2324

2425
const getLoggedInUser = async req => {
@@ -80,39 +81,21 @@ server.applyMiddleware({ app, path: '/graphql' })
8081
const httpServer = http.createServer(app)
8182
server.installSubscriptionHandlers(httpServer)
8283

83-
const isTest = !!process.env.TEST_DATABASE
84-
const isProduction = !!process.env.DATABASE_URL
84+
const isDevelopment = !process.env.PRODUCTION
85+
const isTest = !!process.env.TEST
8586
const port = process.env.PORT || 8000
8687

87-
sequelize.sync({ force: isTest || isProduction }).then(async () => {
88-
if (isTest || isProduction) {
89-
createUsersWithMessages(new Date())
88+
sequelize.sync({ force: isDevelopment || isTest }).then(async () => {
89+
if (isTest) {
90+
createTestData()
9091
}
9192

9293
httpServer.listen({ port }, () => {
9394
console.log(`Apollo Server on http://localhost:${port}/graphql`)
95+
console.log({ isDevelopment, isTest })
9496
})
9597
})
9698

97-
const createUsersWithMessages = async date => {
98-
models.User.create(
99-
{
100-
email: 'hello@robin.com',
101-
password: 'rwieruch',
102-
firstName: 'rev',
103-
lastName: 'rich',
104-
}
105-
).then(async _user => {
106-
const user = (await models.User.findByLogin('hello@robin.com'))
107-
models.SocialProfile.create(
108-
{
109-
facebook: 'facebook.com/krushiraj',
110-
twitter: 'twitter.com/krushiraj123',
111-
userId: user.id
112-
},
113-
{
114-
include: [models.User]
115-
}
116-
)
117-
}).catch(console.error)
99+
const createTestData = async () => {
100+
// Use this function in future to seed the test data
118101
}

src/loaders/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import * as user from './user';
1+
import * as user from './user'
22

3-
export default { user };
3+
export default { user }

src/loaders/user.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ export const batchUsers = async (keys, models) => {
22
const users = await models.User.findAll({
33
where: {
44
id: {
5-
$in: keys,
6-
},
7-
},
8-
});
5+
$in: keys
6+
}
7+
}
8+
})
99

10-
return keys.map(key => users.find(user => user.id === key));
11-
};
10+
return keys.map(key => users.find(user => user.id === key))
11+
}

src/models/event-profile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const EventProfile = (sequelize, DataTypes) => {
44
const EventProfile = sequelize.define(
55
'event_profile',
66
{
7-
id: id(DataTypes)
7+
id: id(DataTypes.UUID)
88
}
99
)
1010

src/models/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import Sequelize from 'sequelize'
22
import { development } from '../config/config'
3-
//import all models here
3+
// import all models here
44
import user from './user'
55
import socialProfile from './social-profile'
66
import eventProfile from './event-profile'
77

88
let sequelize
99
if (process.env.DATABASE_URL) {
1010
sequelize = new Sequelize(process.env.DATABASE_URL, {
11-
dialect: 'postgres',
11+
dialect: 'postgres'
1212
})
1313
} else {
1414
sequelize = new Sequelize(
1515
development.database,
1616
development.username,
1717
development.password,
1818
{
19-
dialect: 'postgres',
20-
},
19+
dialect: 'postgres'
20+
}
2121
)
2222
}
2323

src/models/social-profile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { id } from './utils'
22

33
const socialProfile = (sequelize, DataTypes) => {
4-
const SocialProfile = sequelize.define("social_profile", {
5-
id: id(DataTypes),
4+
const SocialProfile = sequelize.define('social_profile', {
5+
id: id(DataTypes.UUID),
66
facebook: {
77
type: DataTypes.STRING,
88
allowNull: true
@@ -22,4 +22,4 @@ const socialProfile = (sequelize, DataTypes) => {
2222
return SocialProfile
2323
}
2424

25-
export default socialProfile
25+
export default socialProfile

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy