tianji/src/server/model/workspace.ts

103 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-09-04 17:18:43 +00:00
import { prisma } from './_client';
2023-09-06 06:14:12 +00:00
export async function getWorkspaceUser(workspaceId: string, userId: string) {
const info = await prisma.workspacesOnUsers.findFirst({
where: {
workspaceId,
userId,
},
});
return info;
}
2023-09-04 17:18:43 +00:00
export async function checkIsWorkspaceUser(
workspaceId: string,
userId: string
) {
2023-09-06 06:14:12 +00:00
const info = await getWorkspaceUser(workspaceId, userId);
2023-09-04 17:18:43 +00:00
2023-09-06 06:14:12 +00:00
if (info) {
2023-09-04 17:18:43 +00:00
return true;
} else {
return false;
}
}
export async function getWorkspaceWebsites(workspaceId: string) {
const workspace = await prisma.workspace.findUnique({
where: {
id: workspaceId,
},
select: {
websites: true,
},
});
return workspace?.websites ?? [];
}
2023-09-05 07:32:16 +00:00
export async function getWorkspaceWebsiteInfo(
workspaceId: string,
websiteId: string
) {
const websiteInfo = await prisma.website.findUnique({
where: {
id: websiteId,
workspaceId,
},
});
return websiteInfo;
}
export async function updateWorkspaceWebsiteInfo(
workspaceId: string,
websiteId: string,
name: string,
domain: string
) {
const websiteInfo = await prisma.website.update({
where: {
id: websiteId,
workspaceId,
},
data: {
name,
domain,
},
});
return websiteInfo;
}
2023-09-04 17:18:43 +00:00
export async function addWorkspaceWebsite(
workspaceId: string,
name: string,
domain: string
) {
const website = await prisma.website.create({
data: {
name,
domain,
workspaceId,
},
});
return website;
}
2023-09-06 06:14:12 +00:00
export async function deleteWorkspaceWebsite(
workspaceId: string,
websiteId: string
) {
const website = await prisma.website.delete({
where: {
id: websiteId,
workspaceId,
},
});
return website;
}