Skip to content

Commit 3b891ec

Browse files
authored
Merge pull request #139 from beckn/dashboard_api
Created dashboard API
2 parents 988a862 + f0d6c77 commit 3b891ec

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

plugins/policy-api/server/controllers/policy/policy-controller.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,16 @@ export default ({ strapi }: { strapi: Strapi }) => ({
2929
} catch (error) {
3030
ctx.badRequest(error.message);
3131
}
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+
}
3243
}
3344
});

plugins/policy-api/server/routes/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ export default [
1717
auth: false
1818
}
1919
},
20+
{
21+
method: "GET",
22+
path: "/dashboard",
23+
handler: "policyController.getDashboardCount",
24+
config: {
25+
middlewares: ["plugin::policy-api.authMiddleware"],
26+
auth: false
27+
}
28+
},
2029
{
2130
method: 'GET',
2231
path: '/',

plugins/policy-api/server/services/policy/policy-service.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,25 @@ export default ({ strapi }: { strapi: Strapi }) => ({
6262
} catch (error) {
6363
throw new Error(error.message);
6464
}
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+
}
6585
}
6686
});

0 commit comments

Comments
 (0)