Skip to content

Commit 628233a

Browse files
committed
feat: check is deploy book when init page
1 parent df06068 commit 628233a

File tree

22 files changed

+519
-296
lines changed

22 files changed

+519
-296
lines changed

apps/book-server/scripts/createMock.mts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { faker } from '@faker-js/faker'
66
import { UtilsService } from '@lib/utils/UtilsService.mjs'
77
import { PageService } from '@services/PageService/index.mjs'
88
import { BookService } from '@services/BookService/index.mjs'
9+
import { RedisService } from '@lib/redis/RedisService.mjs'
10+
import { WriterService } from '@services/WriterService/index.mjs'
11+
import { JwtService } from '@lib/jwt/JwtService.mjs'
912

1013
class Seeder {
1114
constructor(
@@ -140,7 +143,11 @@ class Seeder {
140143
const main = async () => {
141144
const mongo = new MongoService()
142145
const utils = new UtilsService()
143-
const bookService = new BookService(mongo)
146+
const redis = new RedisService()
147+
const jwt = new JwtService()
148+
149+
const writerService = new WriterService(jwt, mongo, redis)
150+
const bookService = new BookService(mongo, redis, writerService)
144151
const pageService = new PageService(mongo, utils, bookService)
145152
const seeder = new Seeder(mongo, utils, pageService)
146153

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { HttpError } from './HttpError.mjs'
2+
3+
export class NotFoundError extends HttpError {
4+
constructor(message = 'NOT_FOUND') {
5+
super('not found', message, 404)
6+
}
7+
}

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ type Book {
77
}
88

99
type Query {
10-
book(input: BookIDInput!): Book
10+
book(input: BookIdInput!): Book
11+
isDeploy(input: IsDeployInput!): Boolean! @auth
1112
}
1213

1314
type Mutation {
@@ -16,17 +17,17 @@ type Mutation {
1617
}
1718

1819
type Subscription {
19-
bookBuildInstalled(input: BookUrlSlugInput!): SubScriptionPayload @auth
20-
bookBuildCompleted(input: BookUrlSlugInput!): SubScriptionPayload @auth
21-
bookDeployCompleted(input: BookUrlSlugInput!): SubScriptionPayload @auth
20+
buildInstalled(input: BookUrlSlugInput!): SubScriptionPayload @auth
21+
buildCompleted(input: BookUrlSlugInput!): SubScriptionPayload @auth
22+
deployCompleted(input: BookUrlSlugInput!): SubScriptionPayload @auth
2223
}
2324

24-
input BookIDInput {
25+
input BookIdInput {
2526
book_id: ID!
2627
}
2728

2829
input BookUrlSlugInput {
29-
url_slug: String!
30+
book_url_slug: String!
3031
}
3132

3233
type SubScriptionPayload {
@@ -35,8 +36,14 @@ type SubScriptionPayload {
3536

3637
type BuildResult {
3738
result: Boolean!
39+
message: String
3840
}
3941

4042
type DeployResult {
4143
published_url: String
44+
message: String
45+
}
46+
47+
input IsDeployInput {
48+
book_url_slug: String!
4249
}

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

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ export type BookIdInput = {
4444
}
4545

4646
export type BookUrlSlugInput = {
47-
url_slug: Scalars['String']['input']
47+
book_url_slug: Scalars['String']['input']
4848
}
4949

5050
export type BuildResult = {
51+
message?: Maybe<Scalars['String']['output']>
5152
result: Scalars['Boolean']['output']
5253
}
5354

@@ -65,6 +66,7 @@ export type DeletePageInput = {
6566
}
6667

6768
export type DeployResult = {
69+
message?: Maybe<Scalars['String']['output']>
6870
published_url?: Maybe<Scalars['String']['output']>
6971
}
7072

@@ -77,6 +79,10 @@ export type GetPagesInput = {
7779
book_url_slug: Scalars['String']['input']
7880
}
7981

82+
export type IsDeployInput = {
83+
book_url_slug: Scalars['String']['input']
84+
}
85+
8086
export type Mutation = {
8187
build: BuildResult
8288
create?: Maybe<Page>
@@ -132,6 +138,7 @@ export type PageType = 'folder' | 'page' | 'separator'
132138

133139
export type Query = {
134140
book?: Maybe<Book>
141+
isDeploy: Scalars['Boolean']['output']
135142
page?: Maybe<Page>
136143
pages: Array<Page>
137144
}
@@ -140,6 +147,10 @@ export type QueryBookArgs = {
140147
input: BookIdInput
141148
}
142149

150+
export type QueryIsDeployArgs = {
151+
input: IsDeployInput
152+
}
153+
143154
export type QueryPageArgs = {
144155
input: GetPageInput
145156
}
@@ -160,20 +171,20 @@ export type SubScriptionPayload = {
160171
}
161172

162173
export type Subscription = {
163-
bookBuildCompleted?: Maybe<SubScriptionPayload>
164-
bookBuildInstalled?: Maybe<SubScriptionPayload>
165-
bookDeployCompleted?: Maybe<SubScriptionPayload>
174+
buildCompleted?: Maybe<SubScriptionPayload>
175+
buildInstalled?: Maybe<SubScriptionPayload>
176+
deployCompleted?: Maybe<SubScriptionPayload>
166177
}
167178

168-
export type SubscriptionBookBuildCompletedArgs = {
179+
export type SubscriptionBuildCompletedArgs = {
169180
input: BookUrlSlugInput
170181
}
171182

172-
export type SubscriptionBookBuildInstalledArgs = {
183+
export type SubscriptionBuildInstalledArgs = {
173184
input: BookUrlSlugInput
174185
}
175186

176-
export type SubscriptionBookDeployCompletedArgs = {
187+
export type SubscriptionDeployCompletedArgs = {
177188
input: BookUrlSlugInput
178189
}
179190

@@ -278,7 +289,7 @@ export type DirectiveResolverFn<TResult = {}, TParent = {}, TContext = {}, TArgs
278289
/** Mapping between all available schema types and the resolvers types */
279290
export type ResolversTypes = {
280291
Book: ResolverTypeWrapper<BookModel>
281-
BookIDInput: BookIdInput
292+
BookIdInput: BookIdInput
282293
BookUrlSlugInput: BookUrlSlugInput
283294
Boolean: ResolverTypeWrapper<Scalars['Boolean']['output']>
284295
BuildResult: ResolverTypeWrapper<BuildResult>
@@ -290,6 +301,7 @@ export type ResolversTypes = {
290301
GetPagesInput: GetPagesInput
291302
ID: ResolverTypeWrapper<Scalars['ID']['output']>
292303
Int: ResolverTypeWrapper<Scalars['Int']['output']>
304+
IsDeployInput: IsDeployInput
293305
JSON: ResolverTypeWrapper<Scalars['JSON']['output']>
294306
Mutation: ResolverTypeWrapper<{}>
295307
Page: ResolverTypeWrapper<PageModel>
@@ -308,7 +320,7 @@ export type ResolversTypes = {
308320
/** Mapping between all available schema types and the resolvers parents */
309321
export type ResolversParentTypes = {
310322
Book: BookModel
311-
BookIDInput: BookIdInput
323+
BookIdInput: BookIdInput
312324
BookUrlSlugInput: BookUrlSlugInput
313325
Boolean: Scalars['Boolean']['output']
314326
BuildResult: BuildResult
@@ -320,6 +332,7 @@ export type ResolversParentTypes = {
320332
GetPagesInput: GetPagesInput
321333
ID: Scalars['ID']['output']
322334
Int: Scalars['Int']['output']
335+
IsDeployInput: IsDeployInput
323336
JSON: Scalars['JSON']['output']
324337
Mutation: {}
325338
Page: PageModel
@@ -359,6 +372,7 @@ export type BuildResultResolvers<
359372
ContextType = GraphQLContext,
360373
ParentType extends ResolversParentTypes['BuildResult'] = ResolversParentTypes['BuildResult'],
361374
> = {
375+
message?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>
362376
result?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType>
363377
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>
364378
}
@@ -371,6 +385,7 @@ export type DeployResultResolvers<
371385
ContextType = GraphQLContext,
372386
ParentType extends ResolversParentTypes['DeployResult'] = ResolversParentTypes['DeployResult'],
373387
> = {
388+
message?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>
374389
published_url?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>
375390
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>
376391
}
@@ -458,6 +473,12 @@ export type QueryResolvers<
458473
ContextType,
459474
RequireFields<QueryBookArgs, 'input'>
460475
>
476+
isDeploy?: Resolver<
477+
ResolversTypes['Boolean'],
478+
ParentType,
479+
ContextType,
480+
RequireFields<QueryIsDeployArgs, 'input'>
481+
>
461482
page?: Resolver<
462483
Maybe<ResolversTypes['Page']>,
463484
ParentType,
@@ -485,26 +506,26 @@ export type SubscriptionResolvers<
485506
ContextType = GraphQLContext,
486507
ParentType extends ResolversParentTypes['Subscription'] = ResolversParentTypes['Subscription'],
487508
> = {
488-
bookBuildCompleted?: SubscriptionResolver<
509+
buildCompleted?: SubscriptionResolver<
489510
Maybe<ResolversTypes['SubScriptionPayload']>,
490-
'bookBuildCompleted',
511+
'buildCompleted',
491512
ParentType,
492513
ContextType,
493-
RequireFields<SubscriptionBookBuildCompletedArgs, 'input'>
514+
RequireFields<SubscriptionBuildCompletedArgs, 'input'>
494515
>
495-
bookBuildInstalled?: SubscriptionResolver<
516+
buildInstalled?: SubscriptionResolver<
496517
Maybe<ResolversTypes['SubScriptionPayload']>,
497-
'bookBuildInstalled',
518+
'buildInstalled',
498519
ParentType,
499520
ContextType,
500-
RequireFields<SubscriptionBookBuildInstalledArgs, 'input'>
521+
RequireFields<SubscriptionBuildInstalledArgs, 'input'>
501522
>
502-
bookDeployCompleted?: SubscriptionResolver<
523+
deployCompleted?: SubscriptionResolver<
503524
Maybe<ResolversTypes['SubScriptionPayload']>,
504-
'bookDeployCompleted',
525+
'deployCompleted',
505526
ParentType,
506527
ContextType,
507-
RequireFields<SubscriptionBookDeployCompletedArgs, 'input'>
528+
RequireFields<SubscriptionDeployCompletedArgs, 'input'>
508529
>
509530
}
510531

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,43 @@ const bookResolvers: Resolvers = {
1111
const bookService = container.resolve(BookService)
1212
return await bookService.getBook(input.book_id)
1313
},
14+
isDeploy: async (_, { input }, ctx) => {
15+
const bookService = container.resolve(BookService)
16+
return await bookService.isDeploy(input, ctx.writer?.id)
17+
},
1418
},
1519
Mutation: {
1620
build: async (_, { input }, ctx) => {
1721
const bookBuildService = container.resolve(BookBuildService)
18-
return await bookBuildService.build(input.url_slug, ctx.writer?.id)
22+
return await bookBuildService.build(input.book_url_slug, ctx.writer?.id)
1923
},
2024
deploy: async (_, { input }, ctx) => {
2125
const bookDeployService = container.resolve(BookDeployService)
22-
return await bookDeployService.deploy(input.url_slug, ctx.writer?.id)
26+
return await bookDeployService.deploy(input.book_url_slug, ctx.writer?.id)
2327
},
2428
},
2529
Subscription: {
26-
bookBuildInstalled: {
30+
buildInstalled: {
2731
subscribe: async (_, { input }, { pubsub }) => {
2832
const mqService = container.resolve(MqService)
29-
const generator = mqService.topicGenerator('bookBuildInstalled')
30-
const topic = generator(input.url_slug)
33+
const generator = mqService.topicGenerator('buildInstalled')
34+
const topic = generator(input.book_url_slug)
3135
return pubsub.subscribe(topic)
3236
},
3337
},
34-
bookBuildCompleted: {
38+
buildCompleted: {
3539
subscribe: async (_, { input }, { pubsub }) => {
3640
const mqService = container.resolve(MqService)
37-
const generator = mqService.topicGenerator('bookBuildCompleted')
38-
const topic = generator(input.url_slug)
41+
const generator = mqService.topicGenerator('buildCompleted')
42+
const topic = generator(input.book_url_slug)
3943
return pubsub.subscribe(topic)
4044
},
4145
},
42-
bookDeployCompleted: {
46+
deployCompleted: {
4347
subscribe: async (_, { input }, { pubsub }) => {
4448
const mqService = container.resolve(MqService)
45-
const generator = mqService.topicGenerator('bookDeployCompleted')
46-
const topic = generator(input.url_slug)
49+
const generator = mqService.topicGenerator('deployCompleted')
50+
const topic = generator(input.book_url_slug)
4751
return pubsub.subscribe(topic)
4852
},
4953
},

apps/book-server/src/lib/mq/MqService.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export class MqService {
3232

3333
public topicGenerator<T extends SubscriptionResolverKey>(type: T): (args: any) => string {
3434
const map: TopicMap = {
35-
bookBuildCompleted: (bookId: string) => `BOOK_BUILD:completed:${bookId}`,
36-
bookBuildInstalled: (bookId: string) => `BOOK_BUILD:installed:${bookId}`,
37-
bookDeployCompleted: (bookId: string) => `BOOK_DEPLOY:completed:${bookId}`,
35+
buildCompleted: (bookId: string) => `BOOK_BUILD:completed:${bookId}`,
36+
buildInstalled: (bookId: string) => `BOOK_BUILD:installed:${bookId}`,
37+
deployCompleted: (bookId: string) => `BOOK_DEPLOY:completed:${bookId}`,
3838
}
3939
const generator = map[type]
4040
if (!generator) {

0 commit comments

Comments
 (0)