api: get all api, post api, get signle data api and delete api was created

This commit is contained in:
Md Sharafat Hassain
2026-04-08 21:06:42 +06:00
parent bcdb125af1
commit 75209cc435
+33 -5
View File
@@ -1,6 +1,7 @@
import { Request } from "express";
import { prisma } from "../../lib/prisma";
import { AppError } from "../../utils/app_error";
const get_all_plan_from_db = async (req: Request) => {
// define your own login here
@@ -10,14 +11,21 @@ const get_all_plan_from_db = async (req: Request) => {
const get_single_plan_from_db = async (req: Request) => {
// define your own login here
const { id } = req.params ;
const result = await prisma.plan.findUnique({ where: { id } });
const { id } = req.params;
const result = await prisma.plan.findUnique({
where: {
id: id as string
}
});
return result;
};
const create_plan_into_db = async (req: Request) => {
// define your own login here
console.log(req.body)
const user = req.user
if (user?.role !== "ADMIN") {
throw new AppError("You dont have permission to create plan information.!!!", 401)
}
const result = await prisma.plan.create({ data: req.body });
return result;
};
@@ -25,14 +33,34 @@ const create_plan_into_db = async (req: Request) => {
const update_plan_into_db = async (req: Request) => {
// define your own login here
const { id } = req.params;
const result = await prisma.plan.update({ where: { id }, data: req.body });
console.log(req.body)
const isPlanExist = await prisma.plan.findFirst({
where: {
id: id as string
}
})
if (!isPlanExist) {
throw new AppError("The plan is not available!!!", 404)
}
const result = await prisma.plan.update({
where: {
id: isPlanExist.id
},
data: {
...req.body
}
});
return result;
};
const delete_plan_from_db = async (req: Request) => {
// define your own login here
const { id } = req.params;
const result = await prisma.plan.delete({ where: { id } });
const user = req.user
if (user?.role !== "ADMIN") {
throw new AppError("You dont have permission to delete plan information.!!!", 401)
}
const result = await prisma.plan.delete({ where: { id: id as string } });
return result;
};