Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/services/nps/sendNpsResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SystemLogger } from '../../lib/logger/system';

type NPSResultPayload = {
total: number;
votes: INpsVote[];
votes: Pick<INpsVote, 'identifier' | 'roles' | 'score' | 'comment'>[];
};

export const sendNpsResults = Meteor.bindEnvironment(function sendNpsResults(npsId: string, data: NPSResultPayload) {
Expand Down
14 changes: 10 additions & 4 deletions server/services/nps/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export class NPSService extends ServiceClassInternal implements INPSService {
},
{
projection: {
_id: 0,
identifier: 1,
roles: 1,
score: 1,
Expand All @@ -121,17 +120,24 @@ export class NPSService extends ServiceClassInternal implements INPSService {
}),
);

const votes = sending.filter(Boolean) as INpsVote[];
const votes = sending.filter(Boolean) as Pick<INpsVote, '_id' | 'identifier' | 'roles' | 'score' | 'comment'>[];
if (votes.length > 0) {
const voteIds = votes.map(({ _id }) => _id);

const votesWithoutIds = votes.map(({ identifier, roles, score, comment }) => ({
identifier,
roles,
score,
comment,
}));

const payload = {
total,
votes,
votes: votesWithoutIds,
};
sendNpsResults(nps._id, payload);

this.NpsVote.updateVotesToSent(voteIds);
await this.NpsVote.updateVotesToSent(voteIds);
}

const totalSent = await this.NpsVote.findByNpsIdAndStatus(nps._id, INpsVoteStatus.SENT).count();
Expand Down