refactor(errors): migrate decisions to {code,msg}
This commit is contained in:
+3
-3
@@ -1,5 +1,5 @@
|
||||
import { addNotification } from "@/lib/api/notifications"
|
||||
import { allow, deny } from "@/lib/policy/assert"
|
||||
import { allow, deny } from "@/lib/decision"
|
||||
import { useAuthStore } from "@/store/auth"
|
||||
import { usePostStore } from "@/store/posts"
|
||||
|
||||
@@ -18,12 +18,12 @@ export function listPostsByAuthor(userId: string) {
|
||||
export function togglePostLike(postId: string) {
|
||||
const user = useAuthStore.getState().user
|
||||
if (!user) {
|
||||
return deny("AUTH_REQUIRED", "请先登录")
|
||||
return deny(401, "请先登录")
|
||||
}
|
||||
|
||||
const post = usePostStore.getState().posts.find((item) => item.id === postId)
|
||||
if (!post) {
|
||||
return deny("NOT_FOUND", "帖子不存在")
|
||||
return deny(404, "帖子不存在")
|
||||
}
|
||||
|
||||
const shouldNotify = !post.liked
|
||||
|
||||
Reference in New Issue
Block a user