Skip to content

Commit e9788f0

Browse files
authored
408 Fix period NPS on chart legend (#149)
* Add endpoint * Fix minor issues
1 parent 5dd0833 commit e9788f0

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

controllers/object.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,34 @@ router.post(
125125
}
126126
);
127127

128+
router.post("/get-selected-csa-nps",
129+
[
130+
body("data")
131+
.isArray()
132+
.withMessage("data is required and must be an array"),
133+
],
134+
async (req, res) => {
135+
const errors = validationResult(req);
136+
if (!errors.isEmpty()) {
137+
return res.status(400).json({ errors: errors.array() });
138+
}
139+
140+
const { data } = matchedData(req);
141+
142+
const response = [];
143+
const periodNpsObject = {};
144+
145+
data.forEach((item) => {
146+
const { periodNps, ...rest } = item;
147+
response.push(rest);
148+
149+
if (!periodNpsObject[item.customerSupportFullName]) {
150+
periodNpsObject[item.customerSupportFullName] = periodNps;
151+
}
152+
});
153+
154+
return res.status(200).send({ response, periodNpsByCsa: periodNpsObject });
155+
}
156+
)
157+
128158
export default router;

0 commit comments

Comments
 (0)