Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: 2 # use CircleCI 2.0
jobs:
build:
working_directory: ~/new-ecommerce # directory where steps will run
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ecommerce

docker: # run the steps with Docker
- image: circleci/node:14.0 # ...with this image as the primary container; this is where all `steps` will run
steps: # a collection of executable commands
- checkout # special step to check out source code to working directory
- run:
name: update-npm
command: 'sudo npm install -g npm@latest'
- restore_cache: # special step to restore the dependency cache
# Read about caching dependencies: https://circleci.com/docs/2.0/caching/
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: install-dependencies
command: npm install
- save_cache: # special step to save the dependency cache
key: dependency-cache-{{ checksum "package.json" }}
paths:
- ./node_modules
- add_ssh_keys:
fingerprints:
- "2c:18:35:24:5d:a5:96:8f:e9:c8:b4:5c:8f:cc:21:94"
- deploy:
name: deployment
command: ssh -o "StrictHostKeyChecking no" root@68.183.90.186 " cd new-ecommerce && git pull https://github.com/Sagar2177/devsnest-ecommerce-app.git features && sh deployment.sh "
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
# Keep environment variables out of version control
.env
.DS_Store
4 changes: 4 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('dotenv').config();

const config = {
postgresUrl: process.env["DATABASE_URL"] || 'postgres://postgres:password@localhost:5432/mydb',
twilio: {
Expand All @@ -7,4 +9,6 @@ const config = {
}
}

//tet

module.exports = config;
2 changes: 1 addition & 1 deletion controllers/otp.controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { sendSMS} = require("../services/sms.service");

const createOtp = async (req, res) => {
const otp = '1122';
const otp = '1122 - testing ';
const someuser = "+919415751180";

await sendSMS("OTP is " + otp, someuser);
Expand Down
38 changes: 36 additions & 2 deletions controllers/product.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,34 @@ const createProduct = async (req, res) => {
}
}
const getProducts = async (req, res) => {
const { limit = 10, offset = 0, sortBy,
sortOrder, search} = req.query;
console.log(`limit: ${limit} & offset: ${offset}`);
try {
const resp = await prisma.product.findMany({})
// const resp = await prisma.product.findMany({
// skip: parseInt(offset),
// take: parseInt(limit),
// }
const query = {
skip: parseInt(offset),
take: parseInt(limit),
}

if (sortBy && sortOrder) {
query['orderBy'] = {
[sortBy]: sortOrder,
}
}
if (search) {
query['where'] = {
description: {
search: search
}
}
}
const resp = await prisma.product.findMany(query);


res.status(200).json({ msg: "Success", data: resp});
} catch (err) {
console.log(err);
Expand All @@ -47,4 +73,12 @@ const getProducts = async (req, res) => {

module.exports = {
createProduct, getProducts
};
};

// sql injection

// const query = `select * from products
// limit ${limit}
// offset ${offset}
// order by ${sortBy} ${sortOrder}
// `
37 changes: 37 additions & 0 deletions controllers/user.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const { createUser } = require('../services/user.service');

const login = () => {

}

const signUp = async (req, res) => {
const {
name, email, password, confirmPassword, phoneNumber,
dob
} = req.body;

// name, email, password, confirmPassword
// and phone number are present
if (!(name && email && password && confirmPassword
&& phoneNumber)) {
res.status(400).json({ msg: "Insufficient Information"})
}
// password and confirm password are same
if (password!==confirmPassword) {
res.status(400).json({ msg: "Passwords don't match"});
}

try {
await createUser({name, email, password,
phoneNumber, dob});
res.status(201).json({ msg: "Successfully Signed Up"});
} catch (err) {
console.log(err.stack);
res.status(500).json({ msg: "Something Failed!"});
}
};

module.exports = {
login,
signUp
};
10 changes: 10 additions & 0 deletions deployment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
echo ‘installing requirements…’
apt-get install -y npm
npm install
echo ‘start server…’

pm2 restart index

echo ‘started server. ending SSH session..’
exit
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const express = require('express')
const { createSeller, getSellers } = require('./controllers/seller.controller')
const { createProduct, getProducts } = require('./controllers/product.controller');
const { createOtp } = require('./controllers/otp.controller')
const { signUp, login } = require('./controllers/user.controller');

const bodyParser = require('body-parser');
const cors = require('cors');

Expand All @@ -27,6 +29,9 @@ app.get('/products', getProducts);

app.post('/otp', createOtp);

app.post('/auth/signup', signUp);
app.post('/auth/login', login);

app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
Loading