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;
|
||||
};
|
||||
|
||||
@@ -8,7 +8,98 @@ export const templateSwaggerDocs = {
|
||||
required: true,
|
||||
content: {
|
||||
"application/json": {
|
||||
example: JSON.stringify({}), // put your request body
|
||||
example: JSON.stringify({
|
||||
language: "en",
|
||||
deliveryCharge: "60",
|
||||
banner: {
|
||||
isVisible: true,
|
||||
bannerTitle: "Delicious Homemade Food",
|
||||
bannerDesc:
|
||||
"Fresh, healthy and tasty meals delivered to your door.",
|
||||
bannerImage: "https://example.com/banner.jpg",
|
||||
},
|
||||
address: {
|
||||
isVisible: true,
|
||||
phoneNumber: "+8801712345678",
|
||||
shopLocation: "Dhaka, Bangladesh",
|
||||
shopEmail: "foodshop@example.com",
|
||||
},
|
||||
ingredient: {
|
||||
isVisible: true,
|
||||
options: [
|
||||
{
|
||||
ingrImg: "https://example.com/tomato.jpg",
|
||||
ingrTitle: "Tomato",
|
||||
ingrDes: "Fresh organic tomatoes",
|
||||
},
|
||||
{
|
||||
ingrImg: "https://example.com/chicken.jpg",
|
||||
ingrTitle: "Chicken",
|
||||
ingrDes: "Premium quality chicken",
|
||||
},
|
||||
],
|
||||
},
|
||||
instruction: {
|
||||
isVisible: true,
|
||||
instBanner: "https://example.com/instruction-banner.jpg",
|
||||
options: [
|
||||
{
|
||||
hint: "Step 1",
|
||||
detail: "Wash all ingredients properly",
|
||||
},
|
||||
{
|
||||
hint: "Step 2",
|
||||
detail: "Cook on medium heat for 20 minutes",
|
||||
},
|
||||
],
|
||||
},
|
||||
faq: {
|
||||
isVisible: true,
|
||||
options: [
|
||||
{
|
||||
index: 1,
|
||||
text: "Is the food fresh?",
|
||||
},
|
||||
{
|
||||
index: 2,
|
||||
text: "Do you offer home delivery?",
|
||||
},
|
||||
],
|
||||
},
|
||||
tips: {
|
||||
isVisible: true,
|
||||
tipsBanner: "https://example.com/tips-banner.jpg",
|
||||
options: [
|
||||
{
|
||||
index: 1,
|
||||
text: "Use fresh ingredients for best taste",
|
||||
},
|
||||
{
|
||||
index: 2,
|
||||
text: "Serve hot for better flavor",
|
||||
},
|
||||
],
|
||||
},
|
||||
priceCombo: {
|
||||
isVisible: true,
|
||||
options: [
|
||||
{
|
||||
quantity: "1",
|
||||
price: "120",
|
||||
},
|
||||
{
|
||||
quantity: "2",
|
||||
price: "220",
|
||||
},
|
||||
],
|
||||
},
|
||||
product: {
|
||||
isVisible: true,
|
||||
price: "120",
|
||||
discount: 10,
|
||||
productName: "Chicken Burger",
|
||||
},
|
||||
}), // put your request body
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,6 +1,84 @@
|
||||
import { z } from "zod";
|
||||
|
||||
const create_template = z.object({});
|
||||
// Template Options that we need to use for validation.
|
||||
|
||||
// Ingredient Option
|
||||
const ingredientOptionSchema = z.object({
|
||||
ingrImg: z.string().url().or(z.string()),
|
||||
ingrTitle: z.string().min(1),
|
||||
ingrDes: z.string().min(1),
|
||||
});
|
||||
|
||||
// Instruction Option
|
||||
const instructionOptionSchema = z.object({
|
||||
hint: z.string().min(1),
|
||||
detail: z.string().min(1),
|
||||
});
|
||||
|
||||
// FAQ Option
|
||||
const faqOptionSchema = z.object({
|
||||
index: z.number(),
|
||||
text: z.string().min(1),
|
||||
});
|
||||
|
||||
// Tips Option
|
||||
const tipsOptionSchema = z.object({
|
||||
index: z.number(),
|
||||
text: z.string().min(1),
|
||||
});
|
||||
|
||||
// Price Option
|
||||
const priceOptionSchema = z.object({
|
||||
quantity: z.string().min(1),
|
||||
price: z.string().min(1),
|
||||
});
|
||||
|
||||
|
||||
// Create the main template schema validation
|
||||
const create_template = z.object({
|
||||
language: z.string().min(1),
|
||||
deliveryCharge: z.string().min(1),
|
||||
banner: z.object({
|
||||
isVisible: z.boolean(),
|
||||
bannerTitle: z.string().min(1),
|
||||
bannerDesc: z.string().min(1),
|
||||
bannerImage: z.string(),
|
||||
}),
|
||||
address: z.object({
|
||||
isVisible: z.boolean(),
|
||||
phoneNumber: z.string().min(1),
|
||||
shopLocation: z.string().min(1),
|
||||
shopEmail: z.string().email(),
|
||||
}),
|
||||
ingredient: z.object({
|
||||
isVisible: z.boolean(),
|
||||
options: z.array(ingredientOptionSchema).min(1),
|
||||
}),
|
||||
instruction: z.object({
|
||||
isVisible: z.boolean(),
|
||||
instBanner: z.string(),
|
||||
options: z.array(instructionOptionSchema).min(1),
|
||||
}),
|
||||
faq: z.object({
|
||||
isVisible: z.boolean(),
|
||||
options: z.array(faqOptionSchema).min(1),
|
||||
}),
|
||||
tips: z.object({
|
||||
isVisible: z.boolean(),
|
||||
tipsBanner: z.string(),
|
||||
options: z.array(tipsOptionSchema).min(1),
|
||||
}),
|
||||
priceCombo: z.object({
|
||||
isVisible: z.boolean(),
|
||||
options: z.array(priceOptionSchema).min(1),
|
||||
}),
|
||||
product: z.object({
|
||||
isVisible: z.boolean(),
|
||||
price: z.string().min(1),
|
||||
discount: z.number().min(0),
|
||||
productName: z.string().min(1),
|
||||
}),
|
||||
});
|
||||
const update_template = z.object({});
|
||||
|
||||
export const template_validations = {
|
||||
|
||||
Reference in New Issue
Block a user