Skip to content

Commit

Permalink
Remove conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
HranikBs23 committed Feb 23, 2022
2 parents e06186f + 4ed0ded commit f244051
Show file tree
Hide file tree
Showing 253 changed files with 2,311 additions and 355 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .yarn/install-state.gz
Binary file not shown.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"bcrypt": "^5.0.1",
"cloudinary": "^1.28.1",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"formidable": "^2.0.1",
Expand Down
14 changes: 8 additions & 6 deletions seeder.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async function init() {
User.findOrCreate({
where: { email: "[email protected]" },
defaults: {
id: "479753f6-dfeb-47da-abf4-6b41332842a0",
first_name: "System",
last_name: "Admin",
password: "P@ssword123",
Expand All @@ -50,6 +51,7 @@ async function init() {
(admin) => {
const profiles = [
{
id: "1da2bb9b-9594-42f4-ae3d-f543756e9430",
title: "System Admin",
slug: "system-admin",
type: 'standard',
Expand Down Expand Up @@ -92,11 +94,11 @@ async function init() {
function serviceSeeder(callback) {
User.findOne({ where: { email: '[email protected]' } }).then(admin => {
const services = [
{ title: "Management of Platform", slug: "platform-management", created_by: admin.id, updated_by: admin.id },
{ title: "Manage Users", slug: "manage-users", description: 'Manage CDP users', created_by: admin.id, updated_by: admin.id },
{ title: "Manage Profiles", slug: "manage-profiles", description: 'Manage user profiles', created_by: admin.id, updated_by: admin.id },
{ title: "Manage Roles", slug: "manage-roles", description: 'Manage user roles', created_by: admin.id, updated_by: admin.id },
{ title: "Manage Permissions", slug: "manage-permissions", description: 'Assign rights to Permission', created_by: admin.id, updated_by: admin.id },
{ id: "6f8cb12c-c3a6-44c6-b1af-9f0a6c8cb401", title: "Management of Platform", slug: "platform-management", created_by: admin.id, updated_by: admin.id },
{ id: "79f26ef2-52f9-429e-b4bf-c307aa0a6040", title: "Manage Users", slug: "manage-users", description: 'Manage CDP users', created_by: admin.id, updated_by: admin.id },
{ id: "7ae9a3ba-132e-407b-8b0f-bc31bd8b52c1", title: "Manage Profiles", slug: "manage-profiles", description: 'Manage user profiles', created_by: admin.id, updated_by: admin.id },
{ id: "6d1d48c5-565c-4b3b-b4f5-5ad424070333", title: "Manage Roles", slug: "manage-roles", description: 'Manage user roles', created_by: admin.id, updated_by: admin.id },
{ id: "bd690286-de0a-416d-9d04-fda113fb9366", title: "Manage Permissions", slug: "manage-permissions", description: 'Assign rights to Permission', created_by: admin.id, updated_by: admin.id },
];

Service.destroy({ truncate: { cascade: true } }).then(() => {
Expand All @@ -113,7 +115,7 @@ async function init() {
function permissionSeeder(callback) {
User.findOne({ where: { email: '[email protected]' } }).then(admin => {
const permission = [
{ title: "System Admin Permission", slug: "system-admin", type: 'standard', description: "This is the default permission set for System Admin", created_by: admin.id, updated_by: admin.id },
{ id: "bffd87d0-3843-4e5f-b564-0edf6b208149", title: "System Admin Permission", slug: "system-admin", type: 'standard', description: "This is the default permission set for System Admin", created_by: admin.id, updated_by: admin.id },
];

Permission.destroy({ truncate: { cascade: true } }).then(() => {
Expand Down
11 changes: 11 additions & 0 deletions src/config/lib/express.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require("path");
const express = require("express");
const cookieParser = require("cookie-parser");
const cors = require('cors');
const config = require('../config');
const nodecache = require('./nodecache');

Expand All @@ -11,6 +12,16 @@ module.exports = async function () {
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

const corsOptions = {
credentials: true,
origin: (origin, callback) => {
return callback(null, true);

callback(new Error('Not allowed by CORS'));
}
};
app.use(cors(corsOptions));

app.set('port', process.env.PORT);

const globalConfig = config.getGlobalConfig();
Expand Down
70 changes: 70 additions & 0 deletions src/modules/cart/cart.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const path = require('path');
const Cart = require('./cart.model');
const User = require(path.join(process.cwd(), "src/modules/user/user.model"));
const Product = require(path.join(process.cwd(), "src/modules/product/product.model"));

const getCartByUser = async (req, res) => {
try {
const cart = await Cart.findOne({
where: {
user_id
}
});
if (cart === null) res.send([])

const cartDetails = cart.dataValues;

const quantities = [];

const productId = cartDetails.cart_items.map(item => {
quantities.push(item.qty);
return item.product_id;
});

let products = await Products.findAll({
where: { product_id: productId }
});

let arrayOfObjects = [];
products.forEach((item, index) => {
let obj = { ...item };
obj["qty"] = quantities[index];
arrayOfObjects.push(obj);
});

res.send(arrayOfObjects);

} catch (err) {
console.error(err);
res.status(500).send("Internal server error!");
}
};

const addToCart = async (req, res) => {
Cart.findOne({
where: {
user_id: req.body.user_id
}
}).then(user => {
if (user) {
Cart.destroy({
where: {
user_id: req.body.user_id
}
}).then(c => {
if (req.body.cart_items.length > 0) {
Cart.create(req.body)
.then(res.send("Inserted in Cart Successfully"));
} else res.send("Cart is Empty!");
});
} else {
if (req.body.cart_items.length > 0) {
Cart.create(req.body)
.then(res.send("Inserted in Cart Successfully"));
} else res.send("Cart is Empty!");
}
});
}

module.exports.getCartByUser = getCartByUser;
module.exports.addToCart = addToCart;
34 changes: 34 additions & 0 deletions src/modules/cart/cart.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const path = require("path");
const sequelize = require(path.join(process.cwd(), "src/config/lib/sequelize"));
const { DataTypes } = require("sequelize");
const Product = require(path.join(process.cwd(), "src/modules/product/product.model"));

const Cart = sequelize.define("carts", {
id: {
allowNull: false,
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
},
customer_id: {
allowNull: false,
type: DataTypes.UUID,
},
product_id: {
allowNull: false,
type: DataTypes.UUID,
},
quantity: {
allowNull: false,
type: DataTypes.INTEGER,
}
}, {
tableName: "carts",
timestamps: true,
createdAt: "created_at",
updatedAt: "updated_at",
});

Cart.belongsTo(Product, { as: 'product', foreignKey: 'product_id' });

module.exports = Cart;
18 changes: 18 additions & 0 deletions src/modules/cart/cart.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const path = require("path");
const controller = require("./cart.controller");
const validate = require(path.join(
process.cwd(),
"src/modules/core/middlewares/validate"
));

module.exports = (app) => {
app
.route("/api/carts/users/:userId")
.post(controller.addToCart);

app
.route("/api/cart/:id/users/:userId")
.get(controller.getCartByUser)
// .patch(controller.patchProduct)
// .delete(controller.deleteProduct);
};
Empty file added src/modules/cart/cart.schema.js
Empty file.
Loading

0 comments on commit f244051

Please sign in to comment.