mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-21 11:28:47 +00:00
feat(api): add routes for template bookmarks
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
|||||||
apiUpdateUser,
|
apiUpdateUser,
|
||||||
invitation,
|
invitation,
|
||||||
member,
|
member,
|
||||||
|
userTemplateBookmarks,
|
||||||
} from "@dokploy/server/db/schema";
|
} from "@dokploy/server/db/schema";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import * as bcrypt from "bcrypt";
|
import * as bcrypt from "bcrypt";
|
||||||
@@ -447,4 +448,41 @@ export const userRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
return inviteLink;
|
return inviteLink;
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
getBookmarkedTemplates: protectedProcedure.query(async ({ ctx }) => {
|
||||||
|
const bookmarked = await db.query.userTemplateBookmarks.findMany({
|
||||||
|
where: eq(userTemplateBookmarks.userId, ctx.user.id),
|
||||||
|
orderBy: [asc(userTemplateBookmarks.createdAt)],
|
||||||
|
});
|
||||||
|
|
||||||
|
return bookmarked.map((b) => b.templateId);
|
||||||
|
}),
|
||||||
|
|
||||||
|
toggleTemplateBookmark: protectedProcedure
|
||||||
|
.input(
|
||||||
|
z.object({
|
||||||
|
templateId: z.string().min(1),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.mutation(async ({ input, ctx }) => {
|
||||||
|
const existing = await db.query.userTemplateBookmarks.findFirst({
|
||||||
|
where: and(
|
||||||
|
eq(userTemplateBookmarks.userId, ctx.user.id),
|
||||||
|
eq(userTemplateBookmarks.templateId, input.templateId),
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (existing) {
|
||||||
|
await db
|
||||||
|
.delete(userTemplateBookmarks)
|
||||||
|
.where(eq(userTemplateBookmarks.id, existing.id));
|
||||||
|
return { isBookmarked: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
await db.insert(userTemplateBookmarks).values({
|
||||||
|
userId: ctx.user.id,
|
||||||
|
templateId: input.templateId,
|
||||||
|
});
|
||||||
|
return { isBookmarked: true };
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user