Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/api/src/builders/builders.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function findAll(
search: string | undefined,
limit: number,
offset: number,
): E.Effect<{ data: BuilderDocument[]; total: number }, CollectionNotFoundError | DatabaseError> {
): E.Effect<{ data: BuilderDocument[]; total: number; unmigrated: number }, CollectionNotFoundError | DatabaseError> {
const filter: Record<string, unknown> = {};
if (search) {
const escaped = search.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
Expand All @@ -64,9 +64,13 @@ export function findAll(
try: () => collection.countDocuments(filter),
catch: (cause) => new DatabaseError({ cause, message: "findAll:count" }),
}),
E.tryPromise({
try: () => collection.countDocuments({ creditsUsd: { $exists: false } }),
catch: (cause) => new DatabaseError({ cause, message: "findAll:unmigrated" }),
}),
]),
),
E.map(([data, total]) => ({ data, total })),
E.map(([data, total, unmigrated]) => ({ data, total, unmigrated })),
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/credits/credits.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export function adminListBuilders(options: ControllerOptions): void {
return pipe(
BuildersRepository.findAll(c.env, search, limit, offset),
E.map(
({ data, total }): AdminListBuildersResponse => ({
({ data, total, unmigrated }): AdminListBuildersResponse => ({
data: data.map((b) => ({
did: b.did,
name: b.name,
Expand All @@ -384,7 +384,7 @@ export function adminListBuilders(options: ControllerOptions): void {
: b.status) as BuilderStatusDto,
storageBytes: b.storageBytes ?? 0,
})),
pagination: { total, limit, offset },
pagination: { total, limit, offset, unmigrated },
}),
),
E.map((response) => c.json<AdminListBuildersResponse>(response)),
Expand Down
18 changes: 14 additions & 4 deletions packages/types/src/admin.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from "zod";

import { BuilderStatusDto } from "./credits.dto";
import { PaginatedResponse } from "./pagination.dto";
import { SortQuerySchema } from "./pagination.dto";
import { ApiSuccessResponse } from "./responses.dto";

/**
Expand Down Expand Up @@ -43,10 +43,20 @@ const AdminBuilderDto = z.object({

/**
* Paginated list of builders for admin view.
* Extends the standard pagination with an unmigrated count for the migration banner.
*/
export const AdminListBuildersResponse = PaginatedResponse(AdminBuilderDto).meta({
ref: "AdminListBuildersResponse",
});
export const AdminListBuildersResponse = z
.object({
data: z.array(AdminBuilderDto),
pagination: z.object({
total: z.number().int().min(0),
limit: z.number().int().min(1),
offset: z.number().int().min(0),
sort: SortQuerySchema,
unmigrated: z.number().int().min(0),
}),
})
.meta({ ref: "AdminListBuildersResponse" });
export type AdminListBuildersResponse = z.infer<typeof AdminListBuildersResponse>;

/**
Expand Down
Loading