Commit f808a8b5 authored by Romain OZDEN's avatar Romain OZDEN

Script de bd

parent 8a573a2c
(function dbInit() {
const alasql = require('alasql');
alasql(`
CREATE FILESTORAGE DATABASE IF NOT EXISTS annales("${__dirname}/db.json");
ATTACH FILESTORAGE DATABASE annales("${__dirname}/db.json");
USE annales;
SOURCE "${__dirname}/init.sql";
`);
}());
\ No newline at end of file
CREATE TABLE IF NOT EXISTS Promo (
promo_id number UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
annee string,
specialite string
);
CREATE TABLE IF NOT EXISTS `Role` (
role_id number UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
nom string
);
CREATE TABLE IF NOT EXISTS Utilisateur (
`user_id` number UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
identifiant string NOT NULL UNIQUE,
mot_de_passe string NOT NULL,
nom string,
prenom string,
email string,
role_id number UNSIGNED NOT NULL,
CONSTRAINT `fk_user_role` FOREIGN KEY (role_id) REFERENCES Role (role_id)
);
CREATE TABLE IF NOT EXISTS Matiere (
matiere_id number UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
nom string,
`user_id` number UNSIGNED NOT NULL,
promo_id number UNSIGNED NOT NULL,
CONSTRAINT `fj_mat_user` FOREIGN KEY (`user_id`) REFERENCES Utilisateur (`user_id`),
CONSTRAINT `fk_mat_promo` FOREIGN KEY (promo_id) REFERENCES Promo (promo_id)
);
CREATE TABLE IF NOT EXISTS Sujet (
sujet_id number UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
nom string,
pdf_sujet string,
pdf_correction string,
verif boolean,
date_depot date,
matiere_id number UNSIGNED NOT NULL,
CONSTRAINT `fk_suj_mat` FOREIGN KEY (matiere_id) REFERENCES Matiere (matiere_id)
);
CREATE TABLE IF NOT EXISTS Commentaire (
com_id number UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
position number UNSIGNED,
`message` string,
typesujet string,
sujet_id number UNSIGNED NOT NULL,
`user_id` number UNSIGNED NOT NULL,
CONSTRAINT `fk_com_suj` FOREIGN KEY (sujet_id) REFERENCES Sujet (sujet_id),
CONSTRAINT `fk_com_user` FOREIGN KEY (`user_id`) REFERENCES Utilisateur (`user_id`)
);
CREATE TABLE IF NOT EXISTS `Notification` (
notif_id number UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`user_id` number UNSIGNED NOT NULL,
CONSTRAINT `fk_notif_user` FOREIGN KEY (`user_id`) REFERENCES Utilisateur (`user_id`)
);
CREATE TABLE IF NOT EXISTS `Suivre` (
matiere_id number UNSIGNED NOT NULL,
`user_id` number UNSIGNED NOT NULL,
PRIMARY KEY (matiere_id, `user_id`),
CONSTRAINT `fk_suj_mat` FOREIGN KEY (matiere_id) REFERENCES Matiere (matiere_id),
CONSTRAINT `fk_notif_user` FOREIGN KEY (`user_id`) REFERENCES Utilisateur (`user_id`)
);
\ No newline at end of file
......@@ -5,7 +5,7 @@
"main": "serveur.js",
"scripts": {
"test": "node ./node_modules/gulp/bin/gulp.js",
"start": "node ./node_modules/nodemon/bin/nodemon.js --exec node app.js"
"start": "node ./node_modules/nodemon/bin/nodemon.js --exec node serveur.js"
},
"repository": {
"type": "git",
......
<!DOCTYPE html>
<html lang="fr">
<head>
<!-- Il est obligatoire de préciser un encodage de caractères et un titre pour la page -->
<meta charset="utf-8">
<!-- Pour le responsive sur mobile -->
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>PolyMusic - TP3</title>
<!-- Déclaration de la feuille de style du document-->
<link rel="text/css" href="public/css/style.css">
<!-- Polyfills pour le support de fetch dans les vieux navigateurs -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.0.5/es6-promise.min.js" async></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.1/fetch.min.js" async></script>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous" defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous" defer></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous" defer></script>
<!-- Mustache ! -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/3.0.1/mustache.min.js" async></script>
<!-- Page.js for client side routing -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/page.js/1.11.4/page.min.js" defer></script>
<!-- Notre script principal -->
<script src="public/js/main.js" defer></script>
</head>
<body>
Fais un effort là ! (╯°□°)╯︵ ┻━┻)
</body>
</html>
\ No newline at end of file
/* eslint-env browser */
/* global Mustache, page */
'use strict';
// Le script principal de notre application single page
// Celui-ci effectue le routing coté client (et d'autres choses)
// Notre objet contexte, qui contiendra toutes les données
// pour les templates Mustache
let context = {'logged': false};
// fonction utilitaire permettant de faire du
// lazy loading (chargement à la demande) des templates
const templates = (() => {
let templates = {};
return function load(url) {
if (templates[url]) {
return Promise.resolve(templates[url]);
}
else {
return fetch(url)
.then(res => res.text())
.then(text => {
return templates[url] = text;
})
}
}
})();
// Fonction utilitaire qui permet de charger en parallèle les
// différents "partial" (morceaux de template. Ex: header)
const loadPartials = (() => {
let partials;
return async function loadPartials() {
if (!partials) {
partials = {
header: templates('public/templates/header.mustache'),
footer: templates('public/templates/footer.mustache'),
};
const promises = Object.entries(partials)
.map(async function ([k, v]) {
return [k, await v];
});
partials = Object.fromEntries(await Promise.all(promises));
}
return partials;
}
})();
// route pour la page d'authentification des utilisateurs
page('/', async function () {
await renderTemplate(templates('public/templates/signup.mustache'), context);
});
page('/p', async function () {
console.log('test?')
await renderTemplate(templates('public/templates/signup.mustache'), context);
});
// On démarre le routing
page.base(window.location.pathname); // permet d'héberger la page sur une url autre de '/'
page.start();
// fonction utilitaire de rendu d'un template
async function renderTemplate(template, context) {
// On charge les partials (si pas déà chargés)
const partials = await loadPartials();
// On rend le template
const rendered = Mustache.render(await template, context, partials);
// Et on l'insère dans le body
let body = document.querySelector('body');
body.innerHTML = rendered;
}
hey hey on va se créer un joli compte (●'◡'●)
\ No newline at end of file
const express = require('express');
const app = express();
// Le contenu statique public sera lu à partir du repertoire 'public'
app.use('/public', express.static('public'));
// Pour toutes les autres url (catch all) on renverra l'index.html
// c'est le routeur coté client qui fera alors le routing
app.use(function (req, res) {
res.sendFile('public/index.html', {'root': __dirname});
});
app.listen(8080, () => { console.log('Server is running on port 8080')});
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment