-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
488 additions
and
290 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
apps/app/src/app/[locale]/(app)/(dashboard)/tests/[testId]/actions/get-cloud-test-details.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
"use server"; | ||
|
||
import { db } from "@bubba/db"; | ||
import { authActionClient } from "@/actions/safe-action"; | ||
import { auth } from "@/auth"; | ||
import { | ||
appErrors, | ||
type CloudTestResult, | ||
type ActionResponse | ||
} from "./types"; | ||
|
||
export async function getCloudTestDetails(input: { testId: string }): Promise<ActionResponse<CloudTestResult>> { | ||
const { testId } = input; | ||
|
||
const session = await auth(); | ||
const organizationId = session?.user.organizationId; | ||
|
||
if (!organizationId) { | ||
throw new Error("Organization ID not found"); | ||
} | ||
|
||
try { | ||
const cloudTest = await db.cloudTest.findUnique({ | ||
where: { | ||
id: testId, | ||
organizationId, | ||
}, | ||
select: { | ||
id: true, | ||
title: true, | ||
description: true, | ||
provider: true, | ||
status: true, | ||
config: true, | ||
authConfig: true, | ||
createdAt: true, | ||
updatedAt: true, | ||
createdBy: { | ||
select: { | ||
id: true, | ||
name: true, | ||
email: true, | ||
}, | ||
}, | ||
updatedBy: { | ||
select: { | ||
id: true, | ||
name: true, | ||
email: true, | ||
}, | ||
}, | ||
runs: { | ||
select: { | ||
id: true, | ||
status: true, | ||
result: true, | ||
resultDetails: true, | ||
startedAt: true, | ||
completedAt: true, | ||
executedBy: { | ||
select: { | ||
id: true, | ||
name: true, | ||
email: true, | ||
}, | ||
}, | ||
createdAt: true, | ||
updatedAt: true, | ||
}, | ||
orderBy: { | ||
createdAt: 'desc', | ||
}, | ||
take: 10, // Limit to most recent 10 runs | ||
}, | ||
}, | ||
}); | ||
|
||
if (!cloudTest) { | ||
return { | ||
success: false, | ||
error: appErrors.NOT_FOUND, | ||
}; | ||
} | ||
|
||
return { | ||
success: true, | ||
data: cloudTest, | ||
}; | ||
} catch (error) { | ||
console.error("Error fetching cloud test details:", error); | ||
return { | ||
success: false, | ||
error: appErrors.UNEXPECTED_ERROR, | ||
}; | ||
} | ||
} |
84 changes: 0 additions & 84 deletions
84
apps/app/src/app/[locale]/(app)/(dashboard)/tests/[testId]/actions/get-employee-details.ts
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
apps/app/src/app/[locale]/(app)/(dashboard)/tests/[testId]/actions/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { z } from "zod"; | ||
|
||
// Define the app errors | ||
export const appErrors = { | ||
NOT_FOUND: { message: "Cloud test not found" }, | ||
UNEXPECTED_ERROR: { message: "An unexpected error occurred" } | ||
}; | ||
|
||
export type AppError = typeof appErrors[keyof typeof appErrors]; | ||
|
||
// Define the input schema | ||
export const cloudTestDetailsInputSchema = z.object({ | ||
testId: z.string() | ||
}); | ||
|
||
export type CloudTestResult = { | ||
id: string; | ||
title: string; | ||
description: string | null; | ||
provider: string; | ||
status: string; | ||
config: any; | ||
authConfig: any; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
createdBy: { | ||
id: string; | ||
name: string | null; | ||
email: string | null; | ||
}; | ||
updatedBy: { | ||
id: string; | ||
name: string | null; | ||
email: string | null; | ||
}; | ||
runs: Array<{ | ||
id: string; | ||
status: string; | ||
result: string | null; | ||
resultDetails: any | null; | ||
startedAt: Date | null; | ||
completedAt: Date | null; | ||
executedBy: { | ||
id: string; | ||
name: string | null; | ||
email: string | null; | ||
}; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
}>; | ||
}; | ||
|
||
// Type-safe action response | ||
export type ActionResponse<T> = Promise< | ||
{ success: true; data: T } | { success: false; error: AppError } | ||
>; |
Oops, something went wrong.