-
Notifications
You must be signed in to change notification settings - Fork 16
Dodo #6
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?
Dodo #6
Conversation
| const createOrderItem = async (orderItemBody) => { | ||
| const order = await prisma.product.findUnique({ | ||
| where:{ | ||
| id: orderItemBody.orderId | ||
| } | ||
| }) | ||
|
|
||
| const product = await prisma.product.findUnique({ | ||
| where:{ | ||
| id: orderItemBody.productId | ||
| } | ||
| }) | ||
|
|
||
|
|
||
| if(!order) throw new ApiError(httpStatus.NOT_FOUND, 'Order ID not found') | ||
| if(!product) throw new ApiError(httpStatus.NOT_FOUND, 'Product ID not found') | ||
| if(orderItemBody.quantity > product.quantityInStock) throw new ApiError (httpStatus.BAD_REQUEST, `Order quantity exceed product stock. Current product stock is ${product.quantityInStock}`) | ||
|
|
||
| await prisma.product.update({ | ||
| where:{ | ||
| id: product.id | ||
| }, | ||
| data: product.quantityInStock - orderItemBody.quantity | ||
| }) | ||
|
|
||
|
|
||
| return prisma.orderItem.create({ | ||
| data: orderItemBody | ||
| }); | ||
| }; | ||
|
|
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, Handle quantity stock ini MVP challange nya di IS. mantep progressnya do
| const getUsers = async (filters, options) => { | ||
| const {name,role,email} = filters | ||
| const {take, skip} = options | ||
|
|
||
| return prisma.user.findMany({ | ||
| where:{ | ||
| name:{ | ||
| contains: name, | ||
| }, | ||
| role:{ | ||
| contains: role | ||
| }, | ||
| email:{ | ||
| contains:email | ||
| }}, | ||
| take: take && parseInt(take), | ||
| skip: skip && parseInt(skip), | ||
| orderBy:{ | ||
| name: 'asc' | ||
| } | ||
| }); | ||
| }; |
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, diinget terus ya do konsep pagination. ini konsep kepake banget pas kerja jadi BE
| const authAdmin = () => async (req,res,next) => { | ||
| return new Promise((resolve, reject) =>{ | ||
| passport.authenticate('jwt', {session: false}, verifyCallback(req, resolve, reject))(req,res,next); | ||
| }) | ||
| .then(() => { | ||
| const user = req.user | ||
| if(user.role === 'admin'){ | ||
| next() | ||
| }else{ | ||
| throw new ApiError(httpStatus.FORBIDDEN, "This role doesn't has access") | ||
| } | ||
| }) | ||
| .catch((err) => next(err)) | ||
| } | ||
|
|
||
| module.exports = { | ||
| auth, | ||
| authAdmin | ||
| } |
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.
mantepp authorization, kalau udah bisa bedain authenticate sama authorization. Skill BE lu udah Oke banget. ini konsep juga penting banget 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.
Week4 Approve ya do, congratss challangenya kelar semua. lanjut week5 ya di testing sama deployment. kalo ada problem bisa langsung tanya gua aja di channel. gua udh mulai aktif lagi
|
reviewed, lanjutin do testing nya. gaskann |
|
Congrats Dodo, selamat atas kelulusannya di phase 1 🔥 🔥 🔥 overall nilai lu di phase 1 ada di angka 86%, penilaian ini base on: Review: untuk open gate phase 2 nanti di umumin jadwalnya, standby aja. Untuk mengisi liburan , bisa explore backend lagi kalau tertarik mau jadi backend developer :
|
No description provided.