forked from UitsHabib/shop-on
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
253 changed files
with
2,311 additions
and
355 deletions.
There are no files selected for viewing
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
BIN
+3.78 KB
.yarn/cache/buffer-equal-constant-time-npm-1.0.1-41826f3419-80bb945f5d.zip
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
BIN
+5.75 KB
.yarn/cache/console-control-strings-npm-1.1.0-e3160e5275-8755d76787.zip
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
BIN
+3.32 KB
.yarn/cache/is-fullwidth-code-point-npm-3.0.0-1ecf4ebee5-44a30c2945.zip
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|
@@ -50,6 +51,7 @@ async function init() { | |
(admin) => { | ||
const profiles = [ | ||
{ | ||
id: "1da2bb9b-9594-42f4-ae3d-f543756e9430", | ||
title: "System Admin", | ||
slug: "system-admin", | ||
type: 'standard', | ||
|
@@ -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(() => { | ||
|
@@ -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(() => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.