Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
code formatted using prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
s-vamshi committed Oct 8, 2022
1 parent 60c6a10 commit c6b006b
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 95 deletions.
8 changes: 4 additions & 4 deletions backend/config/db.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const mongoose = require('mongoose')
const cloudinary = require("cloudinary").v2
const cloudinary = require('cloudinary').v2

const connectDB = async () => {
try {
Expand All @@ -19,10 +19,10 @@ cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
secure: true
});
secure: true,
})

module.exports = {
connectDB,
cloudinary
cloudinary,
}
16 changes: 8 additions & 8 deletions backend/controllers/productController.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ const createProduct = asyncHandler(async (req, res) => {
description,
})

try{
try {
const createdProduct = await product.save()

res.status(201).json(createdProduct)
}catch(error){
if (error.name === "ValidationError") {
let errors = '';
} catch (error) {
if (error.name === 'ValidationError') {
let errors = ''
Object.keys(error.errors).forEach((key) => {
errors+=error.errors[key].message+'.\n';
});
res.status(500).json(errors);
errors += error.errors[key].message + '.\n'
})
res.status(500).json(errors)
}
}
}
})

// @desc Update a product
Expand Down
16 changes: 8 additions & 8 deletions backend/models/productModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,37 @@ const productSchema = mongoose.Schema(
},
name: {
type: String,
required: [true,"Please Enter Name of the Product"],
required: [true, 'Please Enter Name of the Product'],
},
imageSrc: {
type: String,
required: [true,"Please Upload an Image File"],
required: [true, 'Please Upload an Image File'],
},
imageAlt: {
type: String,
required: [true,"Please Enter Image Alt"],
required: [true, 'Please Enter Image Alt'],
},
category: {
type: String,
required: [true,"Please Enter Category of the Product"],
required: [true, 'Please Enter Category of the Product'],
},
description: {
type: String,
required: [true,"Please Enter Description of the Product"],
required: [true, 'Please Enter Description of the Product'],
},
price: {
type: Number,
required: [true,"Please Enter Price of Product"],
required: [true, 'Please Enter Price of Product'],
default: 0,
},
mrp: {
type: Number,
required: [true,"Please Enter MRP of the Product"],
required: [true, 'Please Enter MRP of the Product'],
default: 0,
},
countInStock: {
type: Number,
required: [true,"Please Enter Stock of the Product"],
required: [true, 'Please Enter Stock of the Product'],
default: 0,
},
},
Expand Down
8 changes: 4 additions & 4 deletions backend/routes/uploadRoutes.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const path = require('path')
const express = require('express')
const multer = require('multer')
const {cloudinary} = require('../config/db')
const { CloudinaryStorage } = require("multer-storage-cloudinary")
const { cloudinary } = require('../config/db')
const { CloudinaryStorage } = require('multer-storage-cloudinary')

const router = express.Router()

const storage = new CloudinaryStorage({
cloudinary,
params: {
folder: "Products"
folder: 'Products',
},
});
})

