Skip to content

Commit

Permalink
[FIX] NPS never finishing sending results (#25067)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Apr 7, 2022
1 parent 1ec8eef commit b50b84c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
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

0 comments on commit b50b84c

Please sign in to comment.