From d583fb78e807e7ff1b3fe59b0db23c777ecac33f Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Sun, 11 Jun 2023 13:35:09 +0300 Subject: [PATCH] README + changed schema of user --- README.md | 13 +++++++++++++ src/controllers/UserController.ts | 6 ++---- src/mongoose/Schema.ts | 4 ---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0fd45a7..39a7d91 100644 --- a/README.md +++ b/README.md @@ -218,4 +218,17 @@ status 404 message: "Cart not found." } +``` + +# Database Schema +## User +``` +{ + name: string, + email: string, + password: string, + cart: { + productId: number + } +} ``` \ No newline at end of file diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index e9151c1..c55b268 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -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, diff --git a/src/mongoose/Schema.ts b/src/mongoose/Schema.ts index 5e0ffb0..0a1157b 100644 --- a/src/mongoose/Schema.ts +++ b/src/mongoose/Schema.ts @@ -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 },