2026-04-27 00:03:06 +06:00
|
|
|
import { Request } from "express";
|
|
|
|
|
import { prisma } from "../../lib/prisma.js";
|
|
|
|
|
|
|
|
|
|
const get_all_template_from_db = async (req: Request) => {
|
|
|
|
|
// define your own login here
|
2026-04-28 00:29:01 +06:00
|
|
|
const result = await prisma.template.findMany({});
|
2026-04-27 00:03:06 +06:00
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const get_single_template_from_db = async (req: Request) => {
|
|
|
|
|
// define your own login here
|
2026-04-28 00:29:01 +06:00
|
|
|
const { id } = req.params as { id: string };
|
|
|
|
|
const result = await prisma.template.findUnique({
|
|
|
|
|
where: { id },
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
language: true,
|
|
|
|
|
deliveryCharge: true,
|
|
|
|
|
banner: true,
|
|
|
|
|
address: true,
|
|
|
|
|
ingredient: true,
|
|
|
|
|
instruction: true,
|
|
|
|
|
faq: true,
|
|
|
|
|
tips: true,
|
|
|
|
|
priceCombo: true,
|
|
|
|
|
product: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
2026-04-27 00:03:06 +06:00
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const create_template_into_db = async (req: Request) => {
|
|
|
|
|
// define your own login here
|
2026-04-28 00:29:01 +06:00
|
|
|
const payload = req.body;
|
|
|
|
|
console.log(payload);
|
|
|
|
|
const result = await prisma.template.create({
|
|
|
|
|
data: {
|
|
|
|
|
language: payload.language,
|
|
|
|
|
deliveryCharge: payload.deliveryCharge,
|
|
|
|
|
|
|
|
|
|
banner: {
|
|
|
|
|
create: payload.banner,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
address: {
|
|
|
|
|
create: payload.address,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
ingredient: {
|
|
|
|
|
create: {
|
|
|
|
|
isVisible: payload.ingredient.isVisible,
|
|
|
|
|
options: {
|
|
|
|
|
create: payload.ingredient.options,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
instruction: {
|
|
|
|
|
create: {
|
|
|
|
|
isVisible: payload.instruction.isVisible,
|
|
|
|
|
instBanner: payload.instruction.instBanner,
|
|
|
|
|
options: {
|
|
|
|
|
create: payload.instruction.options,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
faq: {
|
|
|
|
|
create: {
|
|
|
|
|
isVisible: payload.faq.isVisible,
|
|
|
|
|
options: {
|
|
|
|
|
create: payload.faq.options,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
tips: {
|
|
|
|
|
create: {
|
|
|
|
|
isVisible: payload.tips.isVisible,
|
|
|
|
|
tipsBanner: payload.tips.tipsBanner,
|
|
|
|
|
options: {
|
|
|
|
|
create: payload.tips.options,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
priceCombo: {
|
|
|
|
|
create: {
|
|
|
|
|
isVisible: payload.priceCombo.isVisible,
|
|
|
|
|
options: {
|
|
|
|
|
create: payload.priceCombo.options,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
product: {
|
|
|
|
|
create: {
|
|
|
|
|
isVisible: payload.product.isVisible,
|
|
|
|
|
price: payload.product.price,
|
|
|
|
|
discount: payload.product.discount,
|
|
|
|
|
productName: payload.product.productName,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
include: {
|
|
|
|
|
banner: true,
|
|
|
|
|
address: true,
|
|
|
|
|
ingredient: { include: { options: true } },
|
|
|
|
|
instruction: { include: { options: true } },
|
|
|
|
|
faq: { include: { options: true } },
|
|
|
|
|
tips: { include: { options: true } },
|
|
|
|
|
priceCombo: { include: { options: true } },
|
|
|
|
|
product: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
2026-04-27 00:03:06 +06:00
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const update_template_into_db = async (req: Request) => {
|
|
|
|
|
// define your own login here
|
2026-04-28 00:29:01 +06:00
|
|
|
const { id } = req.params as { id: string };
|
2026-04-27 00:03:06 +06:00
|
|
|
const result = await prisma.template.update({
|
|
|
|
|
where: { id },
|
|
|
|
|
data: req.body,
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const delete_template_from_db = async (req: Request) => {
|
|
|
|
|
// define your own login here
|
2026-04-28 00:29:01 +06:00
|
|
|
const { id } = req.params as { id: string };
|
2026-04-27 00:03:06 +06:00
|
|
|
const result = await prisma.template.delete({ where: { id } });
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const template_service = {
|
|
|
|
|
get_all_template_from_db,
|
|
|
|
|
get_single_template_from_db,
|
|
|
|
|
create_template_into_db,
|
|
|
|
|
update_template_into_db,
|
|
|
|
|
delete_template_from_db,
|
|
|
|
|
};
|