|
| 1 | +import geoip from 'geoip-country' |
| 2 | +import { customAlphabet } from 'nanoid' |
1 | 3 | import { EditPostInput, WritePostInput } from '@graphql/helpers/generated.js'
|
2 | 4 | import { DbService } from '@lib/db/DbService.js'
|
3 | 5 | import { UtilsService } from '@lib/utils/UtilsService.js'
|
4 | 6 | import { injectable, singleton } from 'tsyringe'
|
5 |
| -import { customAlphabet } from 'nanoid' |
6 | 7 | import { TagService } from '@services/TagService/index.js'
|
7 | 8 | import { PostTagService } from '@services/PostTagService/index.js'
|
8 | 9 | import { Time } from '@constants/TimeConstants.js'
|
9 | 10 | import { DiscordService } from '@lib/discord/DiscordService.js'
|
10 | 11 | import { UnauthorizedError } from '@errors/UnauthorizedError.js'
|
11 | 12 | import { NotFoundError } from '@errors/NotfoundError.js'
|
12 | 13 | import { BadRequestError } from '@errors/BadRequestErrors.js'
|
13 |
| -import geoip from 'geoip-country' |
14 | 14 | import { Post, Series, Tag } from '@packages/database/velog-rds'
|
15 | 15 | import { ForbiddenError } from '@errors/ForbiddenError.js'
|
16 | 16 | import { SeriesService } from '@services/SeriesService/index.mjs'
|
@@ -112,12 +112,17 @@ export class PostApiService implements Service {
|
112 | 112 | ])
|
113 | 113 | }
|
114 | 114 |
|
115 |
| - await this.db.post.update({ |
116 |
| - where: { |
117 |
| - id: post.id, |
118 |
| - }, |
119 |
| - data, |
120 |
| - }) |
| 115 | + try { |
| 116 | + await this.db.post.update({ |
| 117 | + where: { |
| 118 | + id: post.id, |
| 119 | + }, |
| 120 | + data, |
| 121 | + }) |
| 122 | + } catch (error) { |
| 123 | + console.error('Prisma update error:', error) |
| 124 | + throw new Error('Failed to update post') |
| 125 | + } |
121 | 126 |
|
122 | 127 | try {
|
123 | 128 | await Promise.all([
|
@@ -223,15 +228,20 @@ export class PostApiService implements Service {
|
223 | 228 |
|
224 | 229 | let post: Post | null = null
|
225 | 230 | if (type === 'write') {
|
226 |
| - post = await this.db.post.create({ |
227 |
| - data: { |
228 |
| - ...(data as Omit<WritePostInput, 'tags' | 'token' | 'series_id'>), |
229 |
| - fk_user_id: signedUserId, |
230 |
| - }, |
231 |
| - include: { |
232 |
| - user: true, |
233 |
| - }, |
234 |
| - }) |
| 231 | + try { |
| 232 | + post = await this.db.post.create({ |
| 233 | + data: { |
| 234 | + ...(data as Omit<WritePostInput, 'tags' | 'token' | 'series_id'>), |
| 235 | + fk_user_id: signedUserId, |
| 236 | + }, |
| 237 | + include: { |
| 238 | + user: true, |
| 239 | + }, |
| 240 | + }) |
| 241 | + } catch (error) { |
| 242 | + console.log('Prisma create post error:', error) |
| 243 | + throw new Error('Failed to create post') |
| 244 | + } |
235 | 245 | }
|
236 | 246 |
|
237 | 247 | if (type === 'edit') {
|
@@ -323,7 +333,7 @@ export class PostApiService implements Service {
|
323 | 333 | // await this.imageService.trackImages(images, data.body)
|
324 | 334 | // }, 0)
|
325 | 335 |
|
326 |
| - return { data, isPublish, post, userId: signedUserId, series_id } |
| 336 | + return { data: { ...data }, isPublish, post, userId: signedUserId, series_id } |
327 | 337 | }
|
328 | 338 | private async generateUrlSlug({ input, urlSlug, userId }: GenerateUrlSlugArgs) {
|
329 | 339 | let processedUrlSlug = this.utils.escapeForUrl(urlSlug)
|
|
0 commit comments