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

SLein #10

Open
wants to merge 130 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
7061c88
Added MongoDB Completion
yogiwijaya777 Dec 7, 2023
0da3852
Merge pull request #1 from yogiwijaya777/yogi
yogiwijaya777 Dec 7, 2023
713bb7d
Adding Folder/File Structure
yogiwijaya777 Dec 7, 2023
3490ceb
Complete Todo & User model
yogiwijaya777 Dec 8, 2023
4d700d8
USer Router completed
yogiwijaya777 Dec 8, 2023
a7d7c0c
Todos Router Complete
yogiwijaya777 Dec 8, 2023
a4368ee
Completing Router Index
yogiwijaya777 Dec 8, 2023
7c2f26f
Refactoring Todo Schema
yogiwijaya777 Dec 8, 2023
cb54aa2
Setting up editorconfig
yogiwijaya777 Dec 8, 2023
143ea07
Refactor All Files Following ESLint rules
yogiwijaya777 Dec 8, 2023
ddda428
Adding createTask feature
yogiwijaya777 Dec 14, 2023
c4b430f
Adding Get All Users API
yogiwijaya777 Dec 14, 2023
7c25b21
Adding Get User API
yogiwijaya777 Dec 14, 2023
c76880f
Adding Delete User API
yogiwijaya777 Dec 14, 2023
007f3b7
Adding Update User API
yogiwijaya777 Dec 14, 2023
e41dc7f
Adding TODOS API
yogiwijaya777 Dec 14, 2023
054ae66
Merge pull request #2 from yogiwijaya777/yogi
yogiwijaya777 Dec 14, 2023
e77f2ff
Starting Project fancy-todo-orm
yogiwijaya777 Dec 24, 2023
c94a3a2
Merge pull request #3 from yogiwijaya777/yogi
yogiwijaya777 Dec 24, 2023
b8171b8
Setting up Prisma
yogiwijaya777 Dec 27, 2023
8acfd92
Merge pull request #4 from yogiwijaya777/yogi
yogiwijaya777 Dec 28, 2023
7c74450
Setting up app.js and index.js
yogiwijaya777 Dec 30, 2023
e73a1cd
Adding services file
yogiwijaya777 Dec 30, 2023
75f5571
Setting up todo.service.js
yogiwijaya777 Dec 30, 2023
de3452a
Setting up user.service.js
yogiwijaya777 Dec 30, 2023
f94aa78
Adding controllers file
yogiwijaya777 Dec 30, 2023
0e58e3c
Setting up user controller
yogiwijaya777 Dec 30, 2023
a369921
Setting up todo controller
yogiwijaya777 Dec 30, 2023
c744ac5
Setting up routers
yogiwijaya777 Dec 30, 2023
11c3621
Push todo-fancy-orm
yogiwijaya777 Dec 30, 2023
d2d84b7
Merge pull request #5 from yogiwijaya777/yogi
yogiwijaya777 Dec 30, 2023
fc9c6bb
Adding Code Standarization
yogiwijaya777 Dec 31, 2023
9f9cd74
npx prisma init
yogiwijaya777 Dec 31, 2023
919fa01
Adding Schema onf DB
yogiwijaya777 Dec 31, 2023
dade522
Adding prisma client.js
yogiwijaya777 Dec 31, 2023
001f0b6
Setting up basic server app.js
yogiwijaya777 Dec 31, 2023
3bb6939
Setting up index.js
yogiwijaya777 Dec 31, 2023
7563365
Merge pull request #6 from yogiwijaya777/yogi
yogiwijaya777 Dec 31, 2023
ad34bad
Adding config.js
yogiwijaya777 Jan 2, 2024
45e7d58
setting up loggin system winston
yogiwijaya777 Jan 2, 2024
64cc51e
Setting Up Morgan logging
yogiwijaya777 Jan 2, 2024
4077c25
Merge pull request #7 from yogiwijaya777/yogi
yogiwijaya777 Jan 2, 2024
d486ffb
Setting up ApiError
yogiwijaya777 Jan 3, 2024
1a5d48f
setting up cactchAsync
yogiwijaya777 Jan 3, 2024
2befc4e
setting ap middleware rror.js
yogiwijaya777 Jan 3, 2024
824dd94
Merge pull request #8 from yogiwijaya777/yogi
yogiwijaya777 Jan 3, 2024
26ec787
setting up backend security
yogiwijaya777 Jan 4, 2024
fc90cd9
Merge pull request #9 from yogiwijaya777/yogi
yogiwijaya777 Jan 4, 2024
347855b
Setting ap Auth
yogiwijaya777 Jan 5, 2024
d31b9a2
Merge pull request #10 from yogiwijaya777/yogi
yogiwijaya777 Jan 5, 2024
98a7778
Backend Validation
yogiwijaya777 Jan 6, 2024
437f32f
Merge pull request #11 from yogiwijaya777/yogi
yogiwijaya777 Jan 6, 2024
6fb6906
testing authentication tokes via cookies
yogiwijaya777 Jan 15, 2024
17716ff
queryCategorys
yogiwijaya777 Jan 18, 2024
92dbfed
Merge pull request #12 from yogiwijaya777/yogi
yogiwijaya777 Jan 18, 2024
933f1b6
fix error
yogiwijaya777 Jan 19, 2024
57783f2
Merge pull request #13 from yogiwijaya777/yogi
yogiwijaya777 Jan 19, 2024
3899510
createProduct complete
yogiwijaya777 Jan 20, 2024
f76da86
queryProducts + logic complete
yogiwijaya777 Jan 20, 2024
6b9a42b
setting auth middleware set req.user without password
yogiwijaya777 Jan 20, 2024
493ef80
Merge pull request #14 from yogiwijaya777/yogi
yogiwijaya777 Jan 20, 2024
d49954a
getProductById complete
yogiwijaya777 Jan 20, 2024
b107ce8
getuser complete
yogiwijaya777 Jan 20, 2024
81ed9a3
getproductbyuser complete
yogiwijaya777 Jan 20, 2024
8660d29
refactor getProductByUser
yogiwijaya777 Jan 20, 2024
9dfec45
refactor querys logic
yogiwijaya777 Jan 20, 2024
69b3a86
refactor category and product query logic only show need information
yogiwijaya777 Jan 21, 2024
202ef73
refresh token logic complete
yogiwijaya777 Jan 21, 2024
fd26490
refactor refresh tokens
yogiwijaya777 Jan 21, 2024
025313b
logout API complete
yogiwijaya777 Jan 21, 2024
11b3ce0
Merge pull request #15 from yogiwijaya777/yogi
yogiwijaya777 Jan 21, 2024
4f59d52
createUser API
yogiwijaya777 Jan 21, 2024
dfdd825
getUserById Complete
yogiwijaya777 Jan 21, 2024
66b98d9
updateUser Complete
yogiwijaya777 Jan 21, 2024
3c9c196
deleteUser complete
yogiwijaya777 Jan 21, 2024
e75686e
setup order.validation.js
yogiwijaya777 Jan 21, 2024
4329439
setup orderItem.validation.js
yogiwijaya777 Jan 21, 2024
e92f711
Merge pull request #16 from yogiwijaya777/yogi
yogiwijaya777 Jan 21, 2024
e30afdb
createOrder and getAllOrders complete
yogiwijaya777 Jan 21, 2024
dc22167
createOrder and getAllOrders complete
yogiwijaya777 Jan 21, 2024
1707c9d
getOrder complete
yogiwijaya777 Jan 21, 2024
51e26ed
updateUser complete
yogiwijaya777 Jan 21, 2024
62e9d54
deleteOrder complete
yogiwijaya777 Jan 21, 2024
fcbaef4
Merge pull request #17 from yogiwijaya777/yogi
yogiwijaya777 Jan 21, 2024
31f12dd
createOrderItem logic complete
yogiwijaya777 Jan 21, 2024
70e4ef2
getOrder compelte
yogiwijaya777 Jan 21, 2024
c1818f3
update service logic complete
yogiwijaya777 Jan 21, 2024
2c46690
deleteOrderITem logic complete
yogiwijaya777 Jan 21, 2024
506c470
get order item by order complete
yogiwijaya777 Jan 21, 2024
b48d12a
get orders by user complete
yogiwijaya777 Jan 21, 2024
f4c6920
Merge pull request #18 from yogiwijaya777/yogi
yogiwijaya777 Jan 21, 2024
2d08e4c
refactor register controller & service toBe expected for testing
yogiwijaya777 Jan 22, 2024
ae43ce5
[__mocks/index.js]Adding beforeEach for deleteMany category
yogiwijaya777 Jan 22, 2024
bf127ac
category.test POST & GET
yogiwijaya777 Jan 23, 2024
a1d8b10
PATCH testing for categories id route
yogiwijaya777 Jan 23, 2024
45e5215
fix error PATCH and adding DELETE testing
yogiwijaya777 Jan 23, 2024
0633fbb
Merge pull request #19 from yogiwijaya777/yogi
yogiwijaya777 Jan 23, 2024
fd01272
addproducts testing 30%
yogiwijaya777 Jan 25, 2024
c0628d1
refactor to newesr faker-js
yogiwijaya777 Jan 26, 2024
b3151b4
Merge pull request #20 from yogiwijaya777/yogi
yogiwijaya777 Jan 26, 2024
1d459a0
refactor product.test and adding more test on POST method
yogiwijaya777 Jan 26, 2024
326ae4e
product testing complete
yogiwijaya777 Jan 26, 2024
208ac84
Merge pull request #21 from yogiwijaya777/yogi
yogiwijaya777 Jan 26, 2024
22f9ae1
queryLogic change
yogiwijaya777 Jan 27, 2024
f78b5ee
refactor user service
yogiwijaya777 Jan 27, 2024
5b0eaa1
user.test POST
yogiwijaya777 Jan 27, 2024
537bd6e
Merge pull request #22 from yogiwijaya777/yogi
yogiwijaya777 Jan 27, 2024
9b54ba8
GET user.testing complete
yogiwijaya777 Jan 28, 2024
d8848ba
GET:id Users and fix error GET
yogiwijaya777 Jan 28, 2024
eab8a26
PATCH user.test complete
yogiwijaya777 Jan 28, 2024
6b3cf43
REFACTOR PATCH user.testing
yogiwijaya777 Jan 28, 2024
741e774
DELETE user testing completed
yogiwijaya777 Jan 28, 2024
b3622c8
Merge pull request #23 from yogiwijaya777/yogi
yogiwijaya777 Jan 28, 2024
06296f4
order fixture and post first test
yogiwijaya777 Jan 29, 2024
4765bb7
Merge pull request #24 from yogiwijaya777/yogi
yogiwijaya777 Jan 29, 2024
b954711
order test complete
yogiwijaya777 Jan 30, 2024
41c425e
Merge pull request #25 from yogiwijaya777/yogi
yogiwijaya777 Jan 30, 2024
d07a2ee
orderItems logic and first test orderItems
yogiwijaya777 Jan 30, 2024
7278980
orderItem.test POST complete
yogiwijaya777 Jan 30, 2024
769374b
GET ordeItem.testing complete
yogiwijaya777 Jan 30, 2024
8b2379e
GET:ID, PATCH:ID, and adding more testing on POST
yogiwijaya777 Jan 30, 2024
9a9906c
order.testing : PATCH refactor, DELETE ctesting Complete
yogiwijaya777 Jan 30, 2024
35d28ef
refactor user authorization to admin, refactor error auth.test , all …
yogiwijaya777 Jan 30, 2024
565a077
Create README.md
yogiwijaya777 Jan 31, 2024
66081ae
Update README.md
yogiwijaya777 Jan 31, 2024
90eb1f9
documentation and serving bit ejs and css
yogiwijaya777 Feb 1, 2024
8bf3ab6
editing readme.md
yogiwijaya777 Feb 1, 2024
be49acf
Update README.md
yogiwijaya777 Feb 1, 2024
531ed37
Merge pull request #27 from yogiwijaya777/yogi
yogiwijaya777 Feb 1, 2024
d178e66
Update README.md
yogiwijaya777 Feb 3, 2024
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
35 changes: 35 additions & 0 deletions inventory-system/src/controllers/order.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const httpStatus = require('http-status');
const catchAsync = require('../utils/catchAsync');
const { orderService } = require('../services');

