Files
quicklanch-server/dist/app/modules/plan/plan.service.js
T
abumahid 61fd639faf feat(account, order, plan, profile, redis): enhance functionality and security
- Updated CORS settings for frontend compatibility.
- Integrated Redis URL configuration.
- Improved login response structure in account service.
- Added role-based authorization for order and plan management.
- Enhanced error handling and logging in profile and plan services.
- Updated Swagger documentation for clarity on order statuses.
- Configured Redis connection for better performance.
2026-04-26 19:14:37 +06:00

69 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { prisma } from "../../lib/prisma.js";
import { AppError } from "../../utils/app_error.js";
const get_all_plan_from_db = async (req) => {
// define your own login here
const result = await prisma.plan.findMany();
return result;
};
const get_single_plan_from_db = async (req) => {
// define your own login here
const { id } = req.params;
const result = await prisma.plan.findUnique({
where: {
id: id
}
});
return result;
};
const create_plan_into_db = async (req) => {
// 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);
}
const result = await prisma.plan.create({ data: req.body });
return result;
};
const update_plan_into_db = async (req) => {
// 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 update plan information.!!!", 401);
}
const isPlanExist = await prisma.plan.findFirst({
where: {
id: id
}
});
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) => {
// 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 } });
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,
};