1
1
import { ConfilctError } from '@errors/ConfilctError.mjs'
2
2
import { NotFoundError } from '@errors/NotfoundError.mjs'
3
3
import { UnauthorizedError } from '@errors/UnauthorizedError.mjs'
4
- import type { CreatePageInput , GetPageInput , ReorderInput } from '@graphql/generated.js'
4
+ import type {
5
+ CreatePageInput ,
6
+ GetPageInput ,
7
+ ReorderInput ,
8
+ UpdatePageInput ,
9
+ } from '@graphql/generated.js'
5
10
import { MongoService } from '@lib/mongo/MongoService.mjs'
6
11
import { UtilsService } from '@lib/utils/UtilsService.mjs'
7
12
import { Page , Prisma } from '@packages/database/velog-book-mongo'
@@ -13,6 +18,7 @@ interface Service {
13
18
getPages ( bookUrlSlug : string , signedWriterId ?: string ) : Promise < Page [ ] >
14
19
getPage ( input : GetPageInput , signedWriterId ?: string ) : Promise < Page | null >
15
20
create ( input : CreatePageInput , signedWriterId ?: string ) : Promise < Page >
21
+ update ( input : UpdatePageInput , signedWriterId ?: string ) : Promise < Page >
16
22
reorder ( input : ReorderInput , signedWriterId ?: string ) : Promise < void >
17
23
}
18
24
@@ -137,8 +143,6 @@ export class PageService implements Service {
137
143
138
144
const { book_url_slug, page_url_slug } = input
139
145
140
- console . log ( 'page_url_slug' , page_url_slug )
141
-
142
146
const book = await this . bookSerivce . findByUrlSlug ( book_url_slug )
143
147
144
148
if ( ! book ) {
@@ -161,7 +165,6 @@ export class PageService implements Service {
161
165
where : whereQuery ,
162
166
} )
163
167
164
- console . log ( 'page' , page ?. title )
165
168
return page
166
169
}
167
170
@@ -220,6 +223,20 @@ export class PageService implements Service {
220
223
return `${ this . utils . removeCodeFromUrlSlug ( parent_url_slug ) } /${ this . utils . escapeForUrl ( title ) . toLowerCase ( ) } -${ code } `
221
224
}
222
225
226
+ public async update ( input : UpdatePageInput , signedWriterId ?: string ) : Promise < Page > {
227
+ if ( ! signedWriterId ) {
228
+ throw new UnauthorizedError ( 'Not authorized' )
229
+ }
230
+
231
+ const { book_url_slug, page_url_slug, ...whereQuery } = input
232
+
233
+ const book = await this . bookSerivce . findByUrlSlug ( book_url_slug )
234
+
235
+ if ( ! book ) {
236
+ throw new NotFoundError ( 'Not found book' )
237
+ }
238
+ }
239
+
223
240
public async reorder ( input : ReorderInput , signedWriterId ?: string ) : Promise < void > {
224
241
if ( ! signedWriterId ) {
225
242
throw new UnauthorizedError ( 'Not authorized' )
0 commit comments