Files
quicklanch-server/dist/app/modules/plan/plan.service.js
T
abumahid 0f7af70b90 ♻️ refactor(account, order, plan, profile, support, email): restructure application modules and enhance error handling
Updated Docker configuration, refactored middleware for improved error handling, and restructured account, order, plan, profile, and support modules, including their routes, services, and validations. Enhanced email processing queues and utilities for token generation, pagination, and response management to streamline the application architecture and enhance maintainability.
2026-04-21 03:12:39 +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,
};