Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Switch to using es6 modules imports/exports
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilome committed Sep 29, 2018
1 parent a60ee54 commit 3d41a93
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 22 deletions.
8 changes: 4 additions & 4 deletions server/app.js
@@ -1,6 +1,6 @@
const express = require('express');
const bodyParser = require('body-parser');
const recipeRouter = require('./routes/recipeRouter');
import express from 'express';
import bodyParser from 'body-parser';
import recipeRouter from './routes/recipeRouter';

const app = express();

Expand All @@ -14,4 +14,4 @@ app.use('/api/v1/', recipeRouter);
// Setup Server Port
app.listen(3000);

module.exports = app;
export default app;
4 changes: 2 additions & 2 deletions server/controllers/Recipes.js
@@ -1,4 +1,4 @@
const pool = require('../db/config');
import pool from '../db/config';

class RecipeController {
static async getAllRecipes(req, res) {
Expand Down Expand Up @@ -79,4 +79,4 @@ class RecipeController {
}
}

module.exports = RecipeController;
export default RecipeController;
8 changes: 5 additions & 3 deletions server/db/config.js
@@ -1,9 +1,11 @@
const dotenv = require('dotenv');
const { Pool } = require('pg');
import dotenv from 'dotenv';
import { Pool } from 'pg';

dotenv.config();

const env = process.env.NODE_ENV || 'development';

/* eslint-disable */
let pool;

if (env === 'test') {
Expand All @@ -12,4 +14,4 @@ if (env === 'test') {
pool = new Pool({ connectionString: process.env.DB_URL });
}

module.exports = pool;
export default pool;
8 changes: 5 additions & 3 deletions server/routes/recipeRouter.js
@@ -1,10 +1,12 @@
const router = require('express').Router();
const RecipeController = require('../controllers/Recipes');
import { Router } from 'express';
import RecipeController from '../controllers/Recipes';

const router = new Router();

router.get('/recipes', RecipeController.getAllRecipes);
router.get('/recipes/:id', RecipeController.getSingleRecipe);
router.post('/recipes', RecipeController.addRecipe);
router.delete('/recipes/:id', RecipeController.deleteSingleRecipe);
router.put('/recipes/:id', RecipeController.updateRecipe);

module.exports = router;
export default router;
16 changes: 8 additions & 8 deletions tests/routes/recipes.spec.js
@@ -1,11 +1,11 @@
const chai = require('chai');
require('chai/register-should');
const chaiHttp = require('chai-http');
const dirtyChai = require('dirty-chai');
const pool = require('../../server/db/config');

const app = require('../../server/app.js');
const { seedData, populateTables } = require('../seed/seed');
import chai from 'chai';
import 'chai/register-should';
import chaiHttp from 'chai-http';
import dirtyChai from 'dirty-chai';
import pool from '../../server/db/config';

import app from '../../server/app';
import { seedData, populateTables } from '../seed/seed';

const validId = Math.ceil(Math.random() * seedData.recipes.length);
const invalidId = seedData.recipes.length + 1;
Expand Down
4 changes: 2 additions & 2 deletions tests/seed/seed.js
@@ -1,4 +1,4 @@
const pool = require('../../server/db/config');
import pool from '../../server/db/config';

const seedData = {
recipes: [
Expand Down Expand Up @@ -31,4 +31,4 @@ const populateTables = async () => {
);
};

module.exports = { seedData, populateTables };
export { seedData, populateTables };

0 comments on commit 3d41a93

Please sign in to comment.