File tree 3 files changed +37
-0
lines changed
3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -10,4 +10,12 @@ export class AppRepositoryGql {
10
10
11
11
return app
12
12
}
13
+
14
+ static async getBySlug ( slug : string , fields ?: AppFields [ ] ) : Promise < App > {
15
+ const appQuery = new AppQueries ( fields )
16
+ const getAppQuery : string = appQuery . getApp ( )
17
+ const { app } : AppResponse = await getClient ( ) . query ( getAppQuery , { filter : { slug : slug } } )
18
+
19
+ return app
20
+ }
13
21
}
Original file line number Diff line number Diff line change @@ -18,4 +18,22 @@ export class AppRepositoryJson {
18
18
19
19
return mock
20
20
}
21
+
22
+ static async getBySlug ( slug : string , fields ?: AppFields [ ] ) {
23
+ const mock = shop_ctx . mock ?. apps || { }
24
+
25
+ if ( slug != mock . slug ) {
26
+ throw new Error ( 'apps_not_found' )
27
+ }
28
+
29
+ const isFieldNotSelected = entry => ! fields . includes ( entry )
30
+
31
+ const deleteFieldIfNecessary = entry => {
32
+ isFieldNotSelected ( entry ) && delete mock [ entry ]
33
+ }
34
+
35
+ fields && Object . keys ( mock ) . forEach ( deleteFieldIfNecessary )
36
+
37
+ return mock
38
+ }
21
39
}
Original file line number Diff line number Diff line change @@ -16,4 +16,15 @@ export class AppService {
16
16
throw new Error ( error ?. message )
17
17
}
18
18
}
19
+
20
+ static async getBySlug ( slug : string , fields ?: AppFields [ ] ) : Promise < App > {
21
+ try {
22
+ const result = await Repository ( ) . getBySlug ( slug , fields )
23
+ BroadcastService . emit ( 'Apps' , result )
24
+
25
+ return result
26
+ } catch ( error ) {
27
+ throw new Error ( error ?. message )
28
+ }
29
+ }
19
30
}
You can’t perform that action at this time.
0 commit comments