Ajout d'une base de données et récupération des données de la base de données

This commit is contained in:
Quentin Millardet
2023-12-29 11:10:36 +01:00
parent 9032254898
commit 132a889dae
6 changed files with 68 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ var logger = require('morgan');
var deviceRouter = require('./routes/device');
var usersRouter = require('./routes/users');
var lightshowRouter = require('./routes/lightshow');
var app = express();
@@ -21,6 +22,7 @@ app.use(express.static(path.join(__dirname, 'public')));
app.use('/devices', deviceRouter);
app.use('/users', usersRouter);
app.use('/lightshow', lightshowRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {

View File

@@ -0,0 +1,8 @@
class Ligthshow{
name;
audioFile;
audioFormat;
fseqFile;
}
module.exports = Ligthshow

View File

@@ -18,4 +18,6 @@ class Device{
set montPoint(value) {
this.#montPoint = value;
}
}
}
module.exports = Device

Binary file not shown.

View File

@@ -0,0 +1,27 @@
var express = require('express');
var router = express.Router();
const LightshowService = require('../service/LightshowService');
const LigthShow = require('../model/Ligthshow')
/* GET users listing. */
router.get('/', async function(req, res, next) {
let lightshowService = new LightshowService();
let ligthshows = await lightshowService.getAllLigthshow()
res.json(ligthshows)
});
router.post('/new', async function(req, res, next) {
let lightshowService = new LightshowService();
let ligthshow = new LigthShow();
ligthshow.name = req.body.name;
ligthshow.audioFile = req.body.name;
lightshowService.createLigthshow(ligthshow);
let ligthshows = await lightshowService.getAllLigthshow()
res.json(ligthshows)
});
module.exports = router;

View File

@@ -0,0 +1,28 @@
const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()
class LigthshowService{
async getAllLigthshow() {
const posts = await prisma.Lightshow.findMany({
})
return posts;
}
//
// createLigthshow(ligthshow) {
// prisma.Ligthshow.create({
// data: {
// ligthshow,
// content,
// published: false,
// author: { connect: { email: authorEmail } },
// },
// })
// }
}
module.exports = LigthshowService