migration

This commit is contained in:
yoan
2024-11-24 20:16:55 +08:00
parent b4c17a6a12
commit 972df7c167
7 changed files with 1241 additions and 107 deletions

View File

@@ -1,45 +0,0 @@
import { Access } from "@/domain/access";
import { AccessGroup } from "@/domain/access_groups";
import { getPb } from "./api";
export const list = async () => {
const resp = await getPb().collection("access_groups").getFullList<AccessGroup>({
sort: "-created",
expand: "access",
});
return resp;
};
export const remove = async (id: string) => {
const pb = getPb();
// 查询有没有关联的access
const accessGroup = await pb.collection("access").getList<Access>(1, 1, {
filter: `group='${id}' && deleted=null`,
});
if (accessGroup.items.length > 0) {
throw new Error("该分组下有授权配置,无法删除");
}
await pb.collection("access_groups").delete(id);
};
export const update = async (accessGroup: AccessGroup) => {
const pb = getPb();
if (accessGroup.id) {
return await pb.collection("access_groups").update(accessGroup.id, accessGroup);
}
return await pb.collection("access_groups").create(accessGroup);
};
type UpdateByIdReq = {
id: string;
[key: string]: string | string[];
};
export const updateById = async (req: UpdateByIdReq) => {
const pb = getPb();
return await pb.collection("access_groups").update(req.id, req);
};