Skip to content

Commit

Permalink
Merge branch 'master' into feature/customer
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaniz-ifte committed Feb 27, 2022
2 parents 800b152 + 492b151 commit 8afe107
Show file tree
Hide file tree
Showing 224 changed files with 1,988 additions and 3,869 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 removed .yarn/cache/depd-npm-1.1.2-b0c8414da7-6b406620d2.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 removed .yarn/cache/etag-npm-1.8.1-54a3b989d9-571aeb3dbe.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 removed .yarn/cache/ip-npm-1.1.5-af36318aa6-30133981f0.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 removed .yarn/cache/jwa-npm-1.4.1-4f19d6572c-ff30ea7c2d.zip
Binary file not shown.
Binary file removed .yarn/cache/jws-npm-3.2.2-c1ae59c7af-f0213fe5b7.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 removed .yarn/cache/long-npm-4.0.0-ecd96a31ed-16afbe8f74.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 removed .yarn/cache/mime-npm-1.6.0-60ae95038a-fef25e3926.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 removed .yarn/cache/ms-npm-2.0.0-9e1101a471-0e6a22b8b7.zip
Binary file not shown.
Binary file removed .yarn/cache/ms-npm-2.1.2-ec0c1512ff-673cdb2c31.zip
Binary file not shown.
Binary file removed .yarn/cache/ms-npm-2.1.3-81ff3cfac1-aa92de6080.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 removed .yarn/cache/nopt-npm-5.0.0-304b40fbfe-d35fdec187.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/once-npm-1.4.0-ccf03ef07a-cd0a885013.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 removed .yarn/cache/tr46-npm-0.0.3-de53018915-726321c5ea.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 removed .yarn/cache/uuid-npm-8.3.2-eca0baba53-5575a8a75c.zip
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/vary-npm-1.1.2-b49f70ae63-ae0123222c.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/wkx-npm-0.5.0-fca5152cd8-47b27387de.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 removed .yarn/install-state.gz
Binary file not shown.
1,936 changes: 0 additions & 1,936 deletions package-lock.json

This file was deleted.

