Order api: create order schema

This commit is contained in:
Md Sharafat Hassain
2026-04-12 22:47:56 +06:00
parent 308445f346
commit ee5eb0f0f5
20 changed files with 443 additions and 33 deletions
+86
View File
@@ -0,0 +1,86 @@
import { Request } from "express";
import { prisma } from "../../lib/prisma";
import { AppError } from "../../utils/app_error";
const get_all_order_from_db = async (req: Request) => {
// define your own login here
const result = await prisma.order.findMany();
return result;
};
const get_single_order_from_db = async (req: Request) => {
// define your own login here
const { id } = req.params;
const result = await prisma.order.findUnique({ where: { id } });
return result;
};
const create_order_into_db = async (req: Request) => {
// define your own login here
const user = req.user
console.log(user)
const {
shopAccountId,
productPrice,
productQuantity,
productName,
customerName,
customerPhone,
customerAddress,
customerNote,
paymentType,
status,
} = req.body
const isUserExists = await prisma.account.findFirst({
where: {
id: user?.accountId
}
})
if (!isUserExists) {
throw new AppError("Account not found", 404);
}
const result = await prisma.order.create({
data: {
productPrice,
productQuantity,
productName,
customerName,
customerPhone,
customerAddress,
customerNote,
paymentType,
status,
account: {
connect: {
id: user?.accountId,
},
},
}
});
return result;
};
const update_order_into_db = async (req: Request) => {
// define your own login here
const { id } = req.params;
const result = await prisma.order.update({ where: { id }, data: req.body });
return result;
};
const delete_order_from_db = async (req: Request) => {
// define your own login here
const { id } = req.params;
const result = await prisma.order.delete({ where: { id } });
return result;
};
export const order_service = {
get_all_order_from_db,
get_single_order_from_db,
create_order_into_db,
update_order_into_db,
delete_order_from_db,
};