Skip to content

Instantly share code, notes, and snippets.

Avatar

Nicolas AUVRAY nicovray

View GitHub Profile
View auth.js
const authRouter = require('express').Router();
const User = require('../models/user');
const { calculateToken } = require('../helpers/users');
authRouter.post('/sessions', (req, res) => {
const { email, password } = req.body;
User.findByEmail(email).then((user) => {
if (!user) res.status(401).send('Invalid credentials');
else {
User.verifyPassword(password, user.hashedPassword).then(
View movies.js
moviesRouter.get('/', (req, res) => {
const { user_token } = req.cookies;
User.findByToken(user_token).then((user) => {
User.movies(user.id).then((movies) => {
res.send(movies)
}).catch(() => res.status(500).send('Error'))
}).catch(()=>res.status(401).send('Unauthorized access'))
});
View auth.js
const authRouter = require('express').Router();
const User = require('../models/user');
authRouter.post('/checkCredentials', (req, res) => {
const { email, password } = req.body;
User.findByEmail(email).then((user) => {
if (!user) res.status(401).send('Invalid credentials');
else {
User.verifyPassword(password, user.hashedPassword).then(
View gist:93c1da691b0428fc9d0f656db52f928a
SELECT team.name, COUNT(*) as nb_player FROM team INNER JOIN player ON player.team_id=team.id GROUP BY team.name ORDER BY nb_player DESC;
+------------+-----------+
| name | nb_player |
+------------+-----------+
| Gryffindor | 36 |
| Slytherin | 21 |
| Ravenclaw | 15 |
| Hufflepuff | 12 |
+------------+-----------+
View gist:4fe9132657cb04d2de46218bb5f81c22
1/Retourne les noms, prénoms, rôle et équipe de tous les joueurs, classés dans l’ordre alphabétique par équipe, puis par rôle dans l’équipe, puis par nom de famille, puis par prénom :
SELECT firstname,lastname,name,role
FROM player
INNER JOIN wizard ON wizard.id=player.wizard_id
INNER JOIN team ON team.id=player.team_id
ORDER BY name,role,firstname,firstname;
2/Retourne uniquement les prénoms et noms des joueurs ayant le rôle de seeker (attrapeur), classés par ordre alphabétique de nom puis prénom :
View App.js
const connection = require('./db-config');
const express = require('express');
const app = express();
const Joi = require('joi');
const port = process.env.PORT || 3000;
connection.connect((err) => {
if (err) {
console.error('error connecting: ' + err.stack);
View gist:84b33b8abb7e6e6c3076ce582919e1fb
\A\.
[0-9]./[0-9]./[0-9]{4}
\ [0-9]\/[0-9]{2}
[a-z]{14}/gi
/\w+(:\/\/)\w+\.\w+\.\w+\/\w+\/\w+/
View App.js
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 {
View App.js
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 {
View App.js
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 {