updated dependecies, added context, axios config

This commit is contained in:
Ben Elferink
2021-03-13 17:46:51 +02:00
parent a895cc0647
commit bc37d68394
19 changed files with 39144 additions and 509 deletions

View File

@@ -0,0 +1,38 @@
import Account from '../models/Account.js';
// more about response status codes ---> https://restapitutorial.com/httpstatuscodes.html
export async function registerAccount(request, response, next) {
try {
// Handle your logic here...
// return something to the client-side
response.status(201).json({ message: 'Account registered' });
} catch (error) {
console.error(error);
response.status(500).send();
}
}
export async function loginAccount(request, response, next) {
try {
// Handle your logic here...
// return something to the client-side
response.status(200).json({ message: 'Account logged-in' });
} catch (error) {
console.error(error);
response.status(500).send();
}
}
export async function getAccount(request, response, next) {
try {
// Handle your logic here...
// return something to the client-side
response.status(200).json({ message: 'Account fetched' });
} catch (error) {
console.error(error);
response.status(500).send();
}
}

View File

@@ -1,29 +0,0 @@
import mongoose from 'mongoose';
import User from '../models/User.js';
// more about response status codes ---> https://restapitutorial.com/httpstatuscodes.html
export async function getAllUsers(request, response, next) {
try {
const allUsers = await User.find(); // finds all in 'users' collection
response.status(200).json(allUsers);
} catch (error) {
console.log(error);
response.status(500).json(error);
}
}
export const createNewUser = async (request, response, next) => {
try {
let newUser = new User({
_id: mongoose.Types.ObjectId(), // _id is set by default, (you can remove this line)
name: request.body.userName, // userName === name used on client side
});
const savedUser = await newUser.save();
response.status(201).json(savedUser);
} catch (error) {
console.log(error);
response.status(500).json(error);
}
};