MCPcopy Create free account
hub / github.com/Y80/bmm / insert

Function insert

src/controllers/UserBookmark.controller.ts:84–103  ·  view source on GitHub ↗
(bookmark: InsertBookmark)

Source from the content-addressed store, hash-verified

82
83const UserBookmarkController = {
84 async insert(bookmark: InsertBookmark) {
85 const userId = await getAuthedUserId()
86 // 插入之前先检查当前用户是否有相同网址或名称的记录
87 const count = await db.$count(
88 userBookmarks,
89 and(
90 eq(userBookmarks.userId, userId),
91 or(eq(userBookmarks.url, bookmark.url), eq(userBookmarks.name, bookmark.name))
92 )
93 )
94 if (count > 0) throw new Error('已存在相同网址或名称的书签')
95 bookmark.pinyin ||= getPinyin(bookmark.name)
96 bookmark.hostKey = getBookmarkHostKey(bookmark.url)
97 const rows = await db
98 .insert(userBookmarks)
99 .values({ ...bookmark, userId })
100 .returning()
101 await fullSetBookmarkToTag(rows[0].id, bookmark.relatedTagIds)
102 return rows[0]
103 },
104 async query(bookmark: Pick<SelectUserBookmark, 'id'>) {
105 const res = await db.query.userBookmarks.findFirst({
106 where: userLimiter(await getAuthedUserId(), bookmark.id),

Callers

nothing calls this directly

Calls 4

getAuthedUserIdFunction · 0.90
getPinyinFunction · 0.90
getBookmarkHostKeyFunction · 0.90
fullSetBookmarkToTagFunction · 0.70

Tested by

no test coverage detected