46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
|
|
|
||
|
|
import { Request } from "express";
|
||
|
|
import { prisma } from "../../lib/prisma";
|
||
|
|
|
||
|
|
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 } });
|
||
|
|
return result;
|
||
|
|
};
|
||
|
|
|
||
|
|
const create_plan_into_db = async (req: Request) => {
|
||
|
|
// define your own login here
|
||
|
|
console.log(req.body)
|
||
|
|
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;
|
||
|
|
const result = await prisma.plan.update({ where: { 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 } });
|
||
|
|
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,
|
||
|
|
};
|