UP user -> ts
This commit is contained in:
parent
46bf2aca1c
commit
ae2aa8c120
@ -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();
|
||||
|
@ -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);
|
13
models/userModel.ts
Normal file
13
models/userModel.ts
Normal file
@ -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;
|
@ -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;
|
18
routes/user.ts
Normal file
18
routes/user.ts
Normal file
@ -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;
|
Loading…
x
Reference in New Issue
Block a user