This file contains hidden or 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
const nconf =require('nconf'); | |
const joinUrl = require('url-join'); | |
const { getRequest } = require('../utils/httpClient'); | |
const usersAPIUrl = nconf.get('url.usersAPI'); | |
const getUsers = ({page = 1}) => getRequest({ | |
url: joinUrl(usersAPIUrl, 'users', `?page=${page}`) | |
}) |
This file contains hidden or 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
const { getUsers } = require('../adaptors/userAdaptor'); | |
const getUsersCtrl = async (req, res) => { | |
try { | |
const { page } = req.query; | |
const users = await getUsers({ page }); | |
res.send(users); | |
} | |
catch (err) { | |
throw err; |
This file contains hidden or 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
const { getUsersCtrl } = require('../controllers/userController') | |
module.exports = async function (fastify) { | |
fastify.get('/users', getUsersCtrl) | |
} |
This file contains hidden or 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
const mongoose = require('mongoose'); | |
const connectMongo = (mongoURI) => { | |
mongoose.connect(mongoURI, { useNewUrlParser: true }); | |
mongoose.connection.on('error', (err) => { | |
console.log(err); | |
process.exit(); | |
}); | |
}; |
This file contains hidden or 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
const nconf = require('nconf'); | |
const server = require('./server') | |
const { connectMongo } = require('./api/db/db') | |
const { loadSettings } = require('./config/configurationAdaptor') | |
const appSettingsPath = process.env.APP_SETTINGS_FILE_PATH; | |
loadSettings({ appSettingsPath }) | |
.then(() => { | |
const mongoURI = nconf.get('db.mongodb.uri'); |
This file contains hidden or 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
const bcrypt = require('bcrypt-nodejs'); | |
const mongoose = require('mongoose'); | |
const userSchema = new mongoose.Schema({ | |
email: { | |
type: String, | |
required: true, | |
unique: true, | |
}, | |
password: String, |
This file contains hidden or 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
const nconf = require('nconf'); | |
const User = require('../models/User'); | |
const { SignUpResponse } = require('../models/Auth'); | |
const { INVALID_PASSWORD, USER_DOESNT_EXISTS, USER_EXISTS } = require('../models/Errors'); | |
const postSignup = async (req, res) => { | |
const { email, password } = req.body; | |
try { | |
const existingUser = await User.findOne({ email: req.body.email }); |
This file contains hidden or 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
const nconf = require('nconf'); | |
const userPasswordRegex = nconf.get('userPasswordRegex'); | |
const validatePostLogin = { | |
schema: { | |
body: { | |
type: 'object', | |
properties: { | |
email: { type: 'string', format: 'email' }, |
This file contains hidden or 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
const { validatePostLogin, validatePostSignup } = require('../validations/auth'); | |
const { postLogin, postSignup } = require('../controllers/authController'); | |
module.exports = async (fastify) => { | |
fastify.post('/auth/login', validatePostLogin, postLogin); | |
fastify.post('/auth/signup', validatePostSignup, postSignup); | |
}; |
This file contains hidden or 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
FROM node:10-alpine | |
WORKDIR /usr/src/app | |
COPY package*.json ./ | |
RUN npm install | |
COPY . . | |
ENV APP_SETTINGS_FILE_PATH '/usr/src/app/config/appSettings.json' | |
EXPOSE 9000 | |
CMD ["node", "app.js"] |