File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed
plugins/policy-api/server Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -29,5 +29,16 @@ export default ({ strapi }: { strapi: Strapi }) => ({
29
29
} catch ( error ) {
30
30
ctx . badRequest ( error . message ) ;
31
31
}
32
+ } ,
33
+ async getDashboardCount ( ctx ) {
34
+ try {
35
+ const policyService = strapi
36
+ . plugin ( PLUGIN )
37
+ . service ( "policyService" ) ;
38
+ const count = await policyService . getDashboardCount ( ) ;
39
+ ctx . body = count ;
40
+ } catch ( error ) {
41
+ ctx . badRequest ( error . message ) ;
42
+ }
32
43
}
33
44
} ) ;
Original file line number Diff line number Diff line change @@ -17,6 +17,15 @@ export default [
17
17
auth : false
18
18
}
19
19
} ,
20
+ {
21
+ method : "GET" ,
22
+ path : "/dashboard" ,
23
+ handler : "policyController.getDashboardCount" ,
24
+ config : {
25
+ middlewares : [ "plugin::policy-api.authMiddleware" ] ,
26
+ auth : false
27
+ }
28
+ } ,
20
29
{
21
30
method : 'GET' ,
22
31
path : '/' ,
Original file line number Diff line number Diff line change @@ -62,5 +62,25 @@ export default ({ strapi }: { strapi: Strapi }) => ({
62
62
} catch ( error ) {
63
63
throw new Error ( error . message ) ;
64
64
}
65
+ } ,
66
+ async getDashboardCount ( ) {
67
+ try {
68
+ const active = await strapi . entityService . count ( 'api::pp-policy.pp-policy' , {
69
+ filters : { status : 'active' }
70
+ } ) ;
71
+ const inactive = await strapi . entityService . count ( 'api::pp-policy.pp-policy' , {
72
+ filters : { status : 'inactive' }
73
+ } ) ;
74
+ const published = await strapi . entityService . count ( 'api::pp-policy.pp-policy' , {
75
+ filters : { status : 'published' }
76
+ } ) ;
77
+ return {
78
+ active,
79
+ inactive,
80
+ published
81
+ }
82
+ } catch ( error ) {
83
+ throw new Error ( error . message ) ;
84
+ }
65
85
}
66
86
} ) ;
You can’t perform that action at this time.
0 commit comments