generated from CodeForBaltimore/ProjectTemplate
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #434 from nmarklund10/nmarklund10/431-implement-ge…
…t-all-users-v2 Nmarklund10/431 implement get all users v2
- Loading branch information
Showing
10 changed files
with
289 additions
and
91 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,34 +1,35 @@ | ||
require('dotenv').config(); | ||
const fs = require('fs'); | ||
const rdsCa = fs.readFileSync('./rds-combined-ca-bundle.pem'); | ||
require('dotenv').config() | ||
const tls = require('tls') | ||
const fs = require('fs') | ||
const rdsCa = fs.readFileSync('./rds-combined-ca-bundle.pem') | ||
|
||
module.exports = { | ||
development: { | ||
database: process.env.DATABASE_NAME, | ||
username: process.env.DATABASE_USERNAME, | ||
password: process.env.DATABASE_PASSWORD, | ||
port: process.env.DATABASE_PORT, | ||
host: process.env.DATABASE_HOST, | ||
dialect: 'postgres', | ||
}, | ||
production: { | ||
database: process.env.DATABASE_NAME, | ||
username: process.env.DATABASE_USERNAME, | ||
password: process.env.DATABASE_PASSWORD, | ||
port: process.env.DATABASE_PORT, | ||
host: process.env.DATABASE_HOST, | ||
dialect: 'postgres', | ||
dialectOptions: { | ||
ssl: { | ||
rejectUnauthorized: true, | ||
ca: [rdsCa], | ||
checkServerIdentity: (host, cert) => { | ||
const error = tls.checkServerIdentity(host, cert); | ||
if (error && !cert.subject.CN.endsWith('.rds.amazonaws.com')) { | ||
return error; | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
}; | ||
development: { | ||
database: process.env.DATABASE_NAME, | ||
username: process.env.DATABASE_USERNAME, | ||
password: process.env.DATABASE_PASSWORD, | ||
port: process.env.DATABASE_PORT, | ||
host: process.env.DATABASE_HOST, | ||
dialect: 'postgres', | ||
}, | ||
production: { | ||
database: process.env.DATABASE_NAME, | ||
username: process.env.DATABASE_USERNAME, | ||
password: process.env.DATABASE_PASSWORD, | ||
port: process.env.DATABASE_PORT, | ||
host: process.env.DATABASE_HOST, | ||
dialect: 'postgres', | ||
dialectOptions: { | ||
ssl: { | ||
rejectUnauthorized: true, | ||
ca: [rdsCa], | ||
checkServerIdentity: (host, cert) => { | ||
const error = tls.checkServerIdentity(host, cert) | ||
if (error && !cert.subject.CN.endsWith('.rds.amazonaws.com')) { | ||
return error | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
} |
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 |
---|---|---|
@@ -1,12 +1,18 @@ | ||
[ | ||
{ | ||
"email": "[email protected]", | ||
"displayName": "Homer Simpson", | ||
"password": "donuts", | ||
"roles": ["admin"] | ||
"roles": [ | ||
"admin" | ||
] | ||
}, | ||
{ | ||
"email": "[email protected]", | ||
"displayName": "Test User", | ||
"password": "test", | ||
"roles": ["user"] | ||
"roles": [ | ||
"user" | ||
] | ||
} | ||
] |
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 |
---|---|---|
@@ -1,48 +1,48 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('Users', { | ||
id: { | ||
type: Sequelize.UUID, | ||
primaryKey: true, | ||
allowNull: false, | ||
autoIncrement: false, | ||
}, | ||
email: { | ||
allowNull: false, | ||
unique: true, | ||
type: Sequelize.STRING | ||
}, | ||
password: { | ||
allowNull: false, | ||
type: Sequelize.STRING | ||
}, | ||
salt: { | ||
type: Sequelize.STRING | ||
}, | ||
token: { | ||
type: Sequelize.STRING | ||
}, | ||
displayName: { | ||
type: Sequelize.STRING | ||
}, | ||
phone: { | ||
type: Sequelize.STRING | ||
}, | ||
attributes: { | ||
type: Sequelize.JSON, | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: queryInterface => { | ||
return queryInterface.dropTable('Users'); | ||
} | ||
}; | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('Users', { | ||
id: { | ||
type: Sequelize.UUID, | ||
primaryKey: true, | ||
allowNull: false, | ||
autoIncrement: false, | ||
}, | ||
email: { | ||
allowNull: false, | ||
unique: true, | ||
type: Sequelize.STRING | ||
}, | ||
password: { | ||
allowNull: false, | ||
type: Sequelize.STRING | ||
}, | ||
salt: { | ||
type: Sequelize.STRING | ||
}, | ||
token: { | ||
type: Sequelize.STRING | ||
}, | ||
displayName: { | ||
type: Sequelize.STRING | ||
}, | ||
phone: { | ||
type: Sequelize.STRING | ||
}, | ||
attributes: { | ||
type: Sequelize.JSON, | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}) | ||
}, | ||
down: queryInterface => { | ||
return queryInterface.dropTable('Users') | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import health from './health' | ||
import security from './security' | ||
import users from './users' | ||
// Exports object of routes we import above. Add to this if you're adding new routes. | ||
|
||
const routeExports = { | ||
health, | ||
security | ||
security, | ||
users | ||
} | ||
|
||
module.exports = routeExports |
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
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 @@ | ||
import { Router } from 'express' | ||
import { authMiddleware } from '../../utils/v2' | ||
|
||
const router = new Router() | ||
|
||
|
||
router.get('/', authMiddleware, async (req, res) => { | ||
let response | ||
try { | ||
const users = await req.context.models.User.findAll({ | ||
attributes: ['email', 'displayName'] | ||
}) | ||
|
||
return res.status(200).json(users) | ||
} catch (e) { | ||
console.error(e) | ||
response.setCode(500) | ||
} | ||
|
||
return res.status(response.getCode()).json(response.getMessage()) | ||
}) | ||
|
||
export default router |
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
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
Oops, something went wrong.