-
![](https://pbs.twimg.com/media/E0lb711XIAQOxch.jpg:large)
@ Ganon
2024-11-21 23:39:06
<div style="position:relative;padding-bottom:56.25%;height:0;overflow:hidden;max-width:100%;"><iframe src="https://www.youtube.com/embed/RFA4XJ5HfG4?enablejsapi=1" style="position:absolute;top:0;left:0;width:100%;height:100%;border:0;" allowfullscreen></iframe></div>
```js
import prisma from "../prisma";
export const getAllDraftsByUserId = async (userId) => {
return await prisma.draft.findMany({
where: { userId },
include: {
user: true,
},
});
}
export const getDraftById = async (id) => {
return await prisma.draft.findUnique({
where: { id },
include: {
user: true,
},
});
};
export const createDraft = async (data) => {
return await prisma.draft.create({
data: {
...data,
user: {
connect: {
id: data.user,
},
},
additionalLinks: data.additionalLinks || [],
},
});
};
export const updateDraft = async (id, data) => {
const { user, additionalLinks, ...otherData } = data;
return await prisma.draft.update({
where: { id },
data: {
...otherData,
user: user ? {
connect: { id: user }
} : undefined,
additionalLinks: additionalLinks || undefined,
},
});
};
export const deleteDraft = async (id) => {
return await prisma.draft.delete({
where: { id },
});
}
```