-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcategories.ts
More file actions
43 lines (42 loc) · 1.16 KB
/
categories.ts
File metadata and controls
43 lines (42 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { builder } from '../helper'
export const categoriesCollection = builder.collection('categories', {
slug: 'categories',
identifierColumn: 'id',
fields: builder.fields('categories', (fb) => ({
id: fb.columns('id', {
type: 'text',
}),
name: fb.columns('name', {
type: 'text',
}),
posts: fb.relations('posts', (fb) => ({
type: 'connect',
fields: fb.fields('posts', (fb) => ({
id: fb.columns('id', {
type: 'text',
}),
title: fb.columns('title', {
type: 'text',
}),
content: fb.columns('content', {
type: 'text',
}),
})),
options: builder.options(async ({ db }) => {
const result = await db.query.user.findMany({ columns: { id: true, name: true } })
return result.map((user) => ({ label: user.name ?? user.id, value: user.id }))
}),
})),
tags: fb.relations('tags', (fb) => ({
type: 'create',
fields: fb.fields('categoryTags', (fb) => ({
id: fb.columns('id', {
type: 'text',
}),
name: fb.columns('name', {
type: 'text',
}),
})),
})),
})),
})