The Javascript library that we use to create interactive back-end servers.
What is Express.js?
The Javascript library that we use to make requests to our Postgres database in Javascript.
What is Sequelize.js?
What two sequelize association keywords would we use to define a one to one relationship?
hasOne and belongsTo
This method will hit a GET route matching the given URL in a server.
What is a GET method?
What is a built in JavaScript function that will check if a value is NaN?
What is isNan()?
The term for an action or route that gets executed after a user sends a request but before they get to their endpoint.
What is Middleware?
The data type that accepts only a few values, specified as a list.
What is ENUM.
How would you define a relationship between a Pokemon and a trainer where a trainer can have lots of different Pokemon, and a Pokemon will be associated to a trainer?
Pokemon.belongsTo(Trainer);
Trainer.hasMany(Pokemon);
A status code that indicates that a request has succeeded, but no content will be given back and the client doesn't need to navigate away from its current page.
What is a 204 status code?
What is a built in JavaScript function that will set a timer which executes a function or specified piece of code once the timer expires?
The Express method living on the Res object that allows you to send back a status code without any other content.
What is res.sendStatus?
The datatype for a Sequelize field that doesn't actually exist within a database but is still queryable.
What is VIRTUAL?
FREE SPACE! What happens if you pick this one? Do you dare?
OOOF You just lost 300 points? :(
A status code that means that a server could not find a client-requested webpage.
What is a 404 status code?
An array method that tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.
const isBelowThreshold = (currentValue) => currentValue < 40;
const array1 = [1, 30, 39, 29, 10, 13];
console.log(array1.???(isBelowThreshold));
// expected output: true
.every()
The Express method that allows you to send back a status code of 201 as well as a JS variable we created called newUser.
res.status(201).send(newUser);
How would we check in Sequelize if our data field on a model is an e-mail and what would we set that value to?
validate: {
isEmail: true,
}
How would you define a many-to-many association between an actor and a movie where Sequelize will automatically create an additional model called ActorMovies and link the actor and movie together?
Movie.belongsToMany(Actor, { through: 'ActorMovies' });
Actor.belongsToMany(Movie, { through: 'ActorMovies' });
The four types of http requests we've used with express.
1. Get
2. Post
3. Put
4. Delete
Guess Ben and Louis favorite Pokemon. You get 3 guesses for each person. If you don't get it in 3 tries you get a final guess of the type for full points. NOTE: 200 points per person.
:)
CODE STRETCH:
Create a GET route with a parameter called ID that sends back that ID multiplied by 4
*Solution*
CODE STRETCH:
Create a Sequelize model that accomplishes the following:
- Called "Post"
- Has a Name field which is required and cannot be an empty string
- Has a Status field which can be one of three options: "Draft", "Published", or "Removed"
db.define("Post", {
name: {
type: Sequelize.STRING,
allowNull: false,
validate: { notEmpty: true }
},
status: Sequelize.ENUM(["Draft", "Published", "Removed"]);
})
CODE STRETCH:
Assuming you have 3 tables - `User`, `Post`, and `Likes`, write up a snippet that accomplishes the following:
- Creates a many-to-many relationship between User and Post through the Join table
- Aliases the relationships as "usersWhoLike" and "postsUserLikes"
User.belongsToMany(Post, { through: Likes, as: "usersWhoLike"})
Post.belongsToMany(User, { through: Likes, as: "postsUserLikes"})
I'm a status code representing a client error indicating that the server refuses to brew coffee because it is, permanently, a teapot.
What is Status Code 418?
refactor this block using a ternary operator.
const isBestPokemon = wiglett;
if(isBestPokemon === 'wiglett') { console.log('yayyy wiglett!')
} else {
console.log('you're wrong! wigletts the best!')
}
const isBestPokemon = wiglett;
isBestPokemon === 'wiglett' ? console.log('yayyy wiglett!') : console.log('you're wrong! wigletts the best!')