Skip to content

Commit 01e5c42

Browse files
committed
saves in the DB
1 parent 407c757 commit 01e5c42

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/components/generic/markdown-editor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const MarkdownEditor: FC<{
99
isInvalid?: boolean
1010
errorMessage?: string
1111
value?: string | null | undefined
12-
onChange?: (e: { target: { value: string } }) => void
12+
onChange?: (e: { target: { value: string | null } }) => void
1313
onBlur?: () => void
1414
label?: string
1515
className?: string
@@ -49,7 +49,7 @@ export const MarkdownEditor: FC<{
4949
onChange={(value) => {
5050
onChange?.({
5151
target: {
52-
value: value ?? '',
52+
value: value || null,
5353
},
5454
})
5555
}}

src/server/api/router/admin/places.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
listPlacesSchema,
1111
} from '~/schemas/places'
1212
import { db } from '~/server/db/db'
13-
import { places, placesToPlaceCategories } from '~/server/db/schema'
13+
import { features, places, placesToPlaceCategories } from '~/server/db/schema'
1414
import { selectPoint } from '~/server/helpers/spatial-data'
1515
import {
1616
flattenTranslationsOnExecute,
@@ -140,6 +140,12 @@ export const placesAdminRouter = router({
140140
.input(createPlaceSchema)
141141
.mutation(async ({ input }) => {
142142
await db.transaction(async (tx) => {
143+
const insertFeaturesResult = await tx
144+
.insert(features)
145+
.values({ ...input.features })
146+
147+
const featuresId = Number(insertFeaturesResult.insertId)
148+
143149
const insertPlaceResult = await tx.insert(places).values({
144150
name: input.name,
145151
description: input.description,
@@ -148,6 +154,7 @@ export const placesAdminRouter = router({
148154
location: pointToString(input.location),
149155
content: input.content,
150156
verificationRequirementsId: 1,
157+
featuresId,
151158
})
152159
const newPlaceId = Number(insertPlaceResult.insertId)
153160

@@ -169,6 +176,28 @@ export const placesAdminRouter = router({
169176
await db.transaction(async (tx) => {
170177
const placeId = Number(input.id)
171178

179+
let featuresId = (
180+
await tx
181+
.selectDistinct({ featuresId: places.featuresId })
182+
.from(places)
183+
.where(eq(places.id, placeId))
184+
)[0].featuresId
185+
186+
if (featuresId === null) {
187+
const insertFeaturesResult = await tx
188+
.insert(features)
189+
.values({ ...input.features })
190+
featuresId = Number(insertFeaturesResult.insertId)
191+
} else {
192+
await tx
193+
.update(features)
194+
.set({
195+
...input.features,
196+
id: featuresId,
197+
})
198+
.where(eq(features.id, featuresId))
199+
}
200+
172201
await tx
173202
.update(places)
174203
.set({
@@ -178,6 +207,7 @@ export const placesAdminRouter = router({
178207
mainImageId: input.mainImageId,
179208
location: pointToString(input.location),
180209
content: input.content,
210+
featuresId: featuresId,
181211
})
182212
.where(eq(places.id, placeId))
183213

0 commit comments

Comments
 (0)