Skip to content

Commit

Permalink
Merge pull request #43 from wednesday-solutions/feat/camelcased-models
Browse files Browse the repository at this point in the history
feat: camelcased mongo-models
  • Loading branch information
alichherawalla authored May 30, 2022
2 parents 772d9da + 5bb2d43 commit d3a7224
Show file tree
Hide file tree
Showing 15 changed files with 577 additions and 758 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ API_AUDIENCE=https://node-express-demo
REDIS_PORT=6379
REDIS_DOMAIN=localhost
MONGO_PORT=27017
MONGO_BASE_URI=localhost
MONGO_BASE_URI=localhost
MONGO_DB_NAME=ecommerce
3 changes: 2 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ NODE_ENV=test
REDIS_PORT=6379
REDIS_DOMAIN=localhost
MONGO_PORT=27017
MONGO_BASE_URI=localhost
MONGO_BASE_URI=localhost
MONGO_DB_NAME=ecommerce
2 changes: 1 addition & 1 deletion models/referencedOrders.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ const schema = new mongoose.Schema({
}
});

const ReferencedOrders = mongoose.model('referenced_orders', schema);
const ReferencedOrders = mongoose.model('referencedOrders', schema);

module.exports = { model: ReferencedOrders, ReferencedOrders, schema };
2 changes: 1 addition & 1 deletion models/storeProducts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ const schema = new mongoose.Schema({
}
});

const StoreProducts = mongoose.model('store_products', schema);
const StoreProducts = mongoose.model('storeProducts', schema);
module.exports = { model: StoreProducts, StoreProducts, schema };
2 changes: 1 addition & 1 deletion models/supplierProducts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ const schema = new mongoose.Schema({
}
});

const SupplierProducts = mongoose.model('supplier_products', schema);
const SupplierProducts = mongoose.model('supplierProducts', schema);
module.exports = { model: SupplierProducts, SupplierProducts, schema };
2 changes: 1 addition & 1 deletion models/unshardedOrders.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ const schema = new mongoose.Schema({
}
});

const UnshardedOrders = mongoose.model('unsharded_orders', schema);
const UnshardedOrders = mongoose.model('unshardedOrders', schema);

module.exports = { model: UnshardedOrders, UnshardedOrders, schema };
2 changes: 1 addition & 1 deletion models/unshardedReferencedOrders.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const schema = new mongoose.Schema({
});

const UnshardedReferencedOrders = mongoose.model(
'unsharded_referenced_orders',
'unshardedReferencedOrders',
schema
);

Expand Down
10 changes: 10 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"exec": "export ENVIRONMENT_NAME=local && yarn start",
"watch": ["server/*"],
"ignore": ["**/__tests__/**", "*.test.js"],
"events": {
"restart": "kill-port 9000",
"crash": "kill-port 9000 && npm run local"
},
"delay": "250"
}
29 changes: 9 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"start": "export ENVIRONMENT_NAME=local && nodemon --exec babel-node app.js | bunyan -o short",
"start:sharded": "export MONGO_PORT=60000 && yarn start",
"postinstall": "link-module-alias",
"preinstall": "command -v link-module-alias && link-module-alias clean || true",
"preinstall": "source /usr/local/opt/nvm/nvm.sh; nvm use; command -v link-module-alias && link-module-alias clean || true",
"format": "prettier-standard './**/**/*.js'",
"lint": "npm run lint:js",
"lint:eslint": "eslint --ignore-path .gitignore --ignore-pattern server/bin",
Expand Down Expand Up @@ -47,16 +47,15 @@
"body-parser": "^1.19.1",
"bull": "^4.8.1",
"bunyan": "^1.8.15",
"core-js": "^3.20.2",
"cors": "^2.8.5",
"dotenv": "^16.0.0",
"express": "^4.17.2",
"express-jwt": "^6.1.1",
"express-jwt-authz": "^2.4.1",
"express-rate-limit": "^6.3.0",
"express-validator": "^6.14.0",
"helmet": "^5.0.1",
"husky": "^7.0.4",
"ioredis": "^5.0.5",
"jwks-rsa": "^2.0.5",
"kill-port": "^1.6.1",
"lodash": "^4.17.21",
Expand All @@ -68,35 +67,25 @@
"opossum": "^6.3.0",
"pluralize": "^8.0.0",
"response-time": "^2.3.2",
"save": "^2.4.0",
"slack-notify": "^2.0.2",
"swagger-ui-express": "^4.3.0"
"swagger-ui-express": "^4.3.0",
"uuid": "^8.3.2"
},
"devDependencies": {
"@babel/cli": "^7.16.7",
"@babel/core": "^7.16.7",
"@babel/eslint-parser": "^7.5.4",
"@babel/eslint-parser": "^7.18.2",
"@babel/node": "^7.16.7",
"@babel/preset-env": "^7.16.7",
"@babel/preset-env": "^7.18.2",
"@faker-js/faker": "^6.0.0-alpha.5",
"@types/jest": "^27.4.1",
"babel-eslint": "^10.1.0",
"eslint": "^8.6.0",
"eslint-config-prettier": "^4.1.0",
"eslint-config-prettier-standard": "^3.0.1",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-node": "^10.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"git-commit-msg-linter": "^4.1.2",
"jest": "^27.4.7",
"jest-coverage-badges": "^1.1.2",
"link-module-alias": "^1.2.0",
"mockingoose": "^2.15.2",
"pre-commit": "1.2.2",
"prettier": "^2.5.1",
"pre-commit": "^1.2.2",
"prettier": "^2.6.2",
"prettier-standard": "^16.4.1",
"supertest": "^6.2.2"
},
Expand Down
2 changes: 1 addition & 1 deletion server/api/referencedOrders/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('fetchAllReferencedOrders tests', () => {
let mockingoose;

beforeAll(() => {
MODEL_NAME = 'referenced_orders';
MODEL_NAME = 'referencedOrders';
ENDPOINT = `/${kebabCase(MODEL_NAME)}`;
});

Expand Down
2 changes: 1 addition & 1 deletion server/api/unshardedReferencedOrders/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('fetchAllUnshardedReferencedOrders tests', () => {
let mockingoose;

beforeAll(() => {
MODEL_NAME = 'unsharded_referenced_orders';
MODEL_NAME = 'unshardedReferencedOrders';
ENDPOINT = `/${kebabCase(MODEL_NAME)}`;
});

Expand Down
5 changes: 0 additions & 5 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import { isTestEnv } from 'utils';
import { initQueues } from 'utils/queue';
import injectRequestId from 'middlewares/injectRequestId';

/**
* Connect to database
*/
// let db = mongoConnector();

/**
* Create express server
*/
Expand Down
4 changes: 3 additions & 1 deletion server/middlewares/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export const mongoConnector = () => {
} else {
mongoose.connect(getMongoUri());
db = mongoose.connection;
db.on('error', err => log.error('error'));
db.on('error', err => {
log.error('error', err);
});
db.once('open', () =>
log.info(
'mongo connection successfully connected to ',
Expand Down
7 changes: 6 additions & 1 deletion server/utils/mongoConstants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
function getMongoOptions() {
return '?readPreference=secondary';
}
function getMongoUri() {
return `mongodb://${process.env.MONGO_BASE_URI}:${process.env.MONGO_PORT}/ecommerce?readPreference=secondary`;
return `mongodb://${process.env.MONGO_BASE_URI}:${process.env.MONGO_PORT}/${
process.env.MONGO_DB_NAME
}${getMongoOptions()}`;
}
module.exports = { getMongoUri };
Loading

0 comments on commit d3a7224

Please sign in to comment.