README + changed schema of user
This commit is contained in:
parent
28ccd1fe64
commit
d583fb78e8
3 changed files with 15 additions and 8 deletions
13
README.md
13
README.md
|
@ -218,4 +218,17 @@ status 404
|
||||||
message:
|
message:
|
||||||
"Cart not found."
|
"Cart not found."
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
# Database Schema
|
||||||
|
## User
|
||||||
|
```
|
||||||
|
{
|
||||||
|
name: string,
|
||||||
|
email: string,
|
||||||
|
password: string,
|
||||||
|
cart: {
|
||||||
|
productId: number
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
|
@ -6,9 +6,9 @@ import { clearJwtCookie, setJwtCookie } from '../middlewares/checkAuth';
|
||||||
|
|
||||||
export async function createUser(req: Request, res: Response) {
|
export async function createUser(req: Request, res: Response) {
|
||||||
try {
|
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' });
|
return res.status(400).json({ error: 'All inputs are required' });
|
||||||
}
|
}
|
||||||
// checkIfUserExists return true if the user exists
|
// 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 hashedPassword = await bcrypt.hash(password, 10);
|
||||||
|
|
||||||
const user: IUser = await User.create({
|
const user: IUser = await User.create({
|
||||||
firstName,
|
|
||||||
lastName,
|
|
||||||
email,
|
email,
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
address,
|
address,
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import mongoose, { Schema, Document } from 'mongoose';
|
import mongoose, { Schema, Document } from 'mongoose';
|
||||||
|
|
||||||
export interface IUser extends Document {
|
export interface IUser extends Document {
|
||||||
firstName: string;
|
|
||||||
lastName: string;
|
|
||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string;
|
||||||
address: string;
|
address: string;
|
||||||
|
@ -35,8 +33,6 @@ export interface IOrder extends Document {
|
||||||
}
|
}
|
||||||
|
|
||||||
const UserSchema: Schema = new Schema({
|
const UserSchema: Schema = new Schema({
|
||||||
firstName: { type: String, required: true },
|
|
||||||
lastName: { type: String, required: true },
|
|
||||||
email: { type: String, required: true, unique: true },
|
email: { type: String, required: true, unique: true },
|
||||||
password: { type: String, required: true },
|
password: { type: String, required: true },
|
||||||
address: { type: String, required: true },
|
address: { type: String, required: true },
|
||||||
|
|
Loading…
Reference in a new issue