diff --git a/controllers/userController.js b/controllers/userController.ts similarity index 79% rename from controllers/userController.js rename to controllers/userController.ts index 3d7c4cd..13a5a48 100644 --- a/controllers/userController.js +++ b/controllers/userController.ts @@ -1,8 +1,9 @@ -var UserModel = require('../models/userModel'); +import { type Request, type Response } from "express"; +import UserModel from '../models/userModel'; -module.exports = { +export default { - create: async function (req, res) { + create: async function (req: Request, res: Response) { const pass = req.body.pass; try { @@ -27,7 +28,7 @@ module.exports = { } }, - remove: async function (req, res) { + remove: async function (req: Request, res: Response) { try { await UserModel.deleteMany(); return res.status(204).json({ message: 'User deleted' }); @@ -36,7 +37,7 @@ module.exports = { } }, - get: async function (req, res) { + get: async function (req: Request, res: Response) { try { const usersFound = await UserModel.find(); diff --git a/models/userModel.js b/models/userModel.js deleted file mode 100644 index 9279228..0000000 --- a/models/userModel.js +++ /dev/null @@ -1,12 +0,0 @@ -var mongoose = require('mongoose'); -var Schema = mongoose.Schema; - -var userSchema = new Schema({ - 'pass': String, - 'omdb_key': String, - 'twitch_client_id': String, - 'twitch_client_secret': String, - 'mac_address': String, -}); - -module.exports = mongoose.model('user', userSchema); \ No newline at end of file diff --git a/models/userModel.ts b/models/userModel.ts new file mode 100644 index 0000000..5650e3c --- /dev/null +++ b/models/userModel.ts @@ -0,0 +1,13 @@ +import mongoose, { Schema } from 'mongoose'; + +const userSchema = new Schema({ + 'pass': String, + 'omdb_key': String, + 'twitch_client_id': String, + 'twitch_client_secret': String, + 'mac_address': String, +}); + +const User = mongoose.model('user', userSchema); + +export default User; diff --git a/routes/user.js b/routes/user.js deleted file mode 100644 index 8d16980..0000000 --- a/routes/user.js +++ /dev/null @@ -1,17 +0,0 @@ -var express = require('express'); -var router = express.Router(); -var userController = require('../controllers/userController.js'); -const checkAuthenticated = require('../miscellaneous/checkAuthenticated.js').default; - -/* GET home page. */ -router.get('/', function (req, res, next) { - res.render('user', { title: 'Register' }); -}); - -router.post('/', userController.create); - -router.delete('/', checkAuthenticated, userController.remove); - -router.put('/', checkAuthenticated, userController.get); - -module.exports = router; \ No newline at end of file diff --git a/routes/user.ts b/routes/user.ts new file mode 100644 index 0000000..1d1242c --- /dev/null +++ b/routes/user.ts @@ -0,0 +1,18 @@ +import express, { type Request, type Response } from "express"; +var router = express.Router(); +import userController from '../controllers/userController'; + +import checkAuthenticated from '../miscellaneous/checkAuthenticated'; + +/* GET home page. */ +router.get('/', function (req: Request, res: Response) { + res.render('user', { title: 'Register' }); +}); + +router.post('/', userController.create); + +router.delete('/', checkAuthenticated, userController.remove); + +router.put('/', checkAuthenticated, userController.get); + +export default router; \ No newline at end of file