3 changes: 2 additions & 1 deletion seeder.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ async function init() {
require(path.join(process.cwd(), 'src/modules/order/order-product.model'));
require(path.join(process.cwd(), 'src/modules/order/order.model'));
require(path.join(process.cwd(), 'src/modules/cart/cart.model'));
require(path.join(process.cwd(), 'src/modules/review/review.model'));
require(path.join(process.cwd(), 'src/modules/review/product-review.model'));
require(path.join(process.cwd(), 'src/modules/review/shop-review.model'));

await sequelize.sync();

Expand Down
Empty file removed src/modules/cart/cart.schema.js
Empty file.
3 changes: 3 additions & 0 deletions src/modules/category/category.model.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require("path");
const sequelize = require(path.join(process.cwd(), 'src/config/lib/sequelize'));
const Product = require(path.join(process.cwd(), 'src/modules/product/product.model'));
const { DataTypes } = require('sequelize');
const SubCategory = require('./sub-category.model');

Expand All @@ -24,4 +25,6 @@ const Category = sequelize.define('categories', {
Category.hasMany(SubCategory, { as: 'subCategories', foreignKey: 'category_id' });
SubCategory.belongsTo(Category, { as: 'category', foreignKey: 'category_id' });

Product.belongsTo(Category, { as: 'category', foreignKey: 'category_id' });

module.exports = Category;
1 change: 1 addition & 0 deletions src/modules/core/authorization/authorization.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const Services = {
MANAGE_ROLE: "manage-roles",
MANAGE_SHOP: "manage-shop",
MANAGE_CLIENT: "manage-client",
MANAGE_REVIEW: "manage-review"
};

module.exports = { Services };
85 changes: 58 additions & 27 deletions src/modules/customer/customer.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async function login(req, res) {
try {
const { email, password } = req.body;

const customer = await Customer.findOne({ where: { email }});
const customer = await Customer.findOne({ where: { email } });

if (!customer || !customer.password || !customer.validPassword(password)) return res.status(400).send("Invalid email or password!");

Expand Down Expand Up @@ -52,9 +52,9 @@ const registerCustomer = async (req, res) => {
}
};

async function getSignedInCustomerProfile (req, res) {
async function getSignedInCustomerProfile(req, res) {
try {
const customer = await Customer.findOne({ where: { id: req.user.id }});
const customer = await Customer.findOne({ where: { id: req.user.id } });

if (!customer) return res.status(404).send("Customer not found!");

Expand All @@ -65,17 +65,17 @@ async function getSignedInCustomerProfile (req, res) {
}
}

async function updateSignedInCustomerProfile (req, res) {
async function updateSignedInCustomerProfile(req, res) {
try {
const { first_name, last_name, username, email, phone } = req.body;

const customer = await Customer.findOne({ where: { id: req.user.id }});
const customer = await Customer.findOne({ where: { id: req.user.id } });

if (!customer) return res.status(404).send("Customer not found!");

await customer.update({ first_name, last_name, username, email, phone });

if(req.file?.path) {
if (req.file?.path) {
const file_url = await cloudinary.uploader.upload(req.file.path);
await customer.update({ avatar_url: file_url.secure_url });
}
Expand All @@ -87,63 +87,63 @@ async function updateSignedInCustomerProfile (req, res) {
}
}

async function getOrders (req, res) {
async function getOrders(req, res) {
try {
const orders = await Order.findAll({
where: { customer_id: req.user.id },
include: [{
model: OrderProduct,
as: "order_products",
attributes: ["id"],
attributes: ["id"],
include: [{
model: Product,
as: "product",
attributes: ["id", "name", "price"],
include: [{
model: Shop,
as: 'shop'
}]
}]
}]
}]
});

res.status(200).send(orders);

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

async function getOrder (req, res) {
async function getOrder(req, res) {
try {
const order = await Order.findOne({
where: { id: req.params.id },
include: [{
model: OrderProduct,
as: "order_products",
attributes: ["id"],
attributes: ["id"],
include: [{
model: Product,
as: "product",
attributes: ["id", "name", "price"],
include: [{
model: Shop,
as: 'shop'
}]
}]
}]
}]
});

res.status(200).send(order);

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

async function createOrder (req, res) {
async function createOrder(req, res) {
try {
const carts = await Cart.findAll({
where: {
Expand Down Expand Up @@ -207,12 +207,12 @@ async function createOrder (req, res) {
}
}

async function addToCart (req, res) {
async function addToCart(req, res) {
try {
const { product_id, quantity } = req.body;

const [cart, created] = await Cart.findOrCreate({
where: {
where: {
customer_id: req.user.id,
product_id
},
Expand All @@ -223,7 +223,7 @@ async function addToCart (req, res) {
},
});

if(cart) await cart.update({ quantity });
if (cart) await cart.update({ quantity });

res.status(201).send((cart || created));
}
Expand All @@ -233,11 +233,11 @@ async function addToCart (req, res) {
}
}

async function getCart (req, res) {
async function getCart(req, res) {
try {
const cart = await Cart.findAll({
where: {
customer_id: req.user.id
const cart = await Cart.findAll({
where: {
customer_id: req.user.id
},
include: [{
model: Product,
Expand All @@ -246,7 +246,7 @@ async function getCart (req, res) {
include: [{
model: Shop,
as: 'shop'
}]
}]
}]
});

Expand All @@ -258,6 +258,36 @@ async function getCart (req, res) {
}
}

async function deleteFromCart(req, res) {
try {

const cart = await Cart.findOne({
where: {
customer_id: req.user.id
},
include: [
{
model: Product,
as: 'product'
}
]
});

await Cart.destroy({
where: {
customer_id: req.user.id
}
});
if (cart) await cart.update({ quantity });
res.status(201).send(('cart updated '));

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

}

module.exports.login = login;
module.exports.logout = logout;
module.exports.registerCustomer = registerCustomer;
Expand All @@ -267,4 +297,5 @@ module.exports.getOrders = getOrders;
module.exports.getOrder = getOrder;
module.exports.createOrder = createOrder;
module.exports.addToCart = addToCart;
module.exports.getCart = getCart;
module.exports.getCart = getCart;
module.exports.deleteFromCart = deleteFromCart;
8 changes: 4 additions & 4 deletions src/modules/platform/user/user.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ User.prototype.validPassword = function (password) {
User.belongsTo(User, { as: 'createdByUser', foreignKey: 'created_by' });
User.belongsTo(User, { as: 'updatedByUser', foreignKey: 'created_by' });

Profile.hasMany(User, { as: 'users', foreignKey: 'profile_id' });
User.belongsTo(Profile, { as: 'profile', foreignKey: 'profile_id' });
Profile.hasMany(User, { as: 'users', foreignKey: 'profile_id', constraints: false });
User.belongsTo(Profile, { as: 'profile', foreignKey: 'profile_id', constraints: false });

Profile.belongsTo(User, { as: "createdByUser", foreignKey: "created_by" });
Profile.belongsTo(User, { as: "updatedByUser", foreignKey: "updated_by" });

Role.hasMany(User, { as: 'users', foreignKey: 'role_id' });
User.belongsTo(Role, { as: 'role', foreignKey: 'role_id' });
Role.hasMany(User, { as: 'users', foreignKey: 'role_id', constraints: false });
User.belongsTo(Role, { as: 'role', foreignKey: 'role_id', constraints: false });

Role.belongsTo(User, { as: "createdByUser", foreignKey: "created_by" });
Role.belongsTo(User, { as: "updatedByUser", foreignKey: "updated_by" });
Expand Down
28 changes: 0 additions & 28 deletions src/modules/product/category.model.js

This file was deleted.

8 changes: 2 additions & 6 deletions src/modules/product/product.controller.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const path = require("path");
const Shop = require("../shop/shop.model");
const Product = require("./product.model");
const Category = require("./category.model");

const { getPagination, getPagingData } = require("./services/product.service");

const Product = require(path.join(process.cwd(), "src/modules/product/product.model"));
const Shop = require(path.join(process.cwd(), "src/modules/shop/shop.model"));

async function getProducts(req, res) {
try {
Expand Down
31 changes: 0 additions & 31 deletions src/modules/product/services/product.service.js

This file was deleted.

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

const ProductReview = sequelize.define("product_reviews", {
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
},
rating: {
allowNull: false,
type: DataTypes.INTEGER
},
comment: {
allowNull: false,
type: DataTypes.STRING(500)
}
},
{
tableName: 'product_reviews',
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at'
});

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

module.exports = ProductReview;
Loading

0 comments on commit 8afe107

Please sign in to comment.