Skip to content

Commit dce95e8

Browse files
committed
WIP: change body in editor
1 parent bc37e81 commit dce95e8

File tree

40 files changed

+616
-333
lines changed

40 files changed

+616
-333
lines changed

apps/book-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"@types/jest": "^29.5.12",
7878
"@types/node": "^20.12.5",
7979
"dotenv-cli": "^7.2.1",
80-
"eslint": "^9.0.0",
80+
"eslint": "^9.5.0",
8181
"inquirer": "^9.2.23",
8282
"jest": "^29.6.4",
8383
"nodemon": "^2.0.22",

apps/book-server/scripts/createMock.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Seeder {
8282
},
8383
data: {
8484
parent_id: parentId,
85-
level: 2,
85+
depth: 2,
8686
},
8787
})
8888

@@ -110,7 +110,7 @@ class Seeder {
110110
},
111111
data: {
112112
parent_id: parentId,
113-
level: 3,
113+
depth: 3,
114114
},
115115
})
116116

apps/book-server/src/graphql/Book.gql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ type Query {
1111
}
1212

1313
type Mutation {
14-
deploy(input: BookIDInput!): Void @auth
15-
build(input: BookIDInput!): Void @auth
14+
deploy(input: BookIDInput!): Void! @auth
15+
build(input: BookIDInput!): Void! @auth
1616
}
1717

