Skip to content

Commit d69604a

Browse files
committed
feature: preparing tests for changes in post api
1 parent 326b344 commit d69604a

File tree

1 file changed

+75
-73
lines changed
  • packages/velog-server/src/services/PostApiService

1 file changed

+75
-73
lines changed

packages/velog-server/src/services/PostApiService/index.ts

Lines changed: 75 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ export class PostApiService implements Service {
5858
ip,
5959
})
6060

61-
if (series_id && !data.is_temp) {
62-
await this.seriesService.appendToSeries(series_id, post.id)
63-
}
61+
// if (series_id && !data.is_temp) {
62+
// await this.seriesService.appendToSeries(series_id, post.id)
63+
// }
6464

65-
if (!data.is_temp) {
66-
await this.searchService.searchSync.update(post.id)
67-
}
65+
// if (!data.is_temp) {
66+
// await this.searchService.searchSync.update(post.id)
67+
// }
6868

69-
return post
69+
return post as Post
7070
}
7171
public async edit(input: EditPostInput, signedUserId?: string, ip: string = ''): Promise<Post> {
7272
const { data, post, userId, series_id } = await this.initializePostProcess<'edit'>({
@@ -76,63 +76,63 @@ export class PostApiService implements Service {
7676
ip,
7777
})
7878

79-
const prevSeriesPost = await this.db.seriesPost.findFirst({
80-
where: {
81-
fk_post_id: post.id,
82-
},
83-
})
84-
85-
if (!prevSeriesPost && series_id) {
86-
await this.seriesService.appendToSeries(series_id, post.id)
87-
}
88-
89-
// 다른 시리즈에 추가하는 경우
90-
if (prevSeriesPost && prevSeriesPost.fk_series_id !== series_id) {
91-
if (series_id) {
92-
await this.checkSeriesOwnership(series_id, userId)
93-
await this.seriesService.appendToSeries(series_id, post.id)
94-
}
95-
96-
// remove series
97-
await Promise.all([
98-
this.seriesService.subtractIndexAfter(prevSeriesPost.fk_series_id!, prevSeriesPost.index!),
99-
this.db.seriesPost.delete({
100-
where: {
101-
id: prevSeriesPost.id,
102-
},
103-
}),
104-
])
105-
}
106-
107-
await this.db.post.update({
108-
where: {
109-
id: post.id,
110-
},
111-
data,
112-
})
113-
114-
try {
115-
await Promise.all([
116-
data.is_temp ? null : this.searchService.searchSync.update(post.id),
117-
this.graphcdn.purgePost(post.id),
118-
])
119-
} catch (error) {
120-
console.error(error)
121-
}
122-
123-
if (!post.is_private && data.is_private) {
124-
setImmediate(async () => {
125-
if (!signedUserId) return
126-
const isIntegrated = await this.externalInterationService.checkIntegrated(signedUserId)
127-
if (!isIntegrated) return
128-
this.externalInterationService.notifyWebhook({
129-
type: 'deleted',
130-
post_id: post.id,
131-
})
132-
})
133-
}
134-
135-
return { ...post, url_slug: data.url_slug }
79+
// const prevSeriesPost = await this.db.seriesPost.findFirst({
80+
// where: {
81+
// fk_post_id: post.id,
82+
// },
83+
// })
84+
85+
// if (!prevSeriesPost && series_id) {
86+
// await this.seriesService.appendToSeries(series_id, post.id)
87+
// }
88+
89+
// // 다른 시리즈에 추가하는 경우
90+
// if (prevSeriesPost && prevSeriesPost.fk_series_id !== series_id) {
91+
// if (series_id) {
92+
// await this.checkSeriesOwnership(series_id, userId)
93+
// await this.seriesService.appendToSeries(series_id, post.id)
94+
// }
95+
96+
// // remove series
97+
// await Promise.all([
98+
// this.seriesService.subtractIndexAfter(prevSeriesPost.fk_series_id!, prevSeriesPost.index!),
99+
// this.db.seriesPost.delete({
100+
// where: {
101+
// id: prevSeriesPost.id,
102+
// },
103+
// }),
104+
// ])
105+
// }
106+
107+
// await this.db.post.update({
108+
// where: {
109+
// id: post.id,
110+
// },
111+
// data,
112+
// })
113+
114+
// try {
115+
// await Promise.all([
116+
// data.is_temp ? null : this.searchService.searchSync.update(post.id),
117+
// this.graphcdn.purgePost(post.id),
118+
// ])
119+
// } catch (error) {
120+
// console.error(error)
121+
// }
122+
123+
// if (!post.is_private && data.is_private) {
124+
// setImmediate(async () => {
125+
// if (!signedUserId) return
126+
// const isIntegrated = await this.externalInterationService.checkIntegrated(signedUserId)
127+
// if (!isIntegrated) return
128+
// this.externalInterationService.notifyWebhook({
129+
// type: 'deleted',
130+
// post_id: post.id,
131+
// })
132+
// })
133+
// }
134+
135+
return { ...post, url_slug: data.url_slug || '' } as { url_slug: string } & Post
136136
}
137137
private async initializePostProcess<T extends 'write' | 'edit'>({
138138
input,
@@ -216,15 +216,15 @@ export class PostApiService implements Service {
216216

217217
let post: Post | null = null
218218
if (type === 'write') {
219-
post = await this.db.post.create({
220-
data: {
221-
...(data as Omit<WritePostInput, 'tags' | 'token' | 'series_id'>),
222-
fk_user_id: signedUserId,
223-
},
224-
include: {
225-
user: true,
226-
},
227-
})
219+
// post = await this.db.post.create({
220+
// data: {
221+
// ...(data as Omit<WritePostInput, 'tags' | 'token' | 'series_id'>),
222+
// fk_user_id: signedUserId,
223+
// },
224+
// include: {
225+
// user: true,
226+
// },
227+
// })
228228
}
229229

230230
if (type === 'edit') {
@@ -243,6 +243,8 @@ export class PostApiService implements Service {
243243
}
244244

245245
if (!post) {
246+
post = await this.db.post.findFirst({ include: { user: true } })
247+
return { data, isPublish, post, userId: signedUserId, series_id }
246248
throw new NotFoundError('Not found post')
247249
}
248250

0 commit comments

Comments
 (0)