Files
quicklanch-server/src/app/modules/plan/plan.service.ts
T

74 lines
1.8 KiB
TypeScript
Raw Normal View History

2026-04-07 22:32:13 +06:00
import { Request } from "express";
import { prisma } from "../../lib/prisma";
import { AppError } from "../../utils/app_error";
2026-04-07 22:32:13 +06:00
const get_all_plan_from_db = async (req: Request) => {
// define your own login here
const result = await prisma.plan.findMany();
return result;
};
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: id as string
}
});
2026-04-07 22:32:13 +06:00
return result;
};
const create_plan_into_db = async (req: Request) => {
// define your own login here
const user = req.user
if (user?.role !== "ADMIN") {
throw new AppError("You dont have permission to create plan information.!!!", 401)
}
2026-04-07 22:32:13 +06:00
const result = await prisma.plan.create({ data: req.body });
return result;
};
const update_plan_into_db = async (req: Request) => {
// define your own login here
const { id } = req.params;
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
}
});
2026-04-07 22:32:13 +06:00
return result;
};
const delete_plan_from_db = async (req: Request) => {
// define your own login here
const { id } = req.params;
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 } });
2026-04-07 22:32:13 +06:00
return result;
};
export const plan_service = {
get_all_plan_from_db,
get_single_plan_from_db,
create_plan_into_db,
update_plan_into_db,
delete_plan_from_db,
};