Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue of fixing all related to the roles #105

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
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
1 change: 0 additions & 1 deletion src/controllers/products/productController.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ cron.schedule('30 17 * * *', async () => {
}
}
});
console.log(`=========${todayWithTimeZone}=========`);
for (const product of expiredProducts) {
product.status = 'UNAVAILABLE';
await product.save();
Expand Down
10 changes: 1 addition & 9 deletions src/controllers/shoppingCartController/addToCartController.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,6 @@ export const viewCart = asyncWrapper(async (req, res) => {
message: req.t('cart_already_empty'),
});
}
console.log(`===================> ${cart}==================`);

// console.log(`===================> ${cartProduct}==================`);
// cartProduct.forEach((cart) => {
// const product = db.ProductAttribute.findOne({
// where: {}
// })
// })

res.status(200).json({
status: req.t('success'),
Expand All @@ -168,7 +160,7 @@ export const pay = asyncWrapper(async (req, res) => {
exp_year: exp_year,
cvc: cvcNumber,
};
console.log(card);

const paymentMethod = await stripe.paymentMethods.create({
type: 'card',
card,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { getCarts, CalculateTotalPrice } from '../../utils/getCartsHandler';

export const updateCart = asyncWrapper(async (req, res) => {
const { id, quantity } = req.body;
// console.log('Hello id',id);
const buyerId = req.user.id;
const cart = await getCarts(buyerId)
if (!cart)
Expand Down Expand Up @@ -35,7 +34,6 @@ export const updateCart = asyncWrapper(async (req, res) => {
});
const newCart = await getCarts(buyerId);
const totalPrice = CalculateTotalPrice(newCart);
console.log('Hello total', totalPrice);
res.status(201).json({
status: req.t('success'),
message: req.t('cart_item_updated'),
Expand Down
7 changes: 3 additions & 4 deletions src/controllers/users/adminControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const createAdmin = asyncWrapper(async (req, res) => {
req.body;

const hashedPassword = await hashPassword(password);
let newRole = await db.role.create({
let newRole = await db.role.findOne({
Copy link

Choose a reason for hiding this comment

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

Delete ·· prettier/prettier

name: 'admin',
});
while(!newRole){
Expand Down Expand Up @@ -38,7 +38,7 @@ export const getAllUsers =asyncWrapper(async (req, res) => {
attributes: { exclude: ['password', 'roleId'] },
include: {
model: db.role,
attributes: ['name'],
attributes: ['name', 'id'],
include: {
model: db.permission,
attributes: { exclude: ['id'] },
Expand All @@ -60,13 +60,12 @@ export const deleteUsers =asyncWrapper(async (req, res) => {
});
});
export const getSingleUser =asyncWrapper(async (req, res) => {
console.log(req.params.id);
const singleUser = await db.user.findAll({
where: { id: req.params.id },
attributes: { exclude: ['password', 'roleId'] },
include: {
model: db.role,
attributes: ['name'],
attributes: ['name', 'id'],
include: {
model: db.permission,
attributes: { exclude: ['id'] },
Expand Down
10 changes: 5 additions & 5 deletions src/database/models/role.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ module.exports = (sequelize, DataTypes) => {
*/
static associate(models) {
// define association here
role.hasMany(models.user, { foreignKey: 'roleId'});
role.belongsToMany(models.permission, {
through: models.rolePermission,
});
role.hasMany(models.user, { foreignKey: 'roleId' });
role.belongsToMany(models.permission, {
through: models.rolePermission,
});
}
}
role.init(
{
name: { allowNull: false, type: DataTypes.STRING },
name: { allowNull: false, type: DataTypes.STRING, unique: true },
},
{
sequelize,
Expand Down