function checkFileType(file, cb) {
const filetypes = /jpg|jpeg|png/
Expand Down
2 changes: 1 addition & 1 deletion backend/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path')
const express = require('express')
require('dotenv').config()
const {connectDB} = require('./config/db')
const { connectDB } = require('./config/db')
const productRoutes = require('./routes/productRoutes')
const userRoutes = require('./routes/userRoutes')
const orderRoutes = require('./routes/orderRoutes')
Expand Down
1 change: 0 additions & 1 deletion frontend/src/actions/productActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ export const createProduct = (product) => async (dispatch, getState) => {

const { data } = await axios.post(`/api/products`, product, config)


dispatch({
type: PRODUCT_CREATE_SUCCESS,
payload: data,
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { Alert } from 'react-bootstrap'

const Message = ({ className, variant, children }) => {
return (
<Alert className={className} style={{whiteSpace: 'pre-wrap'}} variant={variant}>
<Alert
className={className}
style={{ whiteSpace: 'pre-wrap' }}
variant={variant}
>
{children}
</Alert>
)
Expand Down
31 changes: 20 additions & 11 deletions frontend/src/screens/CreateProductScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ const CreateProductScreen = ({ history }) => {
setImageSrc(data)
setUploading(false)
} catch (error) {
const message =error.response && error.response.data.message
? error.response.data.message
: error.message
const message =
error.response && error.response.data.message
? error.response.data.message
: error.message
dispatch({
type: PRODUCT_CREATE_FAIL ,
payload: message
type: PRODUCT_CREATE_FAIL,
payload: message,
})
setImageSrc('')
setUploading(false)
Expand Down Expand Up @@ -129,21 +130,29 @@ const CreateProductScreen = ({ history }) => {
></Form.Control>
</Form.Group>

<Form.Group controlId='image-file'>
<Form.Group controlId="image-file">
<Row>
<Col>
<Col>
<Form.Label>Product Image</Form.Label>
<Form.File
id='image-file'
size='sm'
id="image-file"
size="sm"
custom
variant='secondary'
variant="secondary"
onChange={uploadFileHandler}
></Form.File>
</Col>
<Col>
{uploading && <Loader />}
{!uploading && imageSrc && <img src={imageSrc} className={'m-2'} width={100} height={100} alt="product" />}
{!uploading && imageSrc && (
<img
src={imageSrc}
className={'m-2'}
width={100}
height={100}
alt="product"
/>
)}
</Col>
</Row>
</Form.Group>
Expand Down
57 changes: 33 additions & 24 deletions frontend/src/screens/ProductEditScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { listProductDetails, updateProduct } from '../actions/productActions'
import {
PRODUCT_DETAILS_RESET,
PRODUCT_UPDATE_RESET,
PRODUCT_UPDATE_FAIL
PRODUCT_UPDATE_FAIL,
} from '../constants/productConstants'

const ProductEditScreen = ({ match, history }) => {
Expand Down Expand Up @@ -77,12 +77,13 @@ const ProductEditScreen = ({ match, history }) => {
setImageSrc(data)
setUploading(false)
} catch (error) {
const message =error.response && error.response.data.message
? error.response.data.message
: error.message
const message =
error.response && error.response.data.message
? error.response.data.message
: error.message
dispatch({
type: PRODUCT_UPDATE_FAIL ,
payload: message
type: PRODUCT_UPDATE_FAIL,
payload: message,
})
setImageSrc('')
setUploading(false)
Expand Down Expand Up @@ -148,24 +149,32 @@ const ProductEditScreen = ({ match, history }) => {
></Form.Control>
</Form.Group>

<Form.Group controlId='image-file'>
<Row>
<Col>
<Form.Label>Upload Product Image</Form.Label>
<Form.File
id='image-file'
size='sm'
custom
variant='secondary'
onChange={uploadFileHandler}
></Form.File>
</Col>
<Col>
{uploading && <Loader />}
{!uploading && imageSrc && <img src={imageSrc} className={'m-2'} width={100} height={100} alt="product" />}
</Col>
</Row>
</Form.Group>
<Form.Group controlId="image-file">
<Row>
<Col>
<Form.Label>Upload Product Image</Form.Label>
<Form.File
id="image-file"
size="sm"
custom
variant="secondary"
onChange={uploadFileHandler}
></Form.File>
</Col>
<Col>
{uploading && <Loader />}
{!uploading && imageSrc && (
<img
src={imageSrc}
className={'m-2'}
width={100}
height={100}
alt="product"
/>
)}
</Col>
</Row>
</Form.Group>

<Form.Group className="my-3" controlId="imageAlt">
<Form.Label>Image Alt</Form.Label>
Expand Down
28 changes: 14 additions & 14 deletions frontend/src/screens/ProductListScreen.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect } from 'react'
import { LinkContainer } from 'react-router-bootstrap'
import { Table, Button, Row, Col,ButtonGroup} from 'react-bootstrap'
import { Table, Button, Row, Col, ButtonGroup } from 'react-bootstrap'
import { useDispatch, useSelector } from 'react-redux'
import Message from '../components/Message'
import Loader from '../components/Loader'
Expand Down Expand Up @@ -97,20 +97,20 @@ const ProductListScreen = ({ history, match }) => {
<td>{formatter(product.price)}</td>
<td>{product.category}</td>
<td>
<ButtonGroup>
<LinkContainer to={`/admin/product/${product._id}/edit`}>
<Button variant="light" className="btn-sm m-2 mt-0">
<i className="fas fa-edit"></i>
<ButtonGroup>
<LinkContainer to={`/admin/product/${product._id}/edit`}>
<Button variant="light" className="btn-sm m-2 mt-0">
<i className="fas fa-edit"></i>
</Button>
</LinkContainer>
<Button
variant="danger"
className="btn-sm m-2 mt-0"
onClick={() => deleteHandler(product._id)}
>
<i className="fas fa-trash"></i>
</Button>
</LinkContainer>
<Button
variant="danger"
className="btn-sm m-2 mt-0"
onClick={() => deleteHandler(product._id)}
>
<i className="fas fa-trash"></i>
</Button>
</ButtonGroup>
</ButtonGroup>
</td>
</tr>
))}
Expand Down
18 changes: 12 additions & 6 deletions frontend/src/screens/ProfileScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,22 @@ const ProfileScreen = ({ location, history }) => {
<td>
{order.isPaid ? (
order.paidAt.substring(0, 10)
) : (
<i className="fas fa-times" style={{ color: 'red' }}></i>
)}
) : (
<i
className="fas fa-times"
style={{ color: 'red' }}
></i>
)}
</td>
<td>
{order.isDelivered ? (
order.deliveredAt.substring(0, 10)
) : (
<i className="fas fa-times" style={{ color: 'red' }}></i>
)}
) : (
<i
className="fas fa-times"
style={{ color: 'red' }}
></i>
)}
</td>
<td>
<LinkContainer to={`/order/${order._id}`}>
Expand Down
26 changes: 13 additions & 13 deletions frontend/src/screens/UsersListScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ const UsersListScreen = ({ history }) => {
)}
</td>
<td>
<ButtonGroup>
<LinkContainer to={`/admin/user/${user._id}/edit`}>
<Button variant="light" className="btn-sm m-2 mt-0">
<i className="fas fa-edit"></i>
<ButtonGroup>
<LinkContainer to={`/admin/user/${user._id}/edit`}>
<Button variant="light" className="btn-sm m-2 mt-0">
<i className="fas fa-edit"></i>
</Button>
</LinkContainer>
<Button
variant="danger"
className="btn-sm m-2 mt-0"
onClick={() => deleteHandler(user._id)}
>
<i className="fas fa-trash"></i>
</Button>
</LinkContainer>
<Button
variant="danger"
className="btn-sm m-2 mt-0"
onClick={() => deleteHandler(user._id)}
>
<i className="fas fa-trash"></i>
</Button>
</ButtonGroup>
</ButtonGroup>
</td>
</tr>
))}
Expand Down

0 comments on commit c6b006b

Please sign in to comment.