-
Notifications
You must be signed in to change notification settings - Fork 16
Lkebalik #15
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
base: main
Are you sure you want to change the base?
Lkebalik #15
Conversation
|
Nice , lanjutkan Week4 nya bro. kalo kesusahan bisa chat aja di channel phase 1 yaa |
zexoverz
left a comment
There was a problem hiding this 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
| 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' | ||
| ), | ||
| }), | ||
| }; | ||
|
|
There was a problem hiding this comment.
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
| 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; | ||
| } |
There was a problem hiding this comment.
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
|
Nice Inventory system, untuk deleting ordernya bisa di refactor pake cascade. sisanya aman boleh lanjut week5 (testing dan documentation) |
| // 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'); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
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
zexoverz
left a comment
There was a problem hiding this 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 :)
zexoverz
left a comment
There was a problem hiding this 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
No description provided.