Skip to content

Commit

Permalink
feat: add latest version to /projects/:id/components (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
fgmadeira authored Feb 19, 2024
1 parent 72c8110 commit bf857e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 14 additions & 2 deletions ethereal-nexus-dashboard/src/data/projects/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,24 @@ export async function getActiveProjectComponents(
return actionError('No user provided.');
}

const latest_version = db.select()
.from(componentVersions)
.orderBy(desc(componentVersions.created_at))
.groupBy(
componentVersions.id,
componentVersions.version,
componentVersions.created_at,
)
.limit(1)
.as('latest_version');

try {
const select = await db
.select({
...getTableColumns(components),
is_active: projectComponentConfig.is_active,
version: componentVersions.version,
dialog: componentVersions.dialog,
version: sql`coalesce(${componentVersions.version}, ${latest_version.version})`,
dialog: sql`coalesce(${componentVersions.dialog}, ${latest_version.dialog})`,
})
.from(components)
.leftJoin(
Expand All @@ -194,6 +205,7 @@ export async function getActiveProjectComponents(
componentVersions,
eq(componentVersions.id, projectComponentConfig.component_version),
)
.leftJoin(latest_version, eq(latest_version.component_id, projectComponentConfig.component_id))
.where(eq(projectComponentConfig.is_active, true));

const safe = projectComponentsWithDialogSchema.array().safeParse(select);
Expand Down
4 changes: 3 additions & 1 deletion ethereal-nexus-dashboard/src/data/projects/dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ export const projectComponentsSchema = componentsSchema.extend({
});
export type ProjectComponent = z.infer<typeof projectComponentsSchema>;

export const projectComponentsWithDialogSchema = projectComponentsSchema.extend(
export const projectComponentsWithDialogSchema = projectComponentsSchema
.omit({versions: true})
.extend(
{
dialog: componentVersionsSchema.shape.dialog.nullable(),
},
Expand Down

0 comments on commit bf857e3

Please sign in to comment.