[FIX] NPS never finishing sending results (#25067)

pull/24950/merge
Diego Sampaio 4 years ago committed by GitHub
parent 0401c477a4
commit 08755082fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      server/services/nps/sendNpsResults.ts
  2. 14
      server/services/nps/service.ts

@ -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) {

@ -109,7 +109,6 @@ export class NPSService extends ServiceClassInternal implements INPSService {
},
{
projection: {
_id: 0,
identifier: 1,
roles: 1,
score: 1,
@ -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();

Loading…
Cancel
Save