...
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-11-17 15:59:35 +08:00
parent 22a0cf46fb
commit 0bf3b718b2
35 changed files with 204 additions and 841 deletions

View File

@@ -0,0 +1,68 @@
"use server";
import {
folderCreateInput,
folderUpdateInput,
} from "../../../../generated/prisma/models";
import prisma from "../../db";
export async function getFoldersByOwner(owner: string) {
const folders = await prisma.folder.findMany({
where: {
owner: owner,
},
});
return folders;
}
export async function getFoldersWithTotalPairsByOwner(owner: string) {
const folders = await prisma.folder.findMany({
where: {
owner: owner
},
include: {
text_pair: {
select: {
id: true
}
}
}
});
return folders.map(folder => ({
...folder,
total_pairs: folder.text_pair.length
}));
}
export async function createFolder(folder: folderCreateInput) {
await prisma.folder.create({
data: folder,
});
}
export async function deleteFolderById(id: number) {
await prisma.folder.delete({
where: {
id: id,
},
});
}
export async function updateFolderById(id: number, data: folderUpdateInput) {
await prisma.folder.update({
where: {
id: id,
},
data: data,
});
}
export async function getOwnerByFolderId(id: number) {
const folder = await prisma.folder.findUnique({
where: {
id: id,
},
});
return folder?.owner;
}

View File

@@ -0,0 +1,51 @@
"use server";
import {
text_pairCreateInput,
text_pairUpdateInput,
} from "../../../../generated/prisma/models";
import prisma from "../../db";
export async function createTextPair(data: text_pairCreateInput) {
await prisma.text_pair.create({
data: data,
});
}
export async function deleteTextPairById(id: number) {
await prisma.text_pair.delete({
where: {
id: id,
},
});
}
export async function updateTextPairById(
id: number,
data: text_pairUpdateInput,
) {
await prisma.text_pair.update({
where: {
id: id,
},
data: data,
});
}
export async function getTextPairCountByFolderId(folderId: number) {
const count = await prisma.text_pair.count({
where: {
folder_id: folderId,
},
});
return count;
}
export async function getTextPairsByFolderId(folderId: number) {
const textPairs = await prisma.text_pair.findMany({
where: {
folder_id: folderId,
},
});
return textPairs;
}