mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-30 11:35:22 +02:00
feat(user): add bookmarkedTemplates column to user table and update related API methods
- Introduced a new column `bookmarkedTemplates` to the user table to store user-specific template bookmarks. - Updated API methods to manage bookmarked templates, replacing the deprecated user_template_bookmarks table. - Adjusted queries to retrieve and toggle bookmarks directly from the user record.
This commit is contained in:
1
apps/dokploy/drizzle/0159_polite_puppet_master.sql
Normal file
1
apps/dokploy/drizzle/0159_polite_puppet_master.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE "user" ADD COLUMN "bookmarkedTemplates" text[] DEFAULT ARRAY[]::text[];
|
||||
8277
apps/dokploy/drizzle/meta/0159_snapshot.json
Normal file
8277
apps/dokploy/drizzle/meta/0159_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1114,6 +1114,13 @@
|
||||
"when": 1775270343231,
|
||||
"tag": "0158_amused_synch",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 159,
|
||||
"version": "7",
|
||||
"when": 1775274158009,
|
||||
"tag": "0159_polite_puppet_master",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
apiUpdateUser,
|
||||
invitation,
|
||||
member,
|
||||
userTemplateBookmarks,
|
||||
user,
|
||||
} from "@dokploy/server/db/schema";
|
||||
import {
|
||||
hasPermission,
|
||||
@@ -642,12 +642,12 @@ export const userRouter = createTRPCRouter({
|
||||
}),
|
||||
|
||||
getBookmarkedTemplates: protectedProcedure.query(async ({ ctx }) => {
|
||||
const bookmarked = await db.query.userTemplateBookmarks.findMany({
|
||||
where: eq(userTemplateBookmarks.userId, ctx.user.id),
|
||||
orderBy: [asc(userTemplateBookmarks.createdAt)],
|
||||
const result = await db.query.user.findFirst({
|
||||
where: eq(user.id, ctx.user.id),
|
||||
columns: { bookmarkedTemplates: true },
|
||||
});
|
||||
|
||||
return bookmarked.map((b) => b.templateId);
|
||||
return result?.bookmarkedTemplates ?? [];
|
||||
}),
|
||||
|
||||
toggleTemplateBookmark: protectedProcedure
|
||||
@@ -657,24 +657,23 @@ export const userRouter = createTRPCRouter({
|
||||
}),
|
||||
)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const existing = await db.query.userTemplateBookmarks.findFirst({
|
||||
where: and(
|
||||
eq(userTemplateBookmarks.userId, ctx.user.id),
|
||||
eq(userTemplateBookmarks.templateId, input.templateId),
|
||||
),
|
||||
const result = await db.query.user.findFirst({
|
||||
where: eq(user.id, ctx.user.id),
|
||||
columns: { bookmarkedTemplates: true },
|
||||
});
|
||||
|
||||
if (existing) {
|
||||
await db
|
||||
.delete(userTemplateBookmarks)
|
||||
.where(eq(userTemplateBookmarks.id, existing.id));
|
||||
return { isBookmarked: false };
|
||||
}
|
||||
const current = result?.bookmarkedTemplates ?? [];
|
||||
const isBookmarked = current.includes(input.templateId);
|
||||
|
||||
await db.insert(userTemplateBookmarks).values({
|
||||
userId: ctx.user.id,
|
||||
templateId: input.templateId,
|
||||
});
|
||||
return { isBookmarked: true };
|
||||
const updated = isBookmarked
|
||||
? current.filter((id) => id !== input.templateId)
|
||||
: [...current, input.templateId];
|
||||
|
||||
await db
|
||||
.update(user)
|
||||
.set({ bookmarkedTemplates: updated })
|
||||
.where(eq(user.id, ctx.user.id));
|
||||
|
||||
return { isBookmarked: !isBookmarked };
|
||||
}),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user