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
componentDidMount() { | |
this.$el = $(this.el); | |
this.currentTable = this.$el.DataTable({}); | |
} |
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
import React from "react"; | |
class Datatable extends React.Component { | |
render() { | |
return ( | |
<table ref={(el) => (this.el = el)}> | |
</table> | |
); | |
} | |
} |
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
// This is a basic class component which only displays message in h1 tag. | |
import React from "react"; | |
class Welcome extends React.Component { | |
render() { | |
return <h1>Hello, {this.props.name}</h1>; | |
} | |
} |
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
// npm install -S express jsonwebtoken body-parser bcrypt mongoose | |
// npm install -D nodemon | |
// adding "start": "nodemon" to start script | |
// npm start | |
// CONSTANTS | |
const PORT = 3000; | |
const SECRET_KEY = "a_secret_key_to_sign_jwt"; | |
const SALT_ROUNDS = 10; |
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
// import packages | |
const express = require("express"); | |
const bodyParser = require("body-parser"); | |
const mongoose = require("mongoose"); | |
const path = require("path"); | |
const fs = require("fs"); | |
// create and configure express app | |
const app = express(); | |
app.use(bodyParser.json()); //parsing json files |
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
/** STEP 1: Packages */ | |
// For a minimal node.js server we need to install and import the bellow packages | |
const express = require("express"); // fast, open-source node.js server | |
const cors = require("cors"); // enables CORS (cross-origin resource sharing) | |
const bodyParser = require("body-parser"); // parses json body into javascript object | |
const morgan = require("morgan"); // log http requests | |
const mongoose = require("mongoose"); // mongodb orm | |
/** STEP 2: DATABASE */ |
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
var createTodo = async (req, res, next) => { | |
try { | |
var text = req.body.text; | |
if(!text) { | |
var err = new Error('todo should be provided'); | |
err.msg = 'todo should be provided'; | |
err.status = 406; | |
next(err); | |
return; | |
} |
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 chai = require('chai'); | |
const sinon = require('sinon'); | |
const expect = chai.expect; | |
const {createTodo, listTodos} = require('./todoController'); | |
describe('todoController', function() { | |
beforeEach(function() { | |
req = {body: {text: 'Go to the meeting!'}, db: {TodoModel: {create: null, findAll: null}}}; | |
res = {json: sinon.fake()}; |
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
it('text should be provided', async function() { | |
req.body.text = null; | |
await createTodo(req, res, next); | |
expect(next.args[0][0]).to.have.property('msg', 'todo should be provided'); | |
}); |
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
describe('todoController', function() { | |
describe('createTodo', function() { | |
it('text should be provided'); | |
it('should send success result if todo is saved to database'); | |
it('should send fail result if todo is not saved to database'); | |
}); | |
describe('fetchTodos', function() { | |
it('should send a list of todos with success message'); | |
it('should send fail result if todo is not fetched from database'); |
NewerOlder