-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdeployment.ts
More file actions
54 lines (40 loc) · 1.72 KB
/
Copy pathdeployment.ts
File metadata and controls
54 lines (40 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use server';
import db from '@/lib/data/db';
import { DeploymentInput, DeploymentInputSchema } from '../deployment-schema';
import { getCurrentEnvironment } from '@/components/auth';
import { UserErrorType, userError } from '../user-error';
export async function getProcessDeployments(spaceId: string, processId: string) {
const { ability } = await getCurrentEnvironment(spaceId);
if (!ability.can('view', 'Execution'))
return userError('Invalid Permissions', UserErrorType.PermissionError);
const deployments = await db.processDeployment.findMany({
where: { AND: [{ version: { processId } }, { removeTime: null }] },
include: { version: { select: { processId: true } } },
});
return deployments.map((d) => ({ ...d, version: undefined, processId: d.version.processId }));
}
export async function addDeployment(spaceId: string, input: DeploymentInput) {
const { ability } = await getCurrentEnvironment(spaceId);
if (!ability.can('create', 'Execution'))
return userError('Invalid Permissions', UserErrorType.PermissionError);
const data = DeploymentInputSchema.parse(input);
await db.processDeployment.createMany({
data: data.engineIds.map((engineId) => ({ ...data, engineIds: undefined, engineId })),
});
}
export async function updateDeployment(
spaceId: string,
deploymentId: string,
input: Partial<DeploymentInput>,
) {
const { ability } = await getCurrentEnvironment(spaceId);
if (!ability.can('update', 'Execution')) {
return userError('Invalid Permissions', UserErrorType.PermissionError);
}
const data = DeploymentInputSchema.partial().strict().parse(input);
const result = await db.processDeployment.update({
where: { id: deploymentId },
data,
});
return result;
}