README + changed schema of user

This commit is contained in:
Kfir Dayan 2023-06-11 13:35:09 +03:00
parent 28ccd1fe64
commit d583fb78e8
3 changed files with 15 additions and 8 deletions

View file

@ -218,4 +218,17 @@ status 404
message:
"Cart not found."
}
```
# Database Schema
## User
```
{
name: string,
email: string,
password: string,
cart: {
productId: number
}
}
```

View file

@ -6,9 +6,9 @@ import { clearJwtCookie, setJwtCookie } from '../middlewares/checkAuth';
export async function createUser(req: Request, res: Response) {
try {
const { firstName, lastName, email, password, address } = req.body;
const { email, password, address } = req.body;
if (!(email && password && firstName && lastName && address)) {
if (!(email && password && address)) {
return res.status(400).json({ error: 'All inputs are required' });
}
// checkIfUserExists return true if the user exists
@ -20,8 +20,6 @@ export async function createUser(req: Request, res: Response) {
const hashedPassword = await bcrypt.hash(password, 10);
const user: IUser = await User.create({
firstName,
lastName,
email,
password: hashedPassword,
address,

View file

@ -1,8 +1,6 @@
import mongoose, { Schema, Document } from 'mongoose';
export interface IUser extends Document {
firstName: string;
lastName: string;
email: string;
password: string;
address: string;
@ -35,8 +33,6 @@ export interface IOrder extends Document {
}
const UserSchema: Schema = new Schema({
firstName: { type: String, required: true },
lastName: { type: String, required: true },
email: { type: String, required: true, unique: true },
password: { type: String, required: true },
address: { type: String, required: true },