Skip to content

Commit 030752f

Browse files
committed
docs(changeset):
fix: added error handling to filesWithTags. improved query consitency
1 parent a7e80c7 commit 030752f

File tree

6 files changed

+50
-46
lines changed

6 files changed

+50
-46
lines changed

.changeset/soft-chicken-work.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nimbus/server": patch
3+
---
4+
5+
fix: 5.8.3 is preferred Typescript version rn fix: added error handling to filesWithTags. improved query consitency

apps/server/src/routes/files/file-service.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,17 @@ export class FileService {
4343
return null;
4444
}
4545

46-
// Add tags to files
46+
// Add tags to files, handling any tag retrieval failures
4747
const filesWithTags = await Promise.all(
4848
res.items.map(async item => {
4949
if (!item.id) return { ...item, tags: [] };
50-
const tags = await this.tagService.getFileTags(item.id, user.id);
51-
return { ...item, tags };
50+
try {
51+
const tags = await this.tagService.getFileTags(item.id, user.id);
52+
return { ...item, tags };
53+
} catch (error) {
54+
console.error(`Failed to get tags for file ${item.id}:`, error);
55+
return { ...item, tags: [] };
56+
}
5257
})
5358
);
5459

apps/server/src/routes/tags/tag-service.ts

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export class TagService {
1616
// Get all tags for a user with file counts
1717
async getUserTags(userId: string): Promise<Tag[]> {
1818
// Get all tags for the user
19-
const userTags = await this.c.var.db.select().from(tag).where(eq(tag.userId, userId)).orderBy(tag.name);
19+
const userTags = await this.c.var.db.query.tag.findMany({
20+
where: (table, { eq }) => eq(table.userId, userId),
21+
orderBy: (table, { asc }) => asc(table.name),
22+
});
2023

2124
// Get file counts for each tag
2225
const tagsWithCounts = await Promise.all(
@@ -42,22 +45,17 @@ export class TagService {
4245

4346
// Get a specific tag by ID
4447
async getTagById(tagId: string, userId: string): Promise<Tag | null> {
45-
const tagRecord = await this.c.var.db
46-
.select()
47-
.from(tag)
48-
.where(and(eq(tag.id, tagId), eq(tag.userId, userId)))
49-
.limit(1);
48+
const record = await this.c.var.db.query.tag.findFirst({
49+
where: (table, { and, eq }) => and(eq(table.id, tagId), eq(table.userId, userId)),
50+
});
5051

51-
if (!tagRecord.length) return null;
52+
if (!record) return null;
5253

5354
const fileCount = await this.c.var.db
5455
.select({ count: count() })
5556
.from(fileTag)
5657
.where(and(eq(fileTag.tagId, tagId), eq(fileTag.userId, userId)));
5758

58-
const record = tagRecord[0];
59-
if (!record) return null;
60-
6159
return {
6260
id: record.id,
6361
name: record.name,
@@ -85,9 +83,11 @@ export class TagService {
8583
? and(eq(tag.name, name), eq(tag.userId, userId), eq(tag.parentId, parentId))
8684
: and(eq(tag.name, name), eq(tag.userId, userId), isNull(tag.parentId));
8785

88-
const existingTag = await this.c.var.db.select().from(tag).where(existingTagQuery).limit(1);
86+
const existingTag = await this.c.var.db.query.tag.findFirst({
87+
where: existingTagQuery,
88+
});
8989

90-
if (existingTag.length > 0) {
90+
if (existingTag) {
9191
throw new Error("Tag with this name already exists");
9292
}
9393

@@ -140,9 +140,11 @@ export class TagService {
140140
? and(eq(tag.name, updates.name), eq(tag.userId, userId), eq(tag.parentId, newParentId))
141141
: and(eq(tag.name, updates.name), eq(tag.userId, userId), isNull(tag.parentId));
142142

143-
const nameConflict = await this.c.var.db.select().from(tag).where(nameConflictQuery).limit(1);
143+
const nameConflict = await this.c.var.db.query.tag.findFirst({
144+
where: nameConflictQuery,
145+
});
144146

145-
if (nameConflict.length > 0) {
147+
if (nameConflict) {
146148
throw new Error("Tag with this name already exists");
147149
}
148150
}
@@ -191,10 +193,10 @@ export class TagService {
191193
}
192194

193195
// Check for existing associations
194-
const existingAssociations = await this.c.var.db
195-
.select()
196-
.from(fileTag)
197-
.where(and(eq(fileTag.fileId, fileId), inArray(fileTag.tagId, tagIds), eq(fileTag.userId, userId)));
196+
const existingAssociations = await this.c.var.db.query.fileTag.findMany({
197+
where: (table, { and, eq, inArray }) =>
198+
and(eq(table.fileId, fileId), inArray(table.tagId, tagIds), eq(table.userId, userId)),
199+
});
198200

199201
const existingTagIds = existingAssociations.map(assoc => assoc.tagId);
200202
const newTagIds = tagIds.filter(tagId => !existingTagIds.includes(tagId));
@@ -239,21 +241,17 @@ export class TagService {
239241

240242
// Get all tags for a specific file
241243
async getFileTags(fileId: string, userId: string): Promise<Tag[]> {
242-
const fileTagAssociations = await this.c.var.db
243-
.select({
244-
tagId: fileTag.tagId,
245-
})
246-
.from(fileTag)
247-
.where(and(eq(fileTag.fileId, fileId), eq(fileTag.userId, userId)));
244+
const fileTagAssociations = await this.c.var.db.query.fileTag.findMany({
245+
where: (table, { and, eq }) => and(eq(table.fileId, fileId), eq(table.userId, userId)),
246+
});
248247

249248
const tagIds = fileTagAssociations.map(assoc => assoc.tagId);
250249

251250
if (tagIds.length === 0) return [];
252251

253-
const tags = await this.c.var.db
254-
.select()
255-
.from(tag)
256-
.where(and(inArray(tag.id, tagIds), eq(tag.userId, userId)));
252+
const tags = await this.c.var.db.query.tag.findMany({
253+
where: (table, { and, inArray, eq }) => and(inArray(table.id, tagIds), eq(table.userId, userId)),
254+
});
257255

258256
return tags.map(tagRecord => ({
259257
...tagRecord,
@@ -265,10 +263,9 @@ export class TagService {
265263

266264
// Get all child tag IDs recursively
267265
private async getAllChildTagIds(parentId: string, userId: string): Promise<string[]> {
268-
const childTags = await this.c.var.db
269-
.select({ id: tag.id })
270-
.from(tag)
271-
.where(and(eq(tag.parentId, parentId), eq(tag.userId, userId)));
266+
const childTags = await this.c.var.db.query.tag.findMany({
267+
where: (table, { and, eq }) => and(eq(table.parentId, parentId), eq(table.userId, userId)),
268+
});
272269

273270
const childIds = childTags.map(tag => tag.id);
274271
const grandChildIds = await Promise.all(childIds.map(childId => this.getAllChildTagIds(childId, userId)));

apps/server/src/routes/waitlist/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { sendError, sendSuccess } from "../utils";
33
import { zValidator } from "@hono/zod-validator";
44
import { createPublicRouter } from "../../hono";
55
import { waitlist } from "@nimbus/db/schema";
6-
import { count, eq } from "drizzle-orm";
6+
import { count } from "drizzle-orm";
77
import { nanoid } from "nanoid";
88

99
const waitlistRouter = createPublicRouter()
@@ -29,12 +29,9 @@ const waitlistRouter = createPublicRouter()
2929
try {
3030
const email = c.req.valid("json").email;
3131

32-
const existing = await c.var.db
33-
.select()
34-
.from(waitlist)
35-
.where(eq(waitlist.email, email.toLowerCase().trim()))
36-
.limit(1)
37-
.then(rows => rows[0]);
32+
const existing = await c.var.db.query.waitlist.findFirst({
33+
where: (table, { eq }) => eq(table.email, email.toLowerCase().trim()),
34+
});
3835

3936
if (existing) {
4037
return sendError(c, { message: "This email is already on the waitlist", status: 400 });

bun.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "nimbus",
66
"devDependencies": {
77
"@changesets/cli": "^2.29.5",
8-
"@cloudflare/workers-types": "^4.20250731.0",
8+
"@cloudflare/workers-types": "^4.20250801.0",
99
"@nimbus/eslint": "workspace:*",
1010
"@nimbus/tsconfig": "workspace:*",
1111
"concurrently": "^9.2.0",
@@ -373,7 +373,7 @@
373373

374374
"@cloudflare/workerd-windows-64": ["@cloudflare/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-paVHgocuilMzOU+gEyKR/86j/yI+QzmSHRnqdd8OdQ37Hf6SyPX7kQj6VVNRXbzVHWix1WxaJsXfTGK1LK05wA=="],
375375

376-
"@cloudflare/workers-types": ["@cloudflare/workers-types@4.20250731.0", "", {}, "sha512-J8tz6dQ0gZKzDKNLl3LW7Uvj7rRllKw5UD61fBDf8IGizH9CKznjrdvqRQHB9Qb8yopqjylcx2lxiC3angF4Pw=="],
376+
"@cloudflare/workers-types": ["@cloudflare/workers-types@4.20250801.0", "", {}, "sha512-BQmMdoOGClY23TesgkR1PeGrPvPsSFD/zW7pDzWZHkOEsqkPk2A91h52bP8GbtKYTl1vdaYjQgJlGsP6Ih4G0w=="],
377377

378378
"@cspotcode/source-map-support": ["@cspotcode/[email protected]", "", { "dependencies": { "@jridgewell/trace-mapping": "0.3.9" } }, "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw=="],
379379

@@ -937,7 +937,7 @@
937937

938938
"@tanstack/query-core": ["@tanstack/[email protected]", "", {}, "sha512-OG69LQgT7jSp+5pPuCfzltq/+7l2xoweggjme9vlbCPa/d7D7zaqv5vN/S82SzSYZ4EDLTxNO1PWrv49RAS64Q=="],
939939

940-
"@tanstack/react-query": ["@tanstack/react-query@5.83.1", "", { "dependencies": { "@tanstack/query-core": "5.83.1" }, "peerDependencies": { "react": "^18 || ^19" } }, "sha512-JHZ3xox3p0sqCgM7ykBRtMWSLmWgjR7I+oJMAZ1beK/O/gfShI2b/PdovL2/ivVLUZklXgBenQu4ZjPhIM+yrw=="],
940+
"@tanstack/react-query": ["@tanstack/react-query@5.84.0", "", { "dependencies": { "@tanstack/query-core": "5.83.1" }, "peerDependencies": { "react": "^18 || ^19" } }, "sha512-iPycFGLq5lltDE16Jf13Nx7SOvtfoopfOH/+Ahbdd+z4QqOfYu/SOkY86AVYVcKjneuqPxTm8e85lSGhwe0cog=="],
941941

942942
"@tanstack/react-table": ["@tanstack/[email protected]", "", { "dependencies": { "@tanstack/table-core": "8.21.3" }, "peerDependencies": { "react": ">=16.8", "react-dom": ">=16.8" } }, "sha512-5nNMTSETP4ykGegmVkhjcS8tTLW6Vl4axfEGQN3v0zdHYbK4UfoqfPChclTrJ4EoK9QynqAu9oUf8VEmrpZ5Ww=="],
943943

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.0",
44
"devDependencies": {
55
"@changesets/cli": "^2.29.5",
6-
"@cloudflare/workers-types": "^4.20250731.0",
6+
"@cloudflare/workers-types": "^4.20250801.0",
77
"@nimbus/eslint": "workspace:*",
88
"@nimbus/tsconfig": "workspace:*",
99
"concurrently": "^9.2.0",

0 commit comments

Comments
 (0)