const createOrder = catchAsync(async (req, res) => {
const order = await orderService.createOrder(req.body);

res.status(httpStatus.CREATED).send({
status: httpStatus.CREATED,
message: 'Create Order Success',
data: order,
});
});

const getAllOrders = catchAsync(async (req, res) => {
const filter = { total: req.query.total };
const options = {
take: req.query.take || 10,
page: req.query.page || 1,
sort: req.query.sort === 'latest' ? { date: 'desc' } : { date: 'asc' },
};

const orders = await orderService.queryOrders(filter, options);

Comment on lines +16 to +24
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice options filter, additional sorting gini lumayan kepake buat front end nyari data historical

res.status(httpStatus.OK).send({
status: httpStatus.OK,
message: 'Get Orders Success',
data: orders,
});
});

module.exports = {
createOrder,
getAllOrders,
};
17 changes: 17 additions & 0 deletions inventory-system/src/controllers/orderItem.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const httpStatus = require('http-status');
const catchAsync = require('../utils/catchAsync');
const { orderService } = require('../services');

const createOrderItem = catchAsync(async (req, res) => {
const orderItem = await orderService.createOrderItem(req.body);

res.status(httpStatus.CREATED).send({
status: httpStatus.CREATED,
message: 'Create OrderItem Success',
data: orderItem,
});
});

