Template-API's : create tamplate and also add the get all template and get single templates
This commit is contained in:
@@ -3,26 +3,123 @@ import { prisma } from "../../lib/prisma.js";
|
||||
|
||||
const get_all_template_from_db = async (req: Request) => {
|
||||
// define your own login here
|
||||
const result = await prisma.template.findMany();
|
||||
const result = await prisma.template.findMany({});
|
||||
return result;
|
||||
};
|
||||
|
||||
const get_single_template_from_db = async (req: Request) => {
|
||||
// define your own login here
|
||||
const { id } = req.params;
|
||||
const result = await prisma.template.findUnique({ where: { id } });
|
||||
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,
|
||||
},
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
const create_template_into_db = async (req: Request) => {
|
||||
// define your own login here
|
||||
const result = await prisma.template.create({ data: req.body });
|
||||
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,
|
||||
},
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
const update_template_into_db = async (req: Request) => {
|
||||
// define your own login here
|
||||
const { id } = req.params;
|
||||
const { id } = req.params as { id: string };
|
||||
const result = await prisma.template.update({
|
||||
where: { id },
|
||||
data: req.body,
|
||||
@@ -32,7 +129,7 @@ const update_template_into_db = async (req: Request) => {
|
||||
|
||||
const delete_template_from_db = async (req: Request) => {
|
||||
// define your own login here
|
||||
const { id } = req.params;
|
||||
const { id } = req.params as { id: string };
|
||||
const result = await prisma.template.delete({ where: { id } });
|
||||
return result;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user