-
Notifications
You must be signed in to change notification settings - Fork 16
Husein #7
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?
Husein #7
Conversation
|
Mohon direview @zexoverz, jika ada kurang maupun tidak sesuai akan saya perbaiki. Terimakasih |
| const queryOrderItems = catchAsync(async (req, res) => { | ||
| const { page, size } = req.query; | ||
| const orderItem = await orderItemService.getOrderItems(parseInt(page), parseInt(size)); | ||
|
|
||
| if (!orderItem) throw new ApiError(httpStatus.NOT_FOUND, 'Order Items not found'); | ||
|
|
||
| res.status(httpStatus.OK).send({ | ||
| status: httpStatus.OK, | ||
| message: 'Get All Order Item Success', | ||
| data: orderItem, | ||
| }); | ||
| }); |
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 pagination, tetep ingat terus ya konsep pagination nya. bakal kepake banget pas kerja jadi BE nanti
| const createOrderItem = async (reqBody) => { | ||
| const orderItem = await prisma.orderItem.create({ | ||
| data: reqBody, | ||
| }); | ||
|
|
||
| const totalPrice = await prisma.order.update({ | ||
| where: { | ||
| id: reqBody.orderId, | ||
| }, | ||
| data: { | ||
| totalPrice: reqBody.unitPrice * reqBody.quantity, | ||
| }, | ||
| }); | ||
|
|
||
| const jumlahBarang = await prisma.product.findUnique({ | ||
| where: { | ||
| id: reqBody.productId, | ||
| }, | ||
| }); | ||
|
|
||
| const updateQuantiyProudct = await prisma.product.update({ | ||
| where: { | ||
| id: reqBody.productId, | ||
| }, | ||
| data: { | ||
| quantityInStock: jumlahBarang.quantityInStock - reqBody.quantity, | ||
| }, | ||
| }); | ||
|
|
||
| return orderItem; | ||
| }; | ||
|
|
||
| const updateOrderItem = async (orderItemId, updateBody) => { | ||
| const orderItem = prisma.orderItem.update({ | ||
| where: { | ||
| id: orderItemId, | ||
| }, | ||
| data: updateBody, | ||
| }); | ||
|
|
||
| const totalPrice = await prisma.order.update({ | ||
| where: { | ||
| id: updateBody.orderId, | ||
| }, | ||
| data: { | ||
| totalPrice: updateBody.unitPrice * updateBody.quantity, | ||
| }, | ||
| }); | ||
|
|
||
| const jumlahBarang = await prisma.product.findUnique({ | ||
| where: { | ||
| id: updateBody.productId, | ||
| }, | ||
| }); | ||
|
|
||
| const updateQuantiyProudct = await prisma.product.update({ | ||
| where: { | ||
| id: updateBody.productId, | ||
| }, | ||
| data: { | ||
| quantityInStock: jumlahBarang.quantityInStock - updateBody.quantity, | ||
| }, | ||
| }); | ||
|
|
||
| return orderItem; | ||
| }; |
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 OrderItem Logic, Challange Success. ini Core nya IS. ngatur product quantity ketika order.
| const authAdmin = () => async (req, res, next) => { | ||
| return new Promise((resolve, reject) => { | ||
| passport.authenticate('jwt', { session: false }, verifyCallback(req, resolve, reject))(req, res, next); | ||
| }) | ||
| .then(() => { | ||
| if (req.user.role === 'admin') { | ||
| return next(); | ||
| } | ||
| throw new ApiError(httpStatus.FORBIDDEN, 'Access Denied'); | ||
| }) | ||
| .catch((err) => next(err)); | ||
| }; |
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 Authorization, udah tau kan berarti cara bedain Authenticate sama Authorization.
Progress skill backend lu jadi level up kalo udh bisa bedain ini.
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.
Week4 done ya Husein, gokil banget progress nya. lanjut week 5 ke testing sama deployment. kalau ada problem bisa tanya gua ya di channel DC. gua udh mulai aktif lagi
|
Congrats Husein, selamat atas kelulusannya di phase 1 🔥 🔥 🔥 overall nilai lu di phase 1 ada di angka 80%, penilaian ini base on: Review: open gate phase 2 nanti di umumin jadwalnya, standby aja. |
|
Sir saya kayaknya gak bakal bisa ngikutin phase 2, karena bakalan banyak presentasikan, laptop saya itu kalau buat presentasi ngelag parah karena ramnya cuma ddr3 dan saya belinya seken sir, yang mungkin udah dari 2015-an laptopnya, tahun rilisnya aja 2010-an Masi pake win7 juga(udah dualboot Linux sih). Maaf sir kayaknya gak bisa ngikutin phase 2. |
No description provided.