-
Notifications
You must be signed in to change notification settings - Fork 11
fix: Rename resource tables #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,8 @@ import { Queue, Worker } from "bullmq"; | |
| import { eq, takeFirstOrNull } from "@ctrlplane/db"; | ||
| import { db } from "@ctrlplane/db/client"; | ||
| import { | ||
| targetProvider, | ||
| targetProviderGoogle, | ||
| resourceProvider, | ||
| resourceProviderGoogle, | ||
| workspace, | ||
| } from "@ctrlplane/db/schema"; | ||
| import { upsertTargets } from "@ctrlplane/job-dispatch"; | ||
|
|
@@ -31,12 +31,12 @@ export const createTargetScanWorker = () => | |
|
|
||
| const tp = await db | ||
| .select() | ||
| .from(targetProvider) | ||
| .where(eq(targetProvider.id, targetProviderId)) | ||
| .innerJoin(workspace, eq(targetProvider.workspaceId, workspace.id)) | ||
| .from(resourceProvider) | ||
| .where(eq(resourceProvider.id, targetProviderId)) | ||
| .innerJoin(workspace, eq(resourceProvider.workspaceId, workspace.id)) | ||
| .leftJoin( | ||
| targetProviderGoogle, | ||
| eq(targetProvider.id, targetProviderGoogle.targetProviderId), | ||
| resourceProviderGoogle, | ||
| eq(resourceProvider.id, resourceProviderGoogle.resourceProviderId), | ||
|
Comment on lines
+34
to
+39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Parameter name doesn't match updated schema While the database query has been updated to use - const { targetProviderId } = job.data;
+ const { resourceProviderId } = job.data;
const tp = await db
.select()
.from(resourceProvider)
- .where(eq(resourceProvider.id, targetProviderId))
+ .where(eq(resourceProvider.id, resourceProviderId))
|
||
| ) | ||
| .then(takeFirstOrNull); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,7 +59,8 @@ export const JobTargetConditionRender: React.FC< | |
| ); | ||
| const system = systemQ.data; | ||
| const envFilters = | ||
| system?.environments.map((env) => env.targetFilter).filter(isPresent) ?? []; | ||
| system?.environments.map((env) => env.resourceFilter).filter(isPresent) ?? | ||
| []; | ||
|
Comment on lines
+62
to
+63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Incomplete migration: The migration from
🔗 Analysis chainLGTM! Verify environment filter migration. The change from 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify that all environment configurations use resourceFilter
# and none are still using targetFilter
# Search for any remaining targetFilter references in environment configurations
rg -l "targetFilter" --type ts --type tsx
# Search for new resourceFilter references to confirm migration
rg -l "resourceFilter" --type ts --type tsx
Length of output: 141 Script: #!/bin/bash
# Description: Verify that all environment configurations use resourceFilter
# and none are still using targetFilter
# Search for any remaining targetFilter references in environment configurations
rg -l "targetFilter" --glob "*.ts*"
# Search for new resourceFilter references to confirm migration
rg -l "resourceFilter" --glob "*.ts*"
Length of output: 1973 |
||
|
|
||
| const systemFilter: TargetCondition = { | ||
| type: FilterType.Comparison, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,7 +65,7 @@ export const CreateTargetVariableDialog: React.FC< | |
| const utils = api.useUtils(); | ||
| const onSubmit = form.handleSubmit((data) => | ||
| createTargetVariable | ||
| .mutateAsync({ targetId, ...data }) | ||
| .mutateAsync({ resourceId: targetId, ...data }) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM, but parameter naming is inconsistent with component interface. The change from |
||
| .then(() => utils.target.byId.invalidate(targetId)) | ||
| .then(() => form.reset()) | ||
| .then(() => setOpen(false)), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,7 +74,7 @@ export const EditTargetVariableDialog: React.FC< | |
| updateTargetVariable | ||
| .mutateAsync({ id: targetVariable.id, data }) | ||
| .then(() => form.reset(data)) | ||
| .then(() => utils.target.byId.invalidate(targetVariable.targetId)) | ||
| .then(() => utils.target.byId.invalidate(targetVariable.resourceId)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Multiple remaining references to 🔗 Analysis chainVerify schema and API endpoint alignment with the resource-centric model. The change from Let's verify the schema and API endpoint alignment: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify the schema changes and API endpoint alignment
# Check if the schema has been updated to use resourceId
ast-grep --pattern 'type TargetVariable = {
$$$
resourceId: $_
$$$
}'
# Check if there are any remaining references to targetId in the codebase
rg 'targetId.*=.*targetVariable\.' --type ts
Length of output: 264 Script: #!/bin/bash
# Description: Inspect the context of targetId usage in TargetVariableDropdown.tsx and search for all remaining targetId references.
# Extract lines surrounding the targetId usage for context
rg 'targetId\s*=' apps/webservice/src/app/[workspaceSlug]/_components/target-drawer/TargetVariableDropdown.tsx -A 3 -B 3
# Search for all remaining references to targetId in the codebase
rg 'targetId' --type ts
Length of output: 23027 |
||
| .then(() => setOpen(false)), | ||
| ); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,7 @@ export const TargetVariableDropdown: React.FC<TargetVariableDropdownProps> = ({ | |
| </EditTargetVariableDialog> | ||
| <DeleteTargetVariableDialog | ||
| variableId={targetVariable.id} | ||
| targetId={targetVariable.targetId} | ||
| targetId={targetVariable.resourceId} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification DeleteTargetVariableDialog still expects 🔗 Analysis chainVerify related component updates The prop value has been updated to use 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check if DeleteTargetVariableDialog has been updated to handle resourceId
# Look for the DeleteTargetVariableDialog component definition
ast-grep --pattern 'type $_ = {
$$$
targetId: $_
$$$
}'
# Check for any remaining references to targetId in related files
rg -g '*.{ts,tsx}' 'targetId.*resourceId' ./apps/webservice/src/app
Length of output: 3978 |
||
| onClose={() => setOpen(false)} | ||
| > | ||
| <DropdownMenuItem | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ export const SystemActionsDropdown: React.FC<SystemActionsDropdownProps> = ({ | |
| }) => { | ||
| const { workspaceSlug } = useParams<{ workspaceSlug: string }>(); | ||
| const envFilters = system.environments | ||
| .map((env) => env.targetFilter) | ||
| .map((env) => env.resourceFilter) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Incomplete rename of
🔗 Analysis chainLGTM! Consistent with resource-centric model transition. The change from Let's verify this change is consistent across the codebase: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check for any remaining instances of targetFilter that might need updating
# and verify resourceFilter is used consistently
# Check for any remaining targetFilter instances
echo "Checking for remaining targetFilter instances:"
rg "targetFilter" -l
# Check for consistent usage of resourceFilter
echo "Verifying resourceFilter usage:"
rg "resourceFilter" -l
# Check specifically in environment-related files
echo "Checking environment-related files:"
ast-grep --pattern 'type Environment = {
$$$
}'
Length of output: 2268 |
||
| .filter(isPresent); | ||
| const filter: TargetCondition = { | ||
| type: TargetFilterType.Comparison, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,7 +126,7 @@ const ReleaseCell: React.FC<{ | |
| (releaseJobTrigger) => | ||
| isPresent(releaseJobTrigger.environmentId) && | ||
| isPresent(releaseJobTrigger.releaseId) && | ||
| isPresent(releaseJobTrigger.targetId), | ||
| isPresent(releaseJobTrigger.target.id), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Inconsistent Usage of Multiple instances of 🔗 Analysis chainVerify data structure changes across the codebase The change from Let's verify the consistency of this change across the codebase: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check for any remaining direct targetId references that might need updating
# Search for direct targetId references
rg "targetId" -A 5
# Search for the new target.id pattern
rg "target\.id" -A 5
Length of output: 124 Script: #!/bin/bash
# Description: Check for any remaining direct targetId references that might need updating
# Search for direct targetId references in .ts and .tsx files
rg "targetId" --glob "*.ts" --glob "*.tsx" -A 5
# Search for the new target.id pattern in .ts and .tsx files
rg "target\.id" --glob "*.ts" --glob "*.tsx" -A 5
Length of output: 124110 |
||
| ) | ||
| .map((releaseJobTrigger) => ({ ...releaseJobTrigger })); | ||
| return ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,7 @@ const Variables: React.FC<{ | |
| operator: TargetOperator.Or, | ||
| conditions: await api.environment | ||
| .bySystemId(deployment.systemId) | ||
| .then((envs) => envs.map((e) => e.targetFilter).filter(isPresent)), | ||
| .then((envs) => envs.map((e) => e.resourceFilter).filter(isPresent)), | ||
| }; | ||
|
|
||
| const variablesPromises = variablesByDeployment.map(async (variable) => { | ||
|
|
@@ -43,7 +43,7 @@ const Variables: React.FC<{ | |
| const rest = variable.values.filter((v) => v.id !== defaultValue?.id); | ||
|
|
||
| const valuesPromises = rest.map(async (v) => { | ||
| if (v.targetFilter == null) | ||
| if (v.resourceFilter == null) | ||
| return { | ||
| ...v, | ||
| targetCount: 0, | ||
|
|
@@ -52,13 +52,13 @@ const Variables: React.FC<{ | |
| }; | ||
|
|
||
| const filterHash = LZString.compressToEncodedURIComponent( | ||
| JSON.stringify(v.targetFilter), | ||
| JSON.stringify(v.resourceFilter), | ||
| ); | ||
|
|
||
| const filter: ComparisonCondition = { | ||
| type: TargetFilterType.Comparison, | ||
| operator: TargetOperator.And, | ||
| conditions: [systemTargetsFilter, v.targetFilter], | ||
| conditions: [systemTargetsFilter, v.resourceFilter], | ||
| }; | ||
|
|
||
| const targets = await api.target.byWorkspaceId.list({ | ||
|
|
@@ -78,7 +78,7 @@ const Variables: React.FC<{ | |
| const values = await Promise.all(valuesPromises); | ||
|
|
||
| if (defaultValue != null) { | ||
| const restFilters = rest.map((v) => v.targetFilter).filter(isPresent); | ||
| const restFilters = rest.map((v) => v.resourceFilter).filter(isPresent); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Update target-centric names for consistency. Numerous instances of target-centric terminology were found across the codebase, including:
Refactoring these for consistency with resource-centric naming will enhance maintainability. 🔗 Analysis chainConsider updating related target-centric names for consistency. While
This mix of resource-centric and target-centric terminology could be confusing for future maintenance. Let's check for other occurrences of target-centric naming that might need updates: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for target-related API endpoints and types
rg "api\.target\." --type typescript
rg "type.*Target.*=" --type typescript
Length of output: 87 Script: #!/bin/bash
# Comprehensive search for any target-related terms in TypeScript files
rg "target" --type typescript
Length of output: 64 Script: #!/bin/bash
# Search for target-related terms in TypeScript files using correct file extensions
rg "target" --glob "*.ts" --glob "*.tsx"
Length of output: 177455 |
||
|
|
||
| const filter: TargetCondition = | ||
| restFilters.length === 0 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -423,7 +423,7 @@ export const TargetReleaseTable: React.FC<TargetReleaseTableProps> = ({ | |
| environment: environments.find( | ||
| (e) => e.id === triggers[0]!.environmentId, | ||
| ), | ||
| targets: _.groupBy(triggers, (t) => t.targetId), | ||
| targets: _.groupBy(triggers, (t) => t.target.id), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Additional An additional instance of grouping by 🔗 Analysis chainVerify the impact of grouping change The grouping by 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check for other instances of target.id grouping
# to ensure consistent transition to resource-centric model
# Search for similar grouping patterns
rg -U "groupBy.*target.id|target.id.*groupBy" --type tsx --type ts
# Search for other potential target references that might need updating
rg -l "target\." --type tsx --type ts
Length of output: 164 Script: #!/bin/bash
# Description: Check for other instances of target.id grouping
# to ensure consistent transition to resource-centric model
# Search for similar grouping patterns in .tsx and .ts files
rg -U "groupBy.*target\.id|target\.id.*groupBy" -g "*.tsx" -g "*.ts"
# Search for other potential target references that might need updating in .tsx and .ts files
rg -l "target\." -g "*.tsx" -g "*.ts"
Length of output: 8470 |
||
| })) | ||
| .filter((t) => isPresent(t.environment)) | ||
| .value(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,7 +80,7 @@ const EditVariableValueDialog: React.FC<{ | |
| schema: editVariableValueFormSchema, | ||
| defaultValues: { | ||
| value: value.value, | ||
| targetFilter: value.targetFilter, | ||
| targetFilter: value.resourceFilter, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Complete the target-to-resource renaming transition While the data layer has been updated to use Consider applying this comprehensive rename: -const editVariableValueFormSchema = z.object({
- value: z.union([z.string(), z.number(), z.boolean()]),
- targetFilter: targetCondition
+const editVariableValueFormSchema = z.object({
+ value: z.union([z.string(), z.number(), z.boolean()]),
+ resourceFilter: targetCondition // Note: Consider renaming targetCondition to resourceCondition as well
.nullish()
.refine((data) => data == null || isValidTargetCondition(data), {
message: "Invalid target condition",
}),
default: z.boolean().optional(),
});
const form = useForm({
schema: editVariableValueFormSchema,
defaultValues: {
value: value.value,
- targetFilter: value.resourceFilter,
+ resourceFilter: value.resourceFilter,
default: variable.defaultValueId === value.id,
},
});
const onSubmit = form.handleSubmit((data) =>
update
.mutateAsync({
id: value.id,
- data: { ...data, resourceFilter: data.targetFilter },
+ data: data,
})Also update the form field: <FormField
control={form.control}
- name="targetFilter"
+ name="resourceFilter"
render={({ field: { value, onChange } }) => (
<FormItem>
- <FormLabel>Target filter</FormLabel>
+ <FormLabel>Resource filter</FormLabel>And the clear filter button: <Button
variant="outline"
type="button"
- onClick={() => form.setValue("targetFilter", null)}
+ onClick={() => form.setValue("resourceFilter", null)}
>
Clear filter
</Button>Also applies to: 92-92 |
||
| default: variable.defaultValueId === value.id, | ||
| }, | ||
| }); | ||
|
|
@@ -89,7 +89,7 @@ const EditVariableValueDialog: React.FC<{ | |
| update | ||
| .mutateAsync({ | ||
| id: value.id, | ||
| data, | ||
| data: { ...data, resourceFilter: data.targetFilter }, | ||
| }) | ||
| .then(() => router.refresh()) | ||
| .then(onClose), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ export default async function VariablesPage({ | |
| operator: TargetOperator.Or, | ||
| conditions: await api.environment | ||
| .bySystemId(deployment.systemId) | ||
| .then((envs) => envs.map((e) => e.targetFilter).filter(isPresent)), | ||
| .then((envs) => envs.map((e) => e.resourceFilter).filter(isPresent)), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Incomplete Transition to Resource-Centric Terminology Detected The transition from target-centric to resource-centric terminology is not fully implemented. Numerous files still use target-specific types and operators. Areas Needing Attention:
🔗 Analysis chainVerify complete transition from target to resource terminology While Consider creating a follow-up task to rename these types to maintain consistency with the resource-centric model:
🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for remaining target-related types that should be renamed
rg "Target(Filter|Operator|Condition)" --type ts
Length of output: 35420 |
||
| }; | ||
|
|
||
| const variablesPromises = variablesByDeployment.map(async (variable) => { | ||
|
|
@@ -41,7 +41,7 @@ export default async function VariablesPage({ | |
| const rest = variable.values.filter((v) => v.id !== defaultValue?.id); | ||
|
|
||
| const valuesPromises = rest.map(async (v) => { | ||
| if (v.targetFilter == null) | ||
| if (v.resourceFilter == null) | ||
| return { | ||
| ...v, | ||
| targetCount: 0, | ||
|
|
@@ -50,13 +50,13 @@ export default async function VariablesPage({ | |
| }; | ||
|
|
||
| const filterHash = LZString.compressToEncodedURIComponent( | ||
| JSON.stringify(v.targetFilter), | ||
| JSON.stringify(v.resourceFilter), | ||
| ); | ||
|
|
||
| const filter: ComparisonCondition = { | ||
| type: TargetFilterType.Comparison, | ||
| operator: TargetOperator.And, | ||
| conditions: [systemTargetsFilter, v.targetFilter], | ||
| conditions: [systemTargetsFilter, v.resourceFilter], | ||
| }; | ||
|
|
||
| const targets = await api.target.byWorkspaceId.list({ | ||
|
|
@@ -76,7 +76,7 @@ export default async function VariablesPage({ | |
| const values = await Promise.all(valuesPromises); | ||
|
|
||
| if (defaultValue != null) { | ||
| const restFilters = rest.map((v) => v.targetFilter).filter(isPresent); | ||
| const restFilters = rest.map((v) => v.resourceFilter).filter(isPresent); | ||
|
|
||
| const filter: TargetCondition = | ||
| restFilters.length === 0 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,10 +11,10 @@ import { | |
| jobVariable, | ||
| release, | ||
| releaseJobTrigger, | ||
| resource, | ||
| resourceMetadata, | ||
| runbook, | ||
| runbookJobTrigger, | ||
| target, | ||
| targetMetadata, | ||
| updateJob, | ||
| user, | ||
| } from "@ctrlplane/db/schema"; | ||
|
|
@@ -80,7 +80,7 @@ export const GET = request() | |
| environment, | ||
| eq(environment.id, releaseJobTrigger.environmentId), | ||
| ) | ||
| .leftJoin(target, eq(target.id, releaseJobTrigger.targetId)) | ||
| .leftJoin(resource, eq(resource.id, releaseJobTrigger.resourceId)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider updating response mapping to use consistent terminology. While the database query correctly uses the new Consider updating the response mapping to use consistent terminology: .then((row) => ({
job: row.job,
runbook: row.runbook,
environment: row.environment,
- target: row.resource,
+ resource: row.resource,
deployment: row.deployment,
release: row.release,
}));Note: This change might require coordinated updates in API clients and documentation. Also applies to: 89-94 |
||
| .leftJoin(release, eq(release.id, releaseJobTrigger.releaseId)) | ||
| .leftJoin(deployment, eq(deployment.id, release.deploymentId)) | ||
| .where(eq(job.id, params.jobId)) | ||
|
|
@@ -116,8 +116,8 @@ export const GET = request() | |
|
|
||
| const jobTargetMetadataRows = await db | ||
| .select() | ||
| .from(targetMetadata) | ||
| .where(eq(targetMetadata.targetId, je.target?.id ?? "")); | ||
| .from(resourceMetadata) | ||
| .where(eq(resourceMetadata.resourceId, je.target?.id ?? "")); | ||
|
|
||
| const metadata = Object.fromEntries( | ||
| jobTargetMetadataRows.map((m) => [m.key, m.value]), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,11 @@ import { z } from "zod"; | |
|
|
||
| import { eq, takeFirstOrNull } from "@ctrlplane/db"; | ||
| import { db } from "@ctrlplane/db/client"; | ||
| import { createTarget, targetProvider, workspace } from "@ctrlplane/db/schema"; | ||
| import { | ||
| createTarget, | ||
| resourceProvider, | ||
| workspace, | ||
| } from "@ctrlplane/db/schema"; | ||
|
Comment on lines
+7
to
+11
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Inconsistent naming: 'createTarget' still present Multiple files still reference "createTarget" or "targetProvider", indicating that the refactoring to resource-centric terminology is incomplete.
🔗 Analysis chainVerify naming consistency across schema imports While 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check for any remaining "target" references in schema definitions
# and their corresponding usage in the codebase
# Check schema definitions
echo "Checking schema definitions..."
rg -l "createTarget|targetProvider" --type ts
# Check for mixed usage of target/resource terminology
echo "Checking for mixed terminology..."
ast-grep --pattern 'import { $$$ resource$$$ $$$ } from "@ctrlplane/db/schema"'
Length of output: 1428 |
||
| import { upsertTargets } from "@ctrlplane/job-dispatch"; | ||
| import { Permission } from "@ctrlplane/validators/auth"; | ||
|
|
||
|
|
@@ -55,9 +59,9 @@ export const PATCH = request() | |
|
|
||
| const query = await db | ||
| .select() | ||
| .from(targetProvider) | ||
| .innerJoin(workspace, eq(workspace.id, targetProvider.workspaceId)) | ||
| .where(eq(targetProvider.id, params.providerId)) | ||
| .from(resourceProvider) | ||
| .innerJoin(workspace, eq(workspace.id, resourceProvider.workspaceId)) | ||
| .where(eq(resourceProvider.id, params.providerId)) | ||
| .then(takeFirstOrNull); | ||
|
|
||
| const provider = query?.resource_provider; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,8 +21,8 @@ export const GET = request() | |
| }), | ||
| ) | ||
| .handle(async ({ db }, { params }: { params: { targetId: string } }) => { | ||
| const data = await db.query.target.findFirst({ | ||
| where: eq(schema.target.id, params.targetId), | ||
| const data = await db.query.resource.findFirst({ | ||
| where: eq(schema.resource.id, params.targetId), | ||
|
Comment on lines
+24
to
+25
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Maintain consistency in resource terminology While the database schema has been updated to use Consider updating the error message and variable names: if (data == null)
- return NextResponse.json({ error: "Target not found" }, { status: 404 });
+ return NextResponse.json({ error: "Resource not found" }, { status: 404 });
- const { metadata, ...target } = data;
+ const { metadata, ...resource } = data;
|
||
| with: { | ||
| metadata: true, | ||
| variables: true, | ||
|
|
@@ -73,8 +73,8 @@ export const PATCH = request() | |
| { body: z.infer<typeof patchSchema> }, | ||
| { params: { targetId: string } } | ||
| >(async ({ db, body }, { params }) => { | ||
| const target = await db.query.target.findFirst({ | ||
| where: eq(schema.target.id, params.targetId), | ||
| const target = await db.query.resource.findFirst({ | ||
| where: eq(schema.resource.id, params.targetId), | ||
|
Comment on lines
+76
to
+77
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Update PATCH handler to use resource terminology The schema validation and variable names should be updated to maintain consistency with the resource model. Consider renaming the schema and variables: - const patchSchema = z.object({
+ const resourcePatchSchema = z.object({
// ... schema definition ...
});
- const target = await db.query.resource.findFirst({
+ const resource = await db.query.resource.findFirst({
where: eq(schema.resource.id, params.targetId),
});
if (target == null)
- return NextResponse.json({ error: "Target not found" }, { status: 404 });
+ return NextResponse.json({ error: "Resource not found" }, { status: 404 });
|
||
| }); | ||
|
|
||
| if (target == null) | ||
|
|
@@ -95,14 +95,16 @@ export const DELETE = request() | |
| ), | ||
| ) | ||
| .handle(async ({ db }, { params }: { params: { targetId: string } }) => { | ||
| const target = await db.query.target.findFirst({ | ||
| where: eq(schema.target.id, params.targetId), | ||
| const target = await db.query.resource.findFirst({ | ||
| where: eq(schema.resource.id, params.targetId), | ||
|
Comment on lines
+98
to
+99
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Align DELETE handler with resource terminology While the database operations have been updated, the variable names and error messages still use the old terminology. Consider updating the variable names and error messages: - const target = await db.query.resource.findFirst({
+ const resource = await db.query.resource.findFirst({
where: eq(schema.resource.id, params.targetId),
});
- if (target == null)
- return NextResponse.json({ error: "Target not found" }, { status: 404 });
+ if (resource == null)
+ return NextResponse.json({ error: "Resource not found" }, { status: 404 });Also applies to: 105-107 |
||
| }); | ||
|
|
||
| if (target == null) | ||
| return NextResponse.json({ error: "Target not found" }, { status: 404 }); | ||
|
|
||
| await db.delete(schema.target).where(eq(schema.target.id, params.targetId)); | ||
| await db | ||
| .delete(schema.resource) | ||
| .where(eq(schema.resource.id, params.targetId)); | ||
|
|
||
| return NextResponse.json({ success: true }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Incomplete renaming of
targettoresourcedetectedMultiple instances of
targetandTargetremain in the codebase, indicating that the renaming process is not fully complete. Please update the following files to ensure consistency:packages/api/src/dispatch.tsapps/event-worker/src/target-scan/index.tspackages/api/src/router/target-provider.tspackages/validators/src/events/index.tspackages/api/src/router/target.tsapps/webservice/src/app/[workspaceSlug]/(targets)/target-providers/page.tsxapps/webservice/src/app/[workspaceSlug]/(targets)/target-providers/add/page.tsxapps/webservice/src/app/[workspaceSlug]/(targets)/target-providers/integrations/google/UpdateGoogleProviderDialog.tsxapps/webservice/src/app/[workspaceSlug]/(targets)/layout.tsxapps/event-worker/src/target-scan/gke.ts🔗 Analysis chain
Verify consistency of resource/target terminology
While the schema imports have been updated to use
resourceterminology, other imports still usetarget(e.g.,InsertTarget,TargetScanEvent). This mixing of terms could lead to confusion.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 7449