Merge remote-tracking branch 'origin/sharafat' into dev

This commit is contained in:
2026-04-20 20:39:16 +06:00
6 changed files with 211 additions and 38 deletions
+1 -1
View File
@@ -38,7 +38,7 @@
"@types/express": "^5.0.3", "@types/express": "^5.0.3",
"@types/jsonwebtoken": "^9.0.10", "@types/jsonwebtoken": "^9.0.10",
"@types/multer": "^2.0.0", "@types/multer": "^2.0.0",
"@types/node": "^24.10.9", "@types/node": "^24.12.2",
"@types/nodemailer": "^7.0.2", "@types/nodemailer": "^7.0.2",
"@types/pg": "^8.20.0", "@types/pg": "^8.20.0",
"@types/swagger-jsdoc": "^6.0.4", "@types/swagger-jsdoc": "^6.0.4",
+2 -1
View File
@@ -3,6 +3,7 @@
import RequestValidator from "../../middlewares/request_validator"; import RequestValidator from "../../middlewares/request_validator";
import { order_controller } from "./order.controller"; import { order_controller } from "./order.controller";
import { order_validations } from "./order.validation"; import { order_validations } from "./order.validation";
import auth from "../../middlewares/auth";
const router = Router(); const router = Router();
@@ -14,7 +15,7 @@ router.post(
); );
router.get("/:id", order_controller.get_single_order); router.get("/:id", order_controller.get_single_order);
router.patch( router.patch(
"/:id", "/:id",auth("ADMIN"),
RequestValidator(order_validations.update_order), RequestValidator(order_validations.update_order),
order_controller.update_order, order_controller.update_order,
); );
+119 -6
View File
@@ -1,13 +1,116 @@
import { Request } from "express"; import { Request } from "express";
import { configs } from "../../configs"; import { configs } from "../../configs";
import { prisma } from "../../lib/prisma"; import { prisma } from "../../lib/prisma";
import { orderEmailQueue } from "../../queues/email/order/order.email.queue"; import { orderEmailQueue } from "../../queues/email/order/order.email.queue";
import { AppError } from "../../utils/app_error";
import paginationHelper from "../../utils/pagination_helper";
const get_all_order_from_db = async (req: Request) => { const get_all_order_from_db = async (req: Request) => {
// define your own login here // define your own login here
const result = await prisma.order.findMany(); const search = req.query.search as string;
return result; const customerName = req.query.customerName as string;
const productName = req.query.productName as string;
// for date filter
const startDate = req.query.startDate as string;
const endDate = req.query.endDate as string;
const status = (req.query.status as string) || undefined;
const { page, limit, skip, sortBy, sortOrder } = paginationHelper(req.query);
const andCondition = [] as any[];
if (search) {
andCondition.push({
OR: [
{
productName: {
contains: search,
mode: "insensitive",
},
},
],
});
}
if (customerName) {
andCondition.push({
OR: [
{
customerName: {
contains: customerName,
mode: "insensitive",
},
},
],
});
}
if (productName) {
andCondition.push({
OR: [
{
productName: {
contains: productName,
mode: "insensitive",
},
},
],
});
}
if (status) {
andCondition.push({
OR: [
{
status: {
contains: status,
mode: "insensitive",
},
},
],
});
}
// for date filter
const dateFilter: any = {};
if (startDate) {
const start = new Date(startDate);
start.setHours(0, 0, 0, 0);
dateFilter.gte = start;
}
if (endDate) {
const end = new Date(endDate);
end.setHours(23, 59, 59, 999);
dateFilter.lte = end;
}
if (Object.keys(dateFilter).length > 0) {
andCondition.push({
createdAt: dateFilter,
});
}
const getAllOrders = await prisma.order.findMany({
take: limit,
skip,
where: {
AND: andCondition,
},
orderBy: {
[sortBy as string]: sortOrder,
},
});
const result = await prisma.order.count({
where: {
AND: andCondition,
},
});
return {
data: getAllOrders,
pagination: {
total: result,
page,
limit,
totalPages: Math.ceil(result / limit),
},
};
}; };
const get_single_order_from_db = async (req: Request) => { const get_single_order_from_db = async (req: Request) => {
@@ -19,8 +122,9 @@ const get_single_order_from_db = async (req: Request) => {
const create_order_into_db = async (req: Request) => { const create_order_into_db = async (req: Request) => {
const payload = req?.body; const payload = req?.body;
console.log(payload);
payload.status = "INITIATED"; payload.status = "INITIATED";
payload.paymentType = "COD" payload.paymentType = "COD";
// nwo init order // nwo init order
const result = await prisma.order.create({ data: payload }); const result = await prisma.order.create({ data: payload });
@@ -32,15 +136,24 @@ const create_order_into_db = async (req: Request) => {
email: payload.customerEmail, email: payload.customerEmail,
subject: "Order Tracking", subject: "Order Tracking",
textBody: `Your order has been created. Track your order here: ${trackingLink}`, textBody: `Your order has been created. Track your order here: ${trackingLink}`,
htmlBody: `<p>Your order has been created. Track your order here: <a href="${trackingLink}">Track Order</a></p>` htmlBody: `<p>Your order has been created. Track your order here: <a href="${trackingLink}">Track Order</a></p>`,
}) });
} }
return result; return result;
}; };
const update_order_into_db = async (req: Request) => { const update_order_into_db = async (req: Request) => {
// define your own login here // define your own login here
const user = req.user;
console.log(user);
if (user?.role !== "ADMIN") {
throw new AppError("You are not authorized to perform this action", 403);
}
const { id } = req.params as { id: string }; const { id } = req.params as { id: string };
const isProductExist = await prisma.order.findUnique({ where: { id } });
if (!isProductExist) {
throw new AppError("Order is not found", 404);
}
const result = await prisma.order.update({ where: { id }, data: req.body }); const result = await prisma.order.update({ where: { id }, data: req.body });
return result; return result;
}; };
+55 -21
View File
@@ -1,4 +1,3 @@
export const orderSwaggerDocs = { export const orderSwaggerDocs = {
"/api/order": { "/api/order": {
post: { post: {
@@ -10,16 +9,16 @@ export const orderSwaggerDocs = {
content: { content: {
"application/json": { "application/json": {
example: JSON.stringify({ example: JSON.stringify({
"shopAccountId": "", shopAccountId: "",
"productPrice": 1500, productPrice: 1500,
"productQuantity": 2, productQuantity: 2,
"productName": "Wireless Mouse", productName: "Wireless Mouse",
"customerName": "Rahim Uddin", customerName: "Rahim Uddin",
"customerPhone": "+8801712345678", customerPhone: "+8801712345678",
"customerEmail": "softvence.abumahid@gmail.com", customerEmail: "softvence.abumahid@gmail.com",
"customerAddress": "Rangpur, Bangladesh", customerAddress: "Rangpur, Bangladesh",
"customerNote": "Please deliver between 3-5 PM" customerNote: "Please deliver between 3-5 PM",
}) }),
}, },
}, },
}, },
@@ -45,6 +44,50 @@ export const orderSwaggerDocs = {
required: false, required: false,
schema: { type: "number" }, schema: { type: "number" },
}, },
{
name: "search",
in: "query",
required: false,
schema: { type: "string" },
},
{
name: "customerName",
in: "query",
required: false,
schema: { type: "string" },
},
{
name: "productName",
in: "query",
required: false,
schema: { type: "string" },
},
{
name: "status",
in: "query",
required: false,
schema: { type: "string" },
},
{
name: "date",
in: "query",
required: false,
schema: { type: "string" },
},
{
name: "startDate",
in: "query",
required: false,
schema: { type: "string", format: "date" },
example: "2026-04-01",
},
{
name: "endDate",
in: "query",
required: false,
schema: { type: "string", format: "date" },
example: "2026-04-31",
},
], ],
responses: { responses: {
200: { description: "order fetched successfully" }, 200: { description: "order fetched successfully" },
@@ -88,14 +131,7 @@ export const orderSwaggerDocs = {
content: { content: {
"application/json": { "application/json": {
example: JSON.stringify({ example: JSON.stringify({
"shopAccountId": "", status: "INITIATED",
"productPrice": 1500,
"productQuantity": 2,
"productName": "Wireless Mouse",
"customerName": "Rahim Uddin",
"customerPhone": "+8801712345678",
"customerAddress": "Rangpur, Bangladesh",
"customerNote": "Please deliver between 3-5 PM"
}), // put your request body }), // put your request body
}, },
}, },
@@ -124,5 +160,3 @@ export const orderSwaggerDocs = {
}, },
}, },
}; };
@@ -13,15 +13,6 @@ const create_order = z.object({
customerNote: z.string().optional() customerNote: z.string().optional()
}); });
const update_order = z.object({ const update_order = z.object({
shopAccountId: z.string().optional(),
productPrice: z.number().optional(),
productQuantity: z.number().optional(),
productName: z.string().optional(),
customerName: z.string().optional(),
customerPhone: z.string().optional(),
customerEmail: z.string().optional(),
customerAddress: z.string().optional(),
customerNote: z.string().optional(),
status: z.string().optional() status: z.string().optional()
}); });
+34
View File
@@ -0,0 +1,34 @@
// options type
type IOptions = {
page?: number | string;
limit?: number | string;
sortOrder?: string;
sortBy?: string;
};
// return type
export type IPaginationResult = {
page: number;
limit: number;
skip: number;
sortOrder?: string;
sortBy?: string;
};
const paginationHelper = (options:IOptions): IPaginationResult => {
const page = Number(options?.page) || 1;
const limit = Number(options?.limit) || 10;
const skip = (page-1)*limit
const sortBy =options?.sortBy ||"createdAt";
const sortOrder = options?.sortOrder || "desc";
return {
page,
limit,
skip,
sortBy,
sortOrder
}
};
export default paginationHelper;