Added more backend models
This commit is contained in:
1 parent
b1820521bc
commit
203aca7c65
9 files changed
+193
-14
No files matched your search
+40
-9
@@ -1,21 +1,52 @@
|
||||
// routes/tasks.js
|
||||
const express = require('express');
|
||||
const { fetchMovieData } = require('../services/tmdbService');
|
||||
const { fetchEntryData } = require('../services/tmdbService');
|
||||
const Entry = require('../models/Entry');
|
||||
const EntryId = require('../models/EntryId');
|
||||
const EntryRating = require('../models/EntryRating');
|
||||
const router = express.Router();
|
||||
|
||||
// GET all entries
|
||||
router.get('/', (req, res) => {
|
||||
res.status(200).json(tasks);
|
||||
// ! entries/
|
||||
|
||||
// ? GET all entries
|
||||
router.get('/', async (req, res) => {
|
||||
const { page, pageSize } = req.body;
|
||||
|
||||
const entries = await Entry.findAll({
|
||||
include: [
|
||||
{ model: EntryId, as: 'entryId' },
|
||||
{ model: EntryRating, as: 'entryRating' }
|
||||
]
|
||||
});
|
||||
|
||||
res.status(200).json(entries);
|
||||
});
|
||||
|
||||
// POST a new entry
|
||||
// ? POST a new entry
|
||||
router.post('/', async (req, res) => {
|
||||
const { tmdb_id } = req.body;
|
||||
const entry = await fetchMovieData(tmdb_id);
|
||||
const { tmdb_id, is_tvserie } = req.body;
|
||||
|
||||
console.log(entry);
|
||||
const entry = await fetchEntryData(tmdb_id, is_tvserie);
|
||||
|
||||
res.status(201).json(entry);
|
||||
});
|
||||
|
||||
// ! DELETE an entry by ID
|
||||
router.delete('/:id', async (req, res) => {
|
||||
const { id } = req.params;
|
||||
|
||||
try {
|
||||
const numDeleted = await Entry.destroy({
|
||||
where: { id: id }
|
||||
});
|
||||
|
||||
if (numDeleted) {
|
||||
res.status(200).json({ message: `Entry with ID ${id} deleted.` });
|
||||
} else {
|
||||
res.status(404).json({ message: `Entry with ID ${id} not found.` });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: `Error deleting entry with ID ${id}.`, error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in new issue
Block a user