-
Notifications
You must be signed in to change notification settings - Fork 7
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
1 parent
f2ac595
commit 289bc7c
Showing
9 changed files
with
232 additions
and
44 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,7 +1,58 @@ | ||
import { createTRPCRouter } from "../helpers"; | ||
import { z } from "zod"; | ||
import { eq, asc, and, gt } from "drizzle-orm"; | ||
import { createTRPCRouter, tenantProcedure } from "../helpers"; | ||
import { blueprints, db } from "~/db"; | ||
import { createId } from "@paralleldrive/cuid2"; | ||
|
||
// await ctx.db.insert(blueprints).values( | ||
// Array.from({ length: 1000 }).map((_, i) => ({ | ||
// // pk: i, | ||
// id: createId(), | ||
// name: `Blueprint ${i}`, | ||
// tenantPk: ctx.tenant.pk, | ||
// })), | ||
// ); | ||
|
||
export const blueprintRouter = createTRPCRouter({ | ||
// TODO: CRUD | ||
list: tenantProcedure.query(async function* ({ ctx }) { | ||
let cursor: string | undefined = undefined; | ||
do { | ||
const data = await db | ||
.select({ | ||
id: blueprints.id, | ||
name: blueprints.name, | ||
description: blueprints.description, | ||
}) | ||
.from(blueprints) | ||
.where( | ||
and( | ||
eq(blueprints.tenantPk, ctx.tenant.pk), | ||
cursor !== undefined ? gt(blueprints.id, cursor) : undefined, | ||
), | ||
) | ||
.limit(100) | ||
.orderBy(asc(blueprints.id)); | ||
|
||
cursor = data.length !== 0 ? data[data.length - 1]!.id : undefined; | ||
yield data; | ||
} while (cursor !== undefined); | ||
}), | ||
|
||
list2: tenantProcedure.query(async ({ ctx }) => { | ||
return await db | ||
.select({ | ||
id: blueprints.id, | ||
name: blueprints.name, | ||
description: blueprints.description, | ||
}) | ||
.from(blueprints) | ||
.where(eq(blueprints.tenantPk, ctx.tenant.pk)) | ||
.orderBy(asc(blueprints.id)); | ||
}), | ||
|
||
// TODO: create | ||
// TODO: update | ||
// TODO: delete | ||
|
||
// TODO: Add/remove devices | ||
// TODO: Modify content | ||
}); |
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
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
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
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,31 @@ | ||
// TODO: Remove this file once testing is done | ||
|
||
import { BreadcrumbItem } from "@mattrax/ui"; | ||
import { Suspense } from "solid-js"; | ||
import { useTenantId } from "~/app/(dash)"; | ||
import { Page } from "~/components/Page"; | ||
import { Table } from "~/components/Table"; | ||
import { trpc } from "~/lib"; | ||
|
||
export default function () { | ||
const tenantId = useTenantId(); | ||
|
||
const blueprints = trpc.blueprint.list2.createQuery(() => ({ | ||
tenantId: tenantId(), | ||
})); | ||
|
||
return ( | ||
<Page | ||
title="Blueprints" | ||
breadcrumbs={[ | ||
<BreadcrumbItem> | ||
<BreadcrumbItem>Blueprints</BreadcrumbItem> | ||
</BreadcrumbItem>, | ||
]} | ||
> | ||
<Suspense fallback={<p>TODO: Loading...</p>}> | ||
<Table data={blueprints.data?.flat() || []} /> | ||
</Suspense> | ||
</Page> | ||
); | ||
} |
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
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
Oops, something went wrong.