module.exports = {
createOrderItem,
};
17 changes: 11 additions & 6 deletions inventory-system/src/routes/v1/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const express = require('express');
const authRoute = require('./auth.route');
const categoryRoute = require('./category.route');
const productRoute = require('./product.route');
const categorysRoute = require('./category.route');
const productsRoute = require('./product.route');
const usersRoute = require('./user.route');
const ordersRoute = require('./order.route');

const router = express.Router();

Expand All @@ -12,17 +13,21 @@ const defaultRoutes = [
route: authRoute,
},
{
path: '/category',
route: categoryRoute,
path: '/categories',
route: categorysRoute,
},
{
path: '/product',
route: productRoute,
path: '/products',
route: productsRoute,
},
{
path: '/users',
route: usersRoute,
},
{
path: '/orders',
route: ordersRoute,
},
];

defaultRoutes.forEach((route) => {
Expand Down
14 changes: 14 additions & 0 deletions inventory-system/src/routes/v1/order.route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const express = require('express');
const { auth, authorizePermissions } = require('../../middlewares/auth');
const validate = require('../../middlewares/validate');
const { orderValidation } = require('../../validations');
const orderController = require('../../controllers/order.controller');

const router = express.Router();

router
.route('/')
.get(auth(), authorizePermissions('admin'), orderController.getAllOrders)
.post(auth(), authorizePermissions('admin'), validate(orderValidation.createOrder), orderController.createOrder);

module.exports = router;
Empty file.
2 changes: 2 additions & 0 deletions inventory-system/src/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ module.exports.userService = require('./user.service');
module.exports.categoryService = require('./category.service');
module.exports.productService = require('./product.service');
module.exports.userService = require('./user.service');
module.exports.orderService = require('./order.service');
module.exports.orderItemService = require('./orderItem.service');
33 changes: 33 additions & 0 deletions inventory-system/src/services/order.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const httpStatus = require('http-status');
const prisma = require('../../prisma/client');
const ApiError = require('../utils/ApiError');

const createOrder = async (body) => {
const order = await prisma.order.create({ data: body });
return order;
};

const queryOrders = async (filter, options) => {
const { total: totalPrice } = filter;
const { take, skip, sort: orderBy } = options;

const orders = await prisma.order.findMany({
where: {
totalPrice: {
lte: totalPrice,
},
},
orderBy,
take: Number(take),
skip,
});

if (!orders) throw new ApiError(httpStatus.NOT_FOUND, 'Orders not found');

return orders;
};

module.exports = {
createOrder,
queryOrders,
};
10 changes: 10 additions & 0 deletions inventory-system/src/services/orderItem.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const prisma = require('../../prisma/client');
const httpStatus = require('http-status');
const ApiError = require('../utils/ApiError');

const createOrderItem = async (data) => {
const orderItem = await prisma.orderItem.create({
data,
});
return orderItem;
};
11 changes: 11 additions & 0 deletions inventory-system/src/services/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,21 @@ const deleteUser = async (userId) => {
return deletedUser;
};

const getUserByEmail = async (email) => {
const user = await prisma.user.findUnique({
where: {
email,
},
});

return user;
};

module.exports = {
createUser,
queryUsers,
getUserById,
updateUser,
deleteUser,
getUserByEmail,
};
1 change: 1 addition & 0 deletions inventory-system/src/validations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ module.exports.categoryValidation = require('./category.validation');
module.exports.productValidation = require('./product.validation');
module.exports.userValidation = require('./user.validation');
module.exports.orderValidation = require('./order.validation');
module.exports.orderItemValidation = require('./orderItem.validation');
6 changes: 3 additions & 3 deletions inventory-system/src/validations/order.validation.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const Joi = require('joi');
const { objectId } = require('./category.validation');
const { objectId } = require('./custom.validation');

const createOrder = {
body: Joi.object().keys({
date: Joi.date().required(),
totalPrife: Joi.number().required(),
totalPrice: Joi.number().required(),
customerName: Joi.string().required(),
customerEmail: Joi.string().required(),
userId: Joi.string().custom(objectId).required(),
Expand All @@ -24,7 +24,7 @@ const updateOrder = {
body: Joi.object()
.keys({
date: Joi.date(),
totalPrife: Joi.number(),
totalPrice: Joi.number().required(),
customerName: Joi.string(),
customerEmail: Joi.string(),
userId: Joi.string().custom(objectId),
Expand Down