47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
|
|
import { Request } from "express";
|
||
|
|
import { prisma } from "../../lib/prisma.js";
|
||
|
|
|
||
|
|
const get_all_template_from_db = async (req: Request) => {
|
||
|
|
// define your own login here
|
||
|
|
const result = await prisma.template.findMany();
|
||
|
|
return result;
|
||
|
|
};
|
||
|
|
|
||
|
|
const get_single_template_from_db = async (req: Request) => {
|
||
|
|
// define your own login here
|
||
|
|
const { id } = req.params;
|
||
|
|
const result = await prisma.template.findUnique({ where: { id } });
|
||
|
|
return result;
|
||
|
|
};
|
||
|
|
|
||
|
|
const create_template_into_db = async (req: Request) => {
|
||
|
|
// define your own login here
|
||
|
|
const result = await prisma.template.create({ data: req.body });
|
||
|
|
return result;
|
||
|
|
};
|
||
|
|
|
||
|
|
const update_template_into_db = async (req: Request) => {
|
||
|
|
// define your own login here
|
||
|
|
const { id } = req.params;
|
||
|
|
const result = await prisma.template.update({
|
||
|
|
where: { id },
|
||
|
|
data: req.body,
|
||
|
|
});
|
||
|
|
return result;
|
||
|
|
};
|
||
|
|
|
||
|
|
const delete_template_from_db = async (req: Request) => {
|
||
|
|
// define your own login here
|
||
|
|
const { id } = req.params;
|
||
|
|
const result = await prisma.template.delete({ where: { id } });
|
||
|
|
return result;
|
||
|
|
};
|
||
|
|
|
||
|
|
export const template_service = {
|
||
|
|
get_all_template_from_db,
|
||
|
|
get_single_template_from_db,
|
||
|
|
create_template_into_db,
|
||
|
|
update_template_into_db,
|
||
|
|
delete_template_from_db,
|
||
|
|
};
|