Skip to content

Instantly share code, notes, and snippets.

@cklanac
cklanac / mongoose-relationships.js
Last active March 23, 2018 17:39
Mongo Relationships
/**
*
* Genres => Movies => cast & crew
*
* Movies have reviews:
* - Structure: Movies (parent) embed Reviews (child) as sub-documents
* - Cardinality: is one-to-few
*
* Movies reference cast and crew (one-to-many)
* - Structure: Movies (parent) reference cast and crew (child) using Ids
@cklanac
cklanac / promises.js
Last active March 8, 2018 16:44
Promises demo code
/* global $ */
'use strict';
// instructor
const url = 'https://swapi.co/api/films/1';
// ======================================
console.log('first');
@cklanac
cklanac / test.js
Created February 23, 2018 18:40
Sample login and get a protected endpoint
'use strict';
const app = require('../server');
const chai = require('chai');
const chaiHttp = require('chai-http');
const mongoose = require('mongoose');
const jwt = require('jsonwebtoken');
const { TEST_MONGODB_URI, JWT_SECRET } = require('../config');
@cklanac
cklanac / challenge-19-test-auth.md
Last active November 3, 2018 08:47
Challenge 19: Testing Auth

Challenge - Create User Tests

In this challenge you will create integration tests to verify User endpoints including /login. And you will update the integration tests for endpoints protected by JWT.

Create a User tests

Create a /test/users.test.js file and copy in the starter from this gist

The setup and Mocha hooks have been completed for you. And note the use of describe.only which tells Mocha run this suite of tests and skip the others. You'll tackle the other tests later.

@cklanac
cklanac / challenge-18-multiuser.md
Last active November 3, 2018 08:48
Challenge 18: Multiuser

In this challenge you will update the Noteful to support multiple users. Each user will have their own set of notes, folder and tags. And you must ensure that a user cannot read, modify or delete another user's items.

Requirements

  • Update Notes, Folder and Tags models and seed data individual users
  • Protect against invalid folderId or tag references

Update Note schema and endpoints

To get started, update the Note schema to support a User reference. Reseed the database with Notes that contain a userId. And update all of the notes routes to reference the current user id.

@cklanac
cklanac / challenge-17-jwt-auth.md
Last active November 3, 2018 08:54
Challenge 17: JWT Authorization

Challenge - JWT Authorization

In this challenge you will update the /login endpoint to create and return a JWT. You will also create a Passport JWT Strategy and use it protect all the notes, folder and tags endpoints. And then use the JWT to access the protected endpoints.

Requirements

Configure JWT settings

Add JWT_SECRET and JWT_EXPIRY settings to config.js.

@cklanac
cklanac / challenge-16-local-auth.md
Last active November 3, 2018 08:52
Challenge 16: Local Auth

Challenge - Local Authentication

In this challenge you'll add authentication using Passport Local Strategy to the Noteful app.

Requirements

Save a new User to the DB

The first challenge is to add the ability to save a user to the database. This means you need to create a User schema and User model, and you need to add a POST /api/users endpoint to create the new user.

@cklanac
cklanac / noteful.js
Created February 20, 2018 18:23
Update noteful.js file
/* global $ store api moment */
'use strict';
const noteful = (function () {
function showSuccessMessage(message) {
const el = $('.js-success-message');
el.text(message).show();
setTimeout(() => el.fadeOut('slow'), 3000);
}
@cklanac
cklanac / challenge-15-relationships_ii.md
Last active November 3, 2018 08:55
Challenge 15: Mongo(ose) Relationships II

In this challenge, you will add Tags to the Noteful app, populate the notes with tags, create routes and tests for the tags and update the routes and test for the notes.

Requirements

  • Create tag schema, update notes schema and then seed the database
  • Create tags endpoints and update notes endpoints
  • Update server.js to mount tags router
  • Update the client

Create/Update schemas and seed the database

@cklanac
cklanac / challenge-14-relationships-i.md
Last active November 3, 2018 08:45
Challenge 14: Mongo(ose) Relationships

For this challenge, you will add Folders to the Noteful app, associate the notes with the folders, create routes and tests for the folders and update the routes and test for the notes.

Requirements

  • Create folder schema, update notes schema and seed the database
  • Create folder endpoints and update notes endpoints
  • Update server.js mount folder router
  • Update the client

Create/Update schemas and seed the database