From 330a19a7655b69bacf445fd52f49627ad342ad17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Mon, 10 Oct 2022 10:17:24 +0200 Subject: [PATCH] Fix username and day in daily msg --- .../source/jobs/daily-stand-up.ts | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/standup-mattermost-bot/source/jobs/daily-stand-up.ts b/standup-mattermost-bot/source/jobs/daily-stand-up.ts index ef58618a6..d0616d8a4 100644 --- a/standup-mattermost-bot/source/jobs/daily-stand-up.ts +++ b/standup-mattermost-bot/source/jobs/daily-stand-up.ts @@ -1,6 +1,7 @@ import { botConfig, serverUrl } from '../config.js' -import { getUserChannels, sendMessage } from '../mattermost.js' +import { getUser, getUserChannels, sendMessage } from '../mattermost.js' import { initMongodb } from '../mongodb.js' +import { snakeToCamelCaseKeys } from '../utils.js' const mongo = await initMongodb() @@ -20,10 +21,24 @@ if (!standupChannel) { throw new Error('Standup channel not found') } -const index = new Date().getDay() - 1 -const nextDayMember = (await mongo.getWeeklyTeamOrder())?.memberIds[index] +const day = new Date().getDay() +const nextWorkingDay = day >= 4 ? 1 : day + 1 +const nextDayMemberId = (await mongo.getWeeklyTeamOrder())?.memberIds[ + nextWorkingDay - 1 +] + +const nextDayMember = + typeof nextDayMemberId === 'string' && + (await getUser({ + serverUrl, + accessToken, + userId: nextDayMemberId, + }).then(({ body }) => snakeToCamelCaseKeys(body))) + const nextDayStandup = nextDayMember - ? `:arrow_forward: Demain, c'est ${nextDayMember} qui anime le stand-up.` + ? `:arrow_forward: ${nextWorkingDay === 1 ? 'Lundi' : 'Demain'}, c'est @${ + nextDayMember.username + } qui anime le stand-up.` : '' const now = new Date()