Passed
Push — master ( 09a54a...cba1d2 )
by Muhammad Dyas
01:26
created

handlers.js   A

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 20
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 13
mnd 0
bc 0
fnc 1
dl 0
loc 20
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A ➔ updateWinnerCardHandler 0 12 1
1
import {buildMessageBody, buildNameListWinnerSection} from './src/helpers/components.js';
2
import {updateMessage} from './src/helpers/api.js';
3
import {getRandomWinners} from './src/helpers/utils.js';
4
5
/**
6
 * @param {object} requestBody - list of names
7
 * @returns {Promise<void>} update message
8
 */
9
export async function updateWinnerCardHandler(requestBody) {
10
  const names = requestBody.names;
11
  const winner = getRandomWinners(names);
12
  const messageText = `Congratulations! We have shuffled the list of names and the winner is *${winner.join(',')}*.`;
13
  const message = buildMessageBody(buildNameListWinnerSection(names, winner), messageText);
14
  const request = {
15
    name: requestBody.messageId,
16
    requestBody: message,
17
    updateMask: 'text,cardsV2',
18
  };
19
  await updateMessage(request);
20
}
21
22