@allbluecn/admin-app 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/components/admin/developer-log.tsx +2 -2
- package/src/components/knowledge/public/kp-crud-page.tsx +208 -0
- package/src/components/market/market-app-form.tsx +1 -1
- package/src/components/user/settings-profile.tsx +1 -1
- package/src/components/user/user-create-dialog.tsx +1 -1
- package/src/components/user/user-detail/user-detail-dialogs.tsx +3 -3
- package/src/paraglide/messages/_index.js +0 -2
- package/src/routes/_nav/knowledge-public/bookmarks/route.lazy.tsx +36 -111
- package/src/routes/_nav/knowledge-public/compliance/route.lazy.tsx +29 -105
- package/src/routes/_nav/knowledge-public/legal/route.lazy.tsx +30 -108
- package/src/routes/_nav/monitoring/errors/route.lazy.tsx +1 -1
- package/src/routes/_nav/monitoring/logs/route.lazy.tsx +1 -1
- package/src/routes/_nav/monitoring/metrics/route.lazy.tsx +1 -1
- package/src/routes/_nav/permissions/route.lazy.tsx +1 -1
- package/src/routes/_nav/sso/route.lazy.tsx +1 -1
- package/src/server/knowledge/public/kp-factory.ts +134 -0
- package/src/server/serverFns/knowledge/public/bookmarks/create.ts +23 -25
- package/src/server/serverFns/knowledge/public/bookmarks/delete.ts +2 -14
- package/src/server/serverFns/knowledge/public/bookmarks/detail.ts +2 -11
- package/src/server/serverFns/knowledge/public/bookmarks/list.ts +32 -38
- package/src/server/serverFns/knowledge/public/bookmarks/update.ts +23 -22
- package/src/server/serverFns/knowledge/public/compliance/create.ts +10 -15
- package/src/server/serverFns/knowledge/public/compliance/delete.ts +2 -14
- package/src/server/serverFns/knowledge/public/compliance/detail.ts +2 -11
- package/src/server/serverFns/knowledge/public/compliance/list.ts +24 -31
- package/src/server/serverFns/knowledge/public/compliance/update.ts +22 -22
- package/src/server/serverFns/knowledge/public/legal/create.ts +11 -15
- package/src/server/serverFns/knowledge/public/legal/delete.ts +2 -14
- package/src/server/serverFns/knowledge/public/legal/detail.ts +2 -11
- package/src/server/serverFns/knowledge/public/legal/list.ts +24 -32
- package/src/server/serverFns/knowledge/public/legal/update.ts +20 -22
- package/src/paraglide/messages/common_button_cancel.js +0 -29
- package/src/paraglide/messages/common_dependency_table_pagination_total.js +0 -29
|
@@ -15,11 +15,10 @@
|
|
|
15
15
|
// You should have received a copy of the GNU Affero General Public License
|
|
16
16
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
|
|
18
|
+
|
|
18
19
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
20
|
import { z } from 'zod'
|
|
20
|
-
import {
|
|
21
|
-
import { Prisma } from '@allbluecn/database'
|
|
22
|
-
import { requireAdmin } from '@/server/auth-helpers'
|
|
21
|
+
import { kpListHandler } from '@/server/knowledge/public/kp-factory'
|
|
23
22
|
|
|
24
23
|
const listSchema = z.object({
|
|
25
24
|
search: z.string().optional(),
|
|
@@ -31,38 +30,33 @@ const listSchema = z.object({
|
|
|
31
30
|
|
|
32
31
|
export const adminListBookmarksFn = createServerFn({ method: 'GET' })
|
|
33
32
|
.validator(listSchema)
|
|
34
|
-
.handler(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
...rest,
|
|
65
|
-
categoryIcon: _c?.icon ?? 'Folder',
|
|
66
|
-
}))
|
|
67
|
-
return { items: mapped, total, page: data.page, pageSize: data.pageSize }
|
|
68
|
-
})
|
|
33
|
+
.handler(
|
|
34
|
+
kpListHandler<z.infer<typeof listSchema>>({
|
|
35
|
+
getDelegate: (prisma) => prisma.websiteBookmark,
|
|
36
|
+
buildWhere: (data) => {
|
|
37
|
+
const where: Record<string, unknown> = {}
|
|
38
|
+
if (data.search) {
|
|
39
|
+
where.OR = [
|
|
40
|
+
{ title: { contains: data.search, mode: 'insensitive' } },
|
|
41
|
+
{ summary: { contains: data.search, mode: 'insensitive' } },
|
|
42
|
+
{ url: { contains: data.search, mode: 'insensitive' } },
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
if (data.categoryId) where.categoryId = data.categoryId
|
|
46
|
+
if (data.isGithub !== undefined) where.isGithub = data.isGithub
|
|
47
|
+
return where
|
|
48
|
+
},
|
|
49
|
+
select: {
|
|
50
|
+
id: true, canonicalId: true, title: true, url: true, categoryId: true,
|
|
51
|
+
summary: true, faviconUrl: true, isGithub: true, githubStars: true,
|
|
52
|
+
githubLatestVersion: true, githubVersionDate: true, githubRepoUpdatedAt: true,
|
|
53
|
+
githubSyncedAt: true, tags: true, visibility: true, userId: true, createdAt: true,
|
|
54
|
+
category: { select: { icon: true } },
|
|
55
|
+
},
|
|
56
|
+
postProcess: (items) =>
|
|
57
|
+
items.map(({ category: _c, ...rest }) => ({
|
|
58
|
+
...rest,
|
|
59
|
+
categoryIcon: _c?.icon ?? 'Folder',
|
|
60
|
+
})),
|
|
61
|
+
}),
|
|
62
|
+
)
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
// You should have received a copy of the GNU Affero General Public License
|
|
16
16
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
|
|
18
|
+
|
|
18
19
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
20
|
import { z } from 'zod'
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import { bookmarkCanonicalId, parseGithubUrl } from '@/server/knowledge/public/canonical-id'
|
|
21
|
+
import { bookmarkCanonicalId } from '@/server/knowledge/public/canonical-id'
|
|
22
|
+
import { parseGithubUrl } from '@/server/knowledge/public/canonical-id'
|
|
23
|
+
import { kpUpdateHandler } from '@/server/knowledge/public/kp-factory'
|
|
24
24
|
|
|
25
25
|
const updateSchema = z.object({
|
|
26
26
|
id: z.string(),
|
|
@@ -39,21 +39,22 @@ const updateSchema = z.object({
|
|
|
39
39
|
|
|
40
40
|
export const adminUpdateBookmarkFn = createServerFn({ method: 'POST' })
|
|
41
41
|
.validator(updateSchema)
|
|
42
|
-
.handler(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
42
|
+
.handler(
|
|
43
|
+
kpUpdateHandler<z.infer<typeof updateSchema>>({
|
|
44
|
+
getDelegate: (prisma) => prisma.websiteBookmark,
|
|
45
|
+
buildUpdateData: (data, existing) => {
|
|
46
|
+
const { id: _id, ...rest } = data
|
|
47
|
+
const updateData: Record<string, unknown> = { ...rest }
|
|
48
|
+
// .url() 已排除空串,无需真值判断;局部变量保住 string 收窄
|
|
49
|
+
const nextUrl = data.url
|
|
50
|
+
if (nextUrl !== undefined && nextUrl !== existing.url) {
|
|
51
|
+
const gh = parseGithubUrl(nextUrl)
|
|
52
|
+
updateData.canonicalId = bookmarkCanonicalId(nextUrl)
|
|
53
|
+
updateData.isGithub = !!gh
|
|
54
|
+
updateData.githubOwner = gh?.owner ?? null
|
|
55
|
+
updateData.githubRepo = gh?.repo ?? null
|
|
56
|
+
}
|
|
57
|
+
return updateData
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
)
|
|
@@ -17,9 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
19
|
import { z } from 'zod'
|
|
20
|
-
import { getPrisma } from '@allbluecn/database/get-prisma'
|
|
21
|
-
import { requireAdmin, UnauthorizedError } from '@/server/auth-helpers'
|
|
22
20
|
import { complianceCanonicalId } from '@/server/knowledge/public/canonical-id'
|
|
21
|
+
import { kpCreateHandler } from '@/server/knowledge/public/kp-factory'
|
|
23
22
|
|
|
24
23
|
const createSchema = z.object({
|
|
25
24
|
title: z.string().min(1).max(200),
|
|
@@ -36,26 +35,22 @@ const createSchema = z.object({
|
|
|
36
35
|
|
|
37
36
|
export const adminCreateComplianceFn = createServerFn({ method: 'POST' })
|
|
38
37
|
.validator(createSchema)
|
|
39
|
-
.handler(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (!userId) throw new UnauthorizedError()
|
|
44
|
-
return prisma.industryCompliance.create({
|
|
45
|
-
data: {
|
|
38
|
+
.handler(
|
|
39
|
+
kpCreateHandler<z.infer<typeof createSchema>>({
|
|
40
|
+
getDelegate: (prisma) => prisma.industryCompliance,
|
|
41
|
+
buildData: (data, userId) => ({
|
|
46
42
|
canonicalId: complianceCanonicalId({ title: data.title, code: data.code }),
|
|
47
43
|
title: data.title,
|
|
48
44
|
industry: data.industry,
|
|
49
45
|
regulatoryBody: data.regulatoryBody || null,
|
|
50
46
|
region: data.region || null,
|
|
51
|
-
summary: data.summary
|
|
52
|
-
content: data.content
|
|
47
|
+
summary: data.summary ?? null,
|
|
48
|
+
content: data.content ?? null,
|
|
53
49
|
requirements: data.requirements,
|
|
54
50
|
sourceUrl: data.sourceUrl || null,
|
|
55
51
|
tags: data.tags,
|
|
56
52
|
visibility: 'public',
|
|
57
53
|
userId,
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
})
|
|
54
|
+
}),
|
|
55
|
+
}),
|
|
56
|
+
)
|
|
@@ -17,20 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
19
|
import { z } from 'zod'
|
|
20
|
-
import {
|
|
21
|
-
import { requireAdmin } from '@/server/auth-helpers'
|
|
20
|
+
import { kpDeleteHandler } from '@/server/knowledge/public/kp-factory'
|
|
22
21
|
|
|
23
22
|
export const adminDeleteComplianceFn = createServerFn({ method: 'POST' })
|
|
24
23
|
.validator(z.object({ id: z.string() }))
|
|
25
|
-
.handler(
|
|
26
|
-
const prisma = await getPrisma()
|
|
27
|
-
await requireAdmin()
|
|
28
|
-
// 直接软删,不存在由 P2025 转错误(省一次 findUnique 往返)
|
|
29
|
-
try {
|
|
30
|
-
await prisma.industryCompliance.update({ where: { id: data.id }, data: { isDeleted: true } })
|
|
31
|
-
} catch (e) {
|
|
32
|
-
if ((e as { code?: string }).code === 'P2025') throw new Error('未找到')
|
|
33
|
-
throw e
|
|
34
|
-
}
|
|
35
|
-
return { success: true }
|
|
36
|
-
})
|
|
24
|
+
.handler(kpDeleteHandler((prisma) => prisma.industryCompliance))
|
|
@@ -17,17 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
19
|
import { z } from 'zod'
|
|
20
|
-
import {
|
|
21
|
-
import { requireAdmin } from '@/server/auth-helpers'
|
|
20
|
+
import { kpDetailHandler } from '@/server/knowledge/public/kp-factory'
|
|
22
21
|
|
|
23
22
|
export const adminGetComplianceDetailFn = createServerFn({ method: 'GET' })
|
|
24
23
|
.validator(z.object({ id: z.string() }))
|
|
25
|
-
.handler(
|
|
26
|
-
const prisma = await getPrisma()
|
|
27
|
-
await requireAdmin()
|
|
28
|
-
const item = await prisma.industryCompliance.findFirst({
|
|
29
|
-
where: { id: data.id, visibility: 'public', isDeleted: false },
|
|
30
|
-
})
|
|
31
|
-
if (!item) throw new Error('未找到')
|
|
32
|
-
return item
|
|
33
|
-
})
|
|
24
|
+
.handler(kpDetailHandler((prisma) => prisma.industryCompliance))
|
|
@@ -15,11 +15,10 @@
|
|
|
15
15
|
// You should have received a copy of the GNU Affero General Public License
|
|
16
16
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
|
|
18
|
+
|
|
18
19
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
20
|
import { z } from 'zod'
|
|
20
|
-
import {
|
|
21
|
-
import { Prisma } from '@allbluecn/database'
|
|
22
|
-
import { requireAdmin } from '@/server/auth-helpers'
|
|
21
|
+
import { kpListHandler } from '@/server/knowledge/public/kp-factory'
|
|
23
22
|
|
|
24
23
|
const listSchema = z.object({
|
|
25
24
|
search: z.string().optional(),
|
|
@@ -31,31 +30,25 @@ const listSchema = z.object({
|
|
|
31
30
|
|
|
32
31
|
export const adminListComplianceFn = createServerFn({ method: 'GET' })
|
|
33
32
|
.validator(listSchema)
|
|
34
|
-
.handler(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
take: data.pageSize,
|
|
57
|
-
}),
|
|
58
|
-
prisma.industryCompliance.count({ where }),
|
|
59
|
-
])
|
|
60
|
-
return { items, total, page: data.page, pageSize: data.pageSize }
|
|
61
|
-
})
|
|
33
|
+
.handler(
|
|
34
|
+
kpListHandler<z.infer<typeof listSchema>>({
|
|
35
|
+
getDelegate: (prisma) => prisma.industryCompliance,
|
|
36
|
+
buildWhere: (data) => {
|
|
37
|
+
const where: Record<string, unknown> = {}
|
|
38
|
+
if (data.search) {
|
|
39
|
+
where.OR = [
|
|
40
|
+
{ title: { contains: data.search, mode: 'insensitive' } },
|
|
41
|
+
{ summary: { contains: data.search, mode: 'insensitive' } },
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
if (data.industry) where.industry = data.industry
|
|
45
|
+
if (data.region) where.region = data.region
|
|
46
|
+
return where
|
|
47
|
+
},
|
|
48
|
+
select: {
|
|
49
|
+
id: true, canonicalId: true, title: true, industry: true,
|
|
50
|
+
regulatoryBody: true, region: true, summary: true, requirements: true,
|
|
51
|
+
sourceUrl: true, tags: true, visibility: true, userId: true, createdAt: true,
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
)
|
|
@@ -15,12 +15,11 @@
|
|
|
15
15
|
// You should have received a copy of the GNU Affero General Public License
|
|
16
16
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
|
|
18
|
+
|
|
18
19
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
20
|
import { z } from 'zod'
|
|
20
|
-
import { getPrisma } from '@allbluecn/database/get-prisma'
|
|
21
|
-
import { Prisma } from '@allbluecn/database'
|
|
22
|
-
import { requireAdmin } from '@/server/auth-helpers'
|
|
23
21
|
import { complianceCanonicalId } from '@/server/knowledge/public/canonical-id'
|
|
22
|
+
import { kpUpdateHandler } from '@/server/knowledge/public/kp-factory'
|
|
24
23
|
|
|
25
24
|
const updateSchema = z.object({
|
|
26
25
|
id: z.string(),
|
|
@@ -38,22 +37,23 @@ const updateSchema = z.object({
|
|
|
38
37
|
|
|
39
38
|
export const adminUpdateComplianceFn = createServerFn({ method: 'POST' })
|
|
40
39
|
.validator(updateSchema)
|
|
41
|
-
.handler(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
40
|
+
.handler(
|
|
41
|
+
kpUpdateHandler<z.infer<typeof updateSchema>>({
|
|
42
|
+
getDelegate: (prisma) => prisma.industryCompliance,
|
|
43
|
+
buildUpdateData: (data, existing) => {
|
|
44
|
+
const { id: _id, code, ...rest } = data
|
|
45
|
+
const updateData: Record<string, unknown> = { ...rest }
|
|
46
|
+
if (code !== undefined || data.title !== undefined) {
|
|
47
|
+
// code 不落库(canonicalId = code || title):canonicalId !== title.trim() ⟺ 创建时
|
|
48
|
+
// 提供了 code(canonicalId 即原 code)。只改 title 时必须回落旧 code 重算,
|
|
49
|
+
// 否则 canonicalId 与 title/code 组合脱钩,破坏上游按 canonicalId 去重/同步的语义
|
|
50
|
+
const existingCode = existing.canonicalId === existing.title.trim() ? undefined : existing.canonicalId
|
|
51
|
+
updateData.canonicalId = complianceCanonicalId({
|
|
52
|
+
title: data.title ?? existing.title,
|
|
53
|
+
code: code ?? existingCode,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
return updateData
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
)
|
|
@@ -17,9 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
19
|
import { z } from 'zod'
|
|
20
|
-
import { getPrisma } from '@allbluecn/database/get-prisma'
|
|
21
|
-
import { requireAdmin, UnauthorizedError } from '@/server/auth-helpers'
|
|
22
20
|
import { legalCanonicalId } from '@/server/knowledge/public/canonical-id'
|
|
21
|
+
import { kpCreateHandler } from '@/server/knowledge/public/kp-factory'
|
|
23
22
|
|
|
24
23
|
const createSchema = z.object({
|
|
25
24
|
title: z.string().min(1).max(200),
|
|
@@ -38,28 +37,25 @@ const createSchema = z.object({
|
|
|
38
37
|
|
|
39
38
|
export const adminCreateLegalFn = createServerFn({ method: 'POST' })
|
|
40
39
|
.validator(createSchema)
|
|
41
|
-
.handler(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (!userId) throw new UnauthorizedError()
|
|
46
|
-
return prisma.legalRegulation.create({
|
|
47
|
-
data: {
|
|
40
|
+
.handler(
|
|
41
|
+
kpCreateHandler<z.infer<typeof createSchema>>({
|
|
42
|
+
getDelegate: (prisma) => prisma.legalRegulation,
|
|
43
|
+
buildData: (data, userId) => ({
|
|
48
44
|
canonicalId: legalCanonicalId({ title: data.title, code: data.code }),
|
|
49
45
|
title: data.title,
|
|
46
|
+
code: data.code ?? null,
|
|
50
47
|
jurisdiction: data.jurisdiction,
|
|
51
48
|
region: data.region || null,
|
|
52
49
|
country: data.country || null,
|
|
53
50
|
category: data.category,
|
|
54
51
|
issuingAuthority: data.issuingAuthority || null,
|
|
55
52
|
effectiveDate: data.effectiveDate ?? null,
|
|
56
|
-
summary: data.summary
|
|
57
|
-
content: data.content
|
|
53
|
+
summary: data.summary ?? null,
|
|
54
|
+
content: data.content ?? null,
|
|
58
55
|
sourceUrl: data.sourceUrl || null,
|
|
59
56
|
tags: data.tags,
|
|
60
57
|
visibility: 'public',
|
|
61
58
|
userId,
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
})
|
|
59
|
+
}),
|
|
60
|
+
}),
|
|
61
|
+
)
|
|
@@ -17,20 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
19
|
import { z } from 'zod'
|
|
20
|
-
import {
|
|
21
|
-
import { requireAdmin } from '@/server/auth-helpers'
|
|
20
|
+
import { kpDeleteHandler } from '@/server/knowledge/public/kp-factory'
|
|
22
21
|
|
|
23
22
|
export const adminDeleteLegalFn = createServerFn({ method: 'POST' })
|
|
24
23
|
.validator(z.object({ id: z.string() }))
|
|
25
|
-
.handler(
|
|
26
|
-
const prisma = await getPrisma()
|
|
27
|
-
await requireAdmin()
|
|
28
|
-
// 直接软删,不存在由 P2025 转错误(省一次 findUnique 往返)
|
|
29
|
-
try {
|
|
30
|
-
await prisma.legalRegulation.update({ where: { id: data.id }, data: { isDeleted: true } })
|
|
31
|
-
} catch (e) {
|
|
32
|
-
if ((e as { code?: string }).code === 'P2025') throw new Error('未找到')
|
|
33
|
-
throw e
|
|
34
|
-
}
|
|
35
|
-
return { success: true }
|
|
36
|
-
})
|
|
24
|
+
.handler(kpDeleteHandler((prisma) => prisma.legalRegulation))
|
|
@@ -17,17 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
19
|
import { z } from 'zod'
|
|
20
|
-
import {
|
|
21
|
-
import { requireAdmin } from '@/server/auth-helpers'
|
|
20
|
+
import { kpDetailHandler } from '@/server/knowledge/public/kp-factory'
|
|
22
21
|
|
|
23
22
|
export const adminGetLegalDetailFn = createServerFn({ method: 'GET' })
|
|
24
23
|
.validator(z.object({ id: z.string() }))
|
|
25
|
-
.handler(
|
|
26
|
-
const prisma = await getPrisma()
|
|
27
|
-
await requireAdmin()
|
|
28
|
-
const item = await prisma.legalRegulation.findFirst({
|
|
29
|
-
where: { id: data.id, visibility: 'public', isDeleted: false },
|
|
30
|
-
})
|
|
31
|
-
if (!item) throw new Error('未找到')
|
|
32
|
-
return item
|
|
33
|
-
})
|
|
24
|
+
.handler(kpDetailHandler((prisma) => prisma.legalRegulation))
|
|
@@ -15,11 +15,10 @@
|
|
|
15
15
|
// You should have received a copy of the GNU Affero General Public License
|
|
16
16
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
|
|
18
|
+
|
|
18
19
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
20
|
import { z } from 'zod'
|
|
20
|
-
import {
|
|
21
|
-
import { Prisma } from '@allbluecn/database'
|
|
22
|
-
import { requireAdmin } from '@/server/auth-helpers'
|
|
21
|
+
import { kpListHandler } from '@/server/knowledge/public/kp-factory'
|
|
23
22
|
|
|
24
23
|
const listSchema = z.object({
|
|
25
24
|
search: z.string().optional(),
|
|
@@ -31,32 +30,25 @@ const listSchema = z.object({
|
|
|
31
30
|
|
|
32
31
|
export const adminListLegalFn = createServerFn({ method: 'GET' })
|
|
33
32
|
.validator(listSchema)
|
|
34
|
-
.handler(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
skip: (data.page - 1) * data.pageSize,
|
|
57
|
-
take: data.pageSize,
|
|
58
|
-
}),
|
|
59
|
-
prisma.legalRegulation.count({ where }),
|
|
60
|
-
])
|
|
61
|
-
return { items, total, page: data.page, pageSize: data.pageSize }
|
|
62
|
-
})
|
|
33
|
+
.handler(
|
|
34
|
+
kpListHandler<z.infer<typeof listSchema>>({
|
|
35
|
+
getDelegate: (prisma) => prisma.legalRegulation,
|
|
36
|
+
buildWhere: (data) => {
|
|
37
|
+
const where: Record<string, unknown> = {}
|
|
38
|
+
if (data.search) {
|
|
39
|
+
where.OR = [
|
|
40
|
+
{ title: { contains: data.search, mode: 'insensitive' } },
|
|
41
|
+
{ summary: { contains: data.search, mode: 'insensitive' } },
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
if (data.jurisdiction) where.jurisdiction = data.jurisdiction
|
|
45
|
+
if (data.category) where.category = data.category
|
|
46
|
+
return where
|
|
47
|
+
},
|
|
48
|
+
select: {
|
|
49
|
+
id: true, canonicalId: true, title: true, jurisdiction: true,
|
|
50
|
+
category: true, country: true, issuingAuthority: true, effectiveDate: true,
|
|
51
|
+
summary: true, sourceUrl: true, tags: true, visibility: true, userId: true, createdAt: true,
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
)
|
|
@@ -15,12 +15,11 @@
|
|
|
15
15
|
// You should have received a copy of the GNU Affero General Public License
|
|
16
16
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
|
|
18
|
+
|
|
18
19
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
20
|
import { z } from 'zod'
|
|
20
|
-
import { getPrisma } from '@allbluecn/database/get-prisma'
|
|
21
|
-
import { Prisma } from '@allbluecn/database'
|
|
22
|
-
import { requireAdmin } from '@/server/auth-helpers'
|
|
23
21
|
import { legalCanonicalId } from '@/server/knowledge/public/canonical-id'
|
|
22
|
+
import { kpUpdateHandler } from '@/server/knowledge/public/kp-factory'
|
|
24
23
|
|
|
25
24
|
const updateSchema = z.object({
|
|
26
25
|
id: z.string(),
|
|
@@ -40,22 +39,21 @@ const updateSchema = z.object({
|
|
|
40
39
|
|
|
41
40
|
export const adminUpdateLegalFn = createServerFn({ method: 'POST' })
|
|
42
41
|
.validator(updateSchema)
|
|
43
|
-
.handler(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
})
|
|
42
|
+
.handler(
|
|
43
|
+
kpUpdateHandler<z.infer<typeof updateSchema>>({
|
|
44
|
+
getDelegate: (prisma) => prisma.legalRegulation,
|
|
45
|
+
buildUpdateData: (data, existing) => {
|
|
46
|
+
const { id: _id, code, ...rest } = data
|
|
47
|
+
const updateData: Record<string, unknown> = { ...rest }
|
|
48
|
+
if (code !== undefined || data.title !== undefined) {
|
|
49
|
+
// 同 compliance:只改 title 时回落旧 code 重算(code 不落库)
|
|
50
|
+
const existingCode = existing.canonicalId === existing.title.trim() ? undefined : existing.canonicalId
|
|
51
|
+
updateData.canonicalId = legalCanonicalId({
|
|
52
|
+
title: data.title ?? existing.title,
|
|
53
|
+
code: code ?? existingCode,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
return updateData
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
)
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
|
3
|
-
|
|
4
|
-
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
|
5
|
-
|
|
6
|
-
/** @typedef {{}} Common_Button_CancelInputs */
|
|
7
|
-
|
|
8
|
-
const zh_common_button_cancel = /** @type {(inputs: Common_Button_CancelInputs) => LocalizedString} */ () => {
|
|
9
|
-
return /** @type {LocalizedString} */ (`取消`)
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const en_common_button_cancel = /** @type {(inputs: Common_Button_CancelInputs) => LocalizedString} */ () => {
|
|
13
|
-
return /** @type {LocalizedString} */ (`Cancel`)
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* | output |
|
|
18
|
-
* | --- |
|
|
19
|
-
* | "Cancel" |
|
|
20
|
-
*
|
|
21
|
-
* @param {Common_Button_CancelInputs} inputs
|
|
22
|
-
* @param {{ locale?: "zh" | "en" }} options
|
|
23
|
-
* @returns {LocalizedString}
|
|
24
|
-
*/
|
|
25
|
-
export const common_button_cancel = /** @type {((inputs?: Common_Button_CancelInputs, options?: { locale?: "zh" | "en" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Common_Button_CancelInputs, { locale?: "zh" | "en" }, {}>} */ ((inputs = {}, options = {}) => {
|
|
26
|
-
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
|
27
|
-
if (locale === "en") return en_common_button_cancel(inputs)
|
|
28
|
-
return zh_common_button_cancel(inputs)
|
|
29
|
-
});
|