Skip to content

Commit

Permalink
fix: update project component structure
Browse files Browse the repository at this point in the history
  • Loading branch information
fgmadeira committed Feb 19, 2024
1 parent bf857e3 commit e5bdbab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { headers } from 'next/headers';
import { authenticatedWithKey } from '@/lib/route-wrappers';
import { NextRequest, NextResponse } from 'next/server';
import { updateAssets } from '@/data/components/actions';
import * as console from 'console';

const fileTypes: FileTypes = {
'text/css': 'css',
Expand Down Expand Up @@ -121,6 +122,7 @@ export const POST = authenticatedWithKey(
const { request: responseFromBlob = {} as any } = _response;
const { url } = responseFromBlob;

console.log('POST assets', JSON.stringify(_response, undefined, 2))
if (!url) {
return NextResponse.json('Failed to upload assets', {
status: HttpStatus.BAD_REQUEST,
Expand All @@ -133,13 +135,13 @@ export const POST = authenticatedWithKey(
fileTypes[contentType],
);
if (!response.success) {
return NextResponse.json('Failed to upload assets', {
return NextResponse.json('Failed to update assets', {
status: HttpStatus.BAD_REQUEST,
});
}
return NextResponse.json(response.data);
} catch {
return NextResponse.json('Failed to upload assets', {
return NextResponse.json('Failed to put assets', {
status: HttpStatus.BAD_REQUEST,
});
}
Expand Down
6 changes: 6 additions & 0 deletions ethereal-nexus-dashboard/src/data/components/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export async function updateAssets(
!selectComponentVersion?.id ||
!selectComponentVersion.versions?.length
) {
console.error('updateAssets: failed to fetch component version', selectComponentVersion)
return actionError(
`Failed to fetch component with name ${componentName}.`,
);
Expand All @@ -170,6 +171,7 @@ export async function updateAssets(
componentAssetsCreateSchema.safeParse(assetToUpsert);

if (!safeAssetToUpsert.success) {
console.error('updateAssets: asset input is not valid', JSON.stringify(safeAssetToUpsert, undefined, 2))
return actionZodError(
"There's an issue with the components assets record.",
safeAssetToUpsert.error,
Expand All @@ -196,6 +198,8 @@ export async function updateAssets(
upsertedAsset = componentAssetsSchema.safeParse(insertAssetsResult[0]);

if (!upsertedAsset.success) {
console.error('updateAssets: failed to upsert asset', JSON.stringify(upsertedAsset, undefined, 2))

return actionZodError(
"There's an issue with the inserted components assets record.",
upsertedAsset.error,
Expand Down Expand Up @@ -223,6 +227,8 @@ export async function updateAssets(
updateAssetResult[0],
);
if (!updatedAsset.success) {
console.error('updateAssets: failed to upsert asset', JSON.stringify(updatedAsset, undefined, 2))

return actionZodError(
'There was an issue updating the components version.',
updatedAsset.error,
Expand Down
13 changes: 5 additions & 8 deletions ethereal-nexus-dashboard/src/data/projects/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,7 @@ export async function getProjectComponentConfig(
ARRAY_AGG(
jsonb_build_object(
'id', ${componentAssets.id},
'component_id', ${componentAssets.component_id},
'version_id', ${componentAssets.version_id},
'url', ${componentAssets.url},
'filePath', ${componentAssets.url},
'type', ${componentAssets.type}
)
)
Expand All @@ -265,12 +263,11 @@ export async function getProjectComponentConfig(
try{
const result = await db
.select({
id: projectComponentConfig.project_id,
component: {
id: components.id,
name: components.name,
},
id: components.id,
name: components.name,
title: components.title,
version: sql`coalesce(${componentVersions.version}, ${latest_version.version})`,
dialog: sql`coalesce(${componentVersions.dialog}, ${latest_version.dialog})`,
assets,
})
.from(projectComponentConfig)
Expand Down

0 comments on commit e5bdbab

Please sign in to comment.