UP api -> ts

This commit is contained in:
Nikola Petrov 2024-07-16 15:02:41 +02:00
parent ae2aa8c120
commit e14d405ca2
9 changed files with 56 additions and 54 deletions

2
app.ts
View File

@ -24,7 +24,7 @@ app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
import mainRouter from './routes/main';
var apiRouter = require('./routes/api/apiRouter');
import apiRouter from './routes/api/apiRouter';
app.use('/', mainRouter);
app.use('/api', apiRouter);

View File

@ -1,18 +0,0 @@
var express = require('express');
var router = express.Router();
const checkAuthenticated = require('../../miscellaneous/checkAuthenticated.js').default;
var mediaRouter = require('./mediaRouter');
var gameRouter = require('./gameRouter');
var cashTransactionRouter = require('./cashTransactionRouter');
router.use('/games', gameRouter);
router.use('/movies', mediaRouter);
router.use('/series', mediaRouter);
router.use('/cash', checkAuthenticated, cashTransactionRouter);
router.get('/', function (req, res, next) {
res.status(200).json({ message: 'API is working' });
});
module.exports = router;

19
routes/api/apiRouter.ts Normal file
View File

@ -0,0 +1,19 @@
import express, { type Request, type Response } from "express";
const router = express.Router();
import checkAuthenticated from '../../miscellaneous/checkAuthenticated';
import mediaRouter from './mediaRouter';
import gameRouter from './gameRouter';
import cashTransactionRouter from './cashTransactionRouter';
router.use('/games', gameRouter);
router.use('/movies', mediaRouter);
router.use('/series', mediaRouter);
router.use('/cash', checkAuthenticated, cashTransactionRouter);
router.get('/', function (req: Request, res: Response) {
res.status(200).json({ message: 'API is working' });
});
export default router;

View File

@ -1,11 +0,0 @@
var express = require('express');
var router = express.Router();
const cashTransaction = require('../../controllers/cashTransactionController.js')
router.post('/list', cashTransaction.list);
router.post('/', cashTransaction.create);
router.delete('/', cashTransaction.delete);
module.exports = router;

View File

@ -0,0 +1,11 @@
import express from "express";
const router = express.Router();
import cashTransaction from '../../controllers/cashTransactionController.js';
router.post('/list', cashTransaction.list);
router.post('/', cashTransaction.create);
router.delete('/', cashTransaction.delete);
export default router;

View File

@ -1,12 +0,0 @@
var express = require('express');
var router = express.Router();
var gameController = require('../../controllers/gameController.js');
var checkAuthenticated = require('../../miscellaneous/checkAuthenticated.js').default;
router.get('/', gameController.list);
router.post('/', checkAuthenticated, gameController.create);
router.delete('/', checkAuthenticated, gameController.remove);
module.exports = router;

12
routes/api/gameRouter.ts Normal file
View File

@ -0,0 +1,12 @@
import express from "express";
var router = express.Router();
import gameController from '../../controllers/gameController.js';
import checkAuthenticated from '../../miscellaneous/checkAuthenticated';
router.get('/', gameController.list);
router.post('/', checkAuthenticated, gameController.create);
router.delete('/', checkAuthenticated, gameController.remove);
export default router;

View File

@ -1,12 +0,0 @@
var express = require('express');
var router = express.Router();
var mediaController = require('../../controllers/mediaController.js');
var checkAuthenticated = require('../../miscellaneous/checkAuthenticated.js').default;
router.get('/', mediaController.list);
router.post('/', checkAuthenticated, mediaController.create);
router.delete('/', checkAuthenticated, mediaController.remove);
module.exports = router;

13
routes/api/mediaRouter.ts Normal file
View File

@ -0,0 +1,13 @@
import express from "express";
import mediaController from '../../controllers/mediaController.js';
import checkAuthenticated from '../../miscellaneous/checkAuthenticated';
var router = express.Router();
router.get('/', mediaController.list);
router.post('/', checkAuthenticated, mediaController.create);
router.delete('/', checkAuthenticated, mediaController.remove);
export default router;