Skip to content

Conversation

@mhaatha
Copy link

@mhaatha mhaatha commented Jan 13, 2024

No description provided.

@zexoverz
Copy link
Contributor

Nice , lanjutkan Week4 nya bro. kalo kesusahan bisa chat aja di channel phase 1 yaa

Copy link
Contributor

@zexoverz zexoverz left a comment

Choose a reason for hiding this comment

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

Nice ODM, yang penting tau cara pake mongodb aja udah cukup sebenernya. itu bekel misal nanti kalo kerja di perusahaan NO SQL. lanjutin week4 nya

Comment on lines 16 to 34
const queryCategorys = {
query: Joi.object().keys({
skip: Joi.number().integer().min(0),
take: Joi.number().integer().min(1),
id: Joi.string().custom(objectId),
name: Joi.string(),
createdAt: Joi.date(),
updatedAt: Joi.date(),
orderBy: Joi.string().valid(
'name:asc',
'name:desc',
'createdAt:asc',
'createdAt:desc',
'updatedAt:asc',
'updatedAt:desc'
),
}),
};

Copy link
Contributor

Choose a reason for hiding this comment

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

gua suka orderBy nya pake valid bawaan joi. jadinya string yang di input user harus sesuai asc atau desc.
lebih presisi. good job

Comment on lines 43 to 56
const deleted = async (id) => {
const orderItem = await getId(id);
if (!orderItem) {
throw new ApiError(httpStatus.NOT_FOUND, 'Order Item not found');
}

const deleteOrderItem = await prisma.orderItem.delete({
where: {
id: id,
},
});

return deleteOrderItem;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

sebenrnya pas orderItem di delete ga perlu delete OrderItemnya lewat service gini.

di prisma schema bisa pasang option OnDelete [cascade] di relasi order sama orderItemnya.

itu kalo order kedelete, otomatis anakan orderItemnya kedelete semua

@zexoverz
Copy link
Contributor

zexoverz commented Feb 7, 2024

Nice Inventory system, untuk deleting ordernya bisa di refactor pake cascade. sisanya aman

boleh lanjut week5 (testing dan documentation)

Comment on lines +72 to +134
// Update quantityInStock in Product table & price in Order table
const product = await prisma.product.findFirst({
where: {
id: orderItem.productId,
},
});
const order = await prisma.orders.findFirst({
where: {
id: orderItem.orderId,
},
});

const quantityUpdate = update.quantity || 0;
const quantityNow = orderItem.quantity;
let quantityTotal = quantityUpdate - quantityNow;
// quantityInStock in Product table
const quantityProduct = product.quantityInStock;
// Logic to handle quantityInStock value
if (quantityUpdate > 0) {
if (quantityProduct > quantityUpdate) {
if (quantityTotal <= 0) {
// If quantity decreasing
quantityTotal = Math.abs(quantityTotal);
const updateProduct = await prisma.product.update({
where: {
id: orderItem.productId,
},
data: {
quantityInStock: quantityProduct + quantityTotal,
},
});
const updateOrder = await prisma.orders.update({
where: {
id: orderItem.orderId,
},
data: {
totalPrice: order.totalPrice - orderItem.unitPrice * quantityTotal,
},
});
} else {
// If quantity increasing
const updateProduct = await prisma.product.update({
where: {
id: orderItem.productId,
},
data: {
quantityInStock: quantityProduct - quantityTotal,
},
});
const updateOrder = await prisma.orders.update({
where: {
id: orderItem.orderId,
},
data: {
totalPrice: order.totalPrice + orderItem.unitPrice * quantityTotal,
},
});
}
} else {
throw new ApiError(httpStatus.BAD_REQUEST, 'Order quantity exceeds available stock');
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

woww, nice catch cuy. ini logic quantity di IS. sebenernya ini ga wajib, tapi kalo lu bisa buat nya lu keren sih.
ini salah satu challange di IS yang berguna banget buat di kerjaan

Copy link
Contributor

@zexoverz zexoverz left a comment

Choose a reason for hiding this comment

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

okee authorizationnya juga udah kelar. bisa lanjut testing dan deploy sih di week5.

btw GWS bro, semoga bisa semuh dan ikut belajar lagi di RPN :)

Copy link
Contributor

@zexoverz zexoverz left a comment

Choose a reason for hiding this comment

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

Documentation Approved, sorry baru review. lu juga udah GP ya. raport langsung gua taro sini aja

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants