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
function hello(name: string) { | |
console.log("Hello " + name); | |
} | |
const firstName = "bob"; | |
hello(firstName); | |
hello(firstName + " marley"); | |
function concat(a: string, b: string): string { |
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 mongoose = require("mongoose") | |
const schema = mongoose.Schema({ | |
title: String, | |
content: String, | |
}) | |
module.exports = mongoose.model("Post", schema) |
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
// Model User | |
const create = ({ firstname, lastname, email, password }) => { | |
return hashPassword(password).then((password) => { | |
return db | |
.query("INSERT INTO users SET ?", { | |
firstname, | |
lastname, | |
email, | |
password, |
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
1: mysql> SELECT team.name, COUNT(*) AS nb_players | |
FROM player | |
LEFT JOIN team ON team.id = player.team_id | |
GROUP BY team.name; | |
+------------+------------+ | |
| name | nb_players | | |
+------------+------------+ | |
| Hufflepuff | 12 | | |
| Gryffindor | 36 | | |
| Slytherin | 21 | |
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
mysql> SELECT lastname, firstname, role, name FROM player INNER JOIN wizard ON wizard.id=player.wizard_id INNER JOIN team ON team.id=player.team_id ORDER BY name ASC, role ASC, lastname ASC, firstname ASC; | |
+-----------------+-------------+--------+------------+ | |
| lastname | firstname | role | name | | |
+-----------------+-------------+--------+------------+ | |
| Black | Sirius | beater | Gryffindor | | |
| Brown | Lavender | beater | Gryffindor | | |
| Finnigan | Seamus | beater | Gryffindor | | |
| Hagrid | Rubeus | beater | Gryffindor | | |
| Longbottom | Alice | beater | Gryffindor | | |
| McGonagall | Minerva | beater | Gryffindor | |
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
t |
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
app.post('/api/movies', (req, res) => { | |
const { title, director, year, color, duration } = req.body; | |
const db = connection.promise(); | |
let validationErrors = null; | |
db.query('SELECT * FROM users WHERE title = ?', [title]) | |
.then(([result]) => { | |
if (result[0]) return Promise.reject('DUPLICATE_MOVIE'); | |
validationErrors = Joi.object({ | |
title: Joi.string().email().max(255).required(), | |
director: Joi.string().max(255).required(), |
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 connection = require("./db-config"); | |
const express = require("express"); | |
const app = express(); | |
const port = process.env.PORT || 3000; | |
connection.connect((err) => { | |
if (err) { | |
console.error("error connecting: " + err.stack); | |
} else { |
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
app.delete('/api/movies/:id', (req, res) => { | |
const movieId = req.params.id; | |
connection.query( | |
'DELETE FROM movies WHERE id = ?', | |
[movieId], | |
(err, results) => { | |
if (err) { | |
console.log(err); | |
res.status(500).send('Error deleting a movie'); | |
} else { |
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 connection = require('./db-config'); | |
const express = require('express'); | |
const app = express(); | |
const port = process.env.PORT || 3000; | |
connection.connect((err) => { | |
if (err) { | |
console.error('error connecting: ' + err.stack); | |
} else { |
NewerOlder