1818
type Subscription {

apps/book-server/src/graphql/Page.gql

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,31 @@ type Page {
1515
index: Int!
1616
url_slug: String!
1717
code: String!
18-
level: Int!
18+
depth: Int!
1919
created_at: Date!
2020
updated_at: Date!
2121
childrens: [Page!]!
2222
}
2323

2424
type Query {
2525
pages(input: GetPagesInput!): [Page!]! @auth
26+
page(input: GetPageInput!): Page @auth
2627
}
2728

2829
type Mutation {
2930
create(input: CreatePageInput!): Page @auth
30-
reorder(input: ReorderInput!): Void @auth
31+
reorder(input: ReorderInput!): Void! @auth
3132
}
3233

3334
input GetPagesInput {
3435
book_url_slug: String!
3536
}
3637

38+
input GetPageInput {
39+
book_url_slug: String!
40+
page_url_slug: String!
41+
}
42+
3743
input CreatePageInput {
3844
title: String!
3945
index: Int!

apps/book-server/src/graphql/generated.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,20 @@ export type CreatePageInput = {
5151
type: PageType
5252
}
5353

54+
export type GetPageInput = {
55+
book_url_slug: Scalars['String']['input']
56+
page_url_slug: Scalars['String']['input']
57+
}
58+
5459
export type GetPagesInput = {
5560
book_url_slug: Scalars['String']['input']
5661
}
5762

5863
export type Mutation = {
59-
build?: Maybe<Scalars['Void']['output']>
64+
build: Scalars['Void']['output']
6065
create?: Maybe<Page>
61-
deploy?: Maybe<Scalars['Void']['output']>
62-
reorder?: Maybe<Scalars['Void']['output']>
66+
deploy: Scalars['Void']['output']
67+
reorder: Scalars['Void']['output']
6368
}
6469

6570
export type MutationBuildArgs = {
@@ -84,10 +89,10 @@ export type Page = {
8489
childrens: Array<Page>
8590
code: Scalars['String']['output']
8691
created_at: Scalars['Date']['output']
92+
depth: Scalars['Int']['output']
8793
fk_writer_id: Scalars['ID']['output']
8894
id: Scalars['ID']['output']
8995
index: Scalars['Int']['output']
90-
level: Scalars['Int']['output']
9196
parent_id?: Maybe<Scalars['ID']['output']>
9297
title: Scalars['String']['output']
9398
type: Scalars['String']['output']
@@ -99,13 +104,18 @@ export type PageType = 'folder' | 'page' | 'separator'
99104

100105
export type Query = {
101106
book?: Maybe<Book>
107+
page?: Maybe<Page>
102108
pages: Array<Page>
103109
}
104110

105111
export type QueryBookArgs = {
106112
input: BookIdInput
107113
}
108114

115+
export type QueryPageArgs = {
116+
input: GetPageInput
117+
}
118+
109119
export type QueryPagesArgs = {
110120
input: GetPagesInput
111121
}
@@ -236,6 +246,7 @@ export type ResolversTypes = {
236246
Boolean: ResolverTypeWrapper<Scalars['Boolean']['output']>
237247
CreatePageInput: CreatePageInput
238248
Date: ResolverTypeWrapper<Scalars['Date']['output']>
249+
GetPageInput: GetPageInput
239250
GetPagesInput: GetPagesInput
240251
ID: ResolverTypeWrapper<Scalars['ID']['output']>
241252
Int: ResolverTypeWrapper<Scalars['Int']['output']>
@@ -260,6 +271,7 @@ export type ResolversParentTypes = {
260271
Boolean: Scalars['Boolean']['output']
261272
CreatePageInput: CreatePageInput
262273
Date: Scalars['Date']['output']
274+
GetPageInput: GetPageInput
263275
GetPagesInput: GetPagesInput
264276
ID: Scalars['ID']['output']
265277
Int: Scalars['Int']['output']
@@ -310,7 +322,7 @@ export type MutationResolvers<
310322
ParentType extends ResolversParentTypes['Mutation'] = ResolversParentTypes['Mutation'],
311323
> = {
312324
build?: Resolver<
313-
Maybe<ResolversTypes['Void']>,
325+
ResolversTypes['Void'],
314326
ParentType,
315327
ContextType,
316328
RequireFields<MutationBuildArgs, 'input'>
@@ -322,13 +334,13 @@ export type MutationResolvers<
322334
RequireFields<MutationCreateArgs, 'input'>
323335
>
324336
deploy?: Resolver<
325-
Maybe<ResolversTypes['Void']>,
337+
ResolversTypes['Void'],
326338
ParentType,
327339
ContextType,
328340
RequireFields<MutationDeployArgs, 'input'>
329341
>
330342
reorder?: Resolver<
331-
Maybe<ResolversTypes['Void']>,
343+
ResolversTypes['Void'],
332344
ParentType,
333345
ContextType,
334346
RequireFields<MutationReorderArgs, 'input'>
@@ -344,10 +356,10 @@ export type PageResolvers<
344356
childrens?: Resolver<Array<ResolversTypes['Page']>, ParentType, ContextType>
345357
code?: Resolver<ResolversTypes['String'], ParentType, ContextType>
346358
created_at?: Resolver<ResolversTypes['Date'], ParentType, ContextType>
359+
depth?: Resolver<ResolversTypes['Int'], ParentType, ContextType>
347360
fk_writer_id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>
348361
id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>
349362
index?: Resolver<ResolversTypes['Int'], ParentType, ContextType>
350-
level?: Resolver<ResolversTypes['Int'], ParentType, ContextType>
351363
parent_id?: Resolver<Maybe<ResolversTypes['ID']>, ParentType, ContextType>
352364
title?: Resolver<ResolversTypes['String'], ParentType, ContextType>
353365
type?: Resolver<ResolversTypes['String'], ParentType, ContextType>
@@ -371,6 +383,12 @@ export type QueryResolvers<
371383
ContextType,
372384
RequireFields<QueryBookArgs, 'input'>
373385
>
386+
page?: Resolver<
387+
Maybe<ResolversTypes['Page']>,
388+
ParentType,
389+
ContextType,
390+
RequireFields<QueryPageArgs, 'input'>
391+
>
374392
pages?: Resolver<
375393
Array<ResolversTypes['Page']>,
376394
ParentType,

apps/book-server/src/graphql/resolvers/pageResolvers.mts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const pageResolvers: Resolvers = {
88
const pageService = container.resolve(PageService)
99
return await pageService.getPages(input.book_url_slug, ctx.writer?.id)
1010
},
11+
page: async (_, { input }, ctx) => {
12+
const pageService = container.resolve(PageService)
13+
return await pageService.getPage(input, ctx.writer?.id)
14+
},
1115
},
1216
Mutation: {
1317
create: async (_, { input }, ctx) => {

apps/book-server/src/services/PageService/index.mts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ConfilctError } from '@errors/ConfilctError.mjs'
22
import { NotFoundError } from '@errors/NotfoundError.mjs'
33
import { UnauthorizedError } from '@errors/UnauthorizedError.mjs'
4-
import type { CreatePageInput, ReorderInput } from '@graphql/generated.js'
4+
import type { CreatePageInput, GetPageInput, ReorderInput } from '@graphql/generated.js'
55
import { MongoService } from '@lib/mongo/MongoService.mjs'
66
import { UtilsService } from '@lib/utils/UtilsService.mjs'
77
import { Page, Prisma } from '@packages/database/velog-book-mongo'
@@ -11,6 +11,7 @@ import { injectable, singleton } from 'tsyringe'
1111
interface Service {
1212
updatePageAndChildrenUrlSlug(args: UpdatePageAndChildrenUrlSlugArgs): Promise<void>
1313
getPages(bookUrlSlug: string, signedWriterId?: string): Promise<Page[]>
14+
getPage(input: GetPageInput, signedWriterId?: string): Promise<Page | null>
1415
create(input: CreatePageInput, signedWriterId?: string): Promise<Page>
1516
reorder(input: ReorderInput, signedWriterId?: string): Promise<void>
1617
}
@@ -107,13 +108,18 @@ export class PageService implements Service {
107108
},
108109
orderBy,
109110
include: {
111+
// depth 1
110112
childrens: {
111113
orderBy,
112114
include: {
115+
// depth 2
113116
childrens: {
114117
orderBy,
115118
include: {
116-
childrens: true,
119+
// depth 3
120+
childrens: {
121+
orderBy,
122+
},
117123
},
118124
},
119125
},
@@ -124,6 +130,36 @@ export class PageService implements Service {
124130
return pages
125131
}
126132

133+
public async getPage(input: GetPageInput, signedWriterId?: string): Promise<Page | null> {
134+
console.log('input', input)
135+
console.log('signedWriterId', signedWriterId)
136+
if (!signedWriterId) {
137+
throw new UnauthorizedError('Not authorized')
138+
}
139+
140+
const { book_url_slug, page_url_slug } = input
141+
142+
const book = await this.bookSerivce.findByUrlSlug(book_url_slug)
143+
144+
if (!book) {
145+
throw new NotFoundError('Not found book')
146+
}
147+
148+
if (book.fk_writer_id !== signedWriterId) {
149+
throw new ConfilctError('Not owner of book')
150+
}
151+
152+
const page = await this.mongo.page.findFirst({
153+
where: {
154+
url_slug: page_url_slug,
155+
book_id: book.id,
156+
fk_writer_id: signedWriterId,
157+
},
158+
})
159+
160+
return page
161+
}
162+
127163
public async create(input: CreatePageInput, signedWriterId?: string): Promise<Page> {
128164
if (!signedWriterId) {
129165
throw new UnauthorizedError('Not authorized')
@@ -168,7 +204,7 @@ export class PageService implements Service {
168204
fk_writer_id: signedWriterId,
169205
book_id: book.id,
170206
type,
171-
level: parentPage ? parentPage.level + 1 : 1,
207+
depth: Math.min(3, parentPage ? parentPage.depth + 1 : 1), // max level 3
172208
parent_id: parentPage ? parentPage!.id : null,
173209
},
174210
})

apps/book-web/eslint.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import nextConfig from '@packages/eslint-config/next.mjs'
1+
import nextConfig from '@packages/eslint-config/base.mjs'
22

33
/** @type {import("eslint").Linter.Config} */
44
export default [
5-
...nextConfig,
65
{
76
rules: {
87
'@typescript-eslint/no-unused-vars': ['error', { ignoreRestSiblings: true }],
98
},
109
},
10+
...nextConfig,
1111
]

apps/book-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"@types/node": "^20",
5555
"@types/react": "^18",
5656
"@types/react-dom": "^18",
57-
"eslint": "^9.0.0",
57+
"eslint": "^9.5.0",
5858
"inquirer": "^9.2.23",
5959
"postcss": "^8",
6060
"prettier": "^3.2.5",

0 commit comments

Comments
 (0)