Skip to content

Commit

Permalink
[Fix] 월별 통계가 작동하지 않던 문제 수정 (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
jyoo0515 authored Apr 1, 2024
1 parent 75897cb commit 7bce1bb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Route.add({
*/
Route.add({
method: 'GET',
path: `${apiPath}scoreboard/{listType}/{scoreTypeInput}/{month}/{year}`,
path: `${apiPath}monthlyScoreboard/{listType}/{scoreTypeInput}/{month}/{year}`,
handler: async (request: any, res: any) => {
try {
const { listType, scoreTypeInput, month, year } = request.params;
Expand Down
16 changes: 8 additions & 8 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { parseMessage, parseReactedMessage } from './lib/parseMessage';
import { validBotMention, validMessage, validReaction } from './lib/validator';
import Rtm from './slack/Rtm';
import Wbc from './slack/Wbc';
import log from 'bog'
import log from 'bog';

const { enableDecrement, dailyCap, dailyDecCap, emojiInc, emojiDec, disableEmojiDec } = config.slack;

Expand All @@ -19,7 +19,7 @@ interface Updates {
type: string;
}
const emojis: Array<Emojis> = [];
const dashBoardUrl = 'http://ec2-43-201-180-152.ap-northeast-2.compute.amazonaws.com:3333/'
const dashBoardUrl = 'http://ec2-43-201-180-152.ap-northeast-2.compute.amazonaws.com:3333/';

const incEmojis = emojiInc.split(',').map((emoji) => emoji.trim());
incEmojis.forEach((emoji: string) => emojis.push({ type: 'inc', emoji }));
Expand Down Expand Up @@ -50,7 +50,7 @@ const notifyUser = (user: string, message: string, messageBlock?: Object[]) => {
};

const handleBurritos = async (giver: string, channel: string, duckedMessage: string, duckedMessageLink: string, updates: Updates[]) => {
log.info(updates)
log.info(updates);
if (!enableDecrement) {
const burritos = await BurritoStore.givenBurritosToday(giver, 'from');
const diff = dailyCap - burritos;
Expand Down Expand Up @@ -92,8 +92,8 @@ const handleBurritos = async (giver: string, channel: string, duckedMessage: str
const leftOverDucks = dailyCap - givenDucks;
const receivers = [...new Set(updates.map((it) => it.username))];
const eachGivenDucks = Math.ceil(updates.length / receivers.length);
const firstLineContent = duckedMessage.split('\n')[0] ?? ""
const trailingDots = duckedMessage.split('\n').length > 1 ? "..." : ""
const firstLineContent = duckedMessage.split('\n')[0] ?? '';
const trailingDots = duckedMessage.split('\n').length > 1 ? '...' : '';
notifyUser(
giver,
`${receivers
Expand Down Expand Up @@ -145,7 +145,7 @@ const start = () => {
if (result) {
const { giver, updates } = result;
if (updates.length) {
const messageLink = await Wbc.fetchMessageLink(event.channel, event.event_ts)
const messageLink = await Wbc.fetchMessageLink(event.channel, event.event_ts);
await handleBurritos(giver, event.channel, event.text, messageLink, updates);
}
}
Expand All @@ -157,10 +157,10 @@ const start = () => {
if (validReaction(event, emojis)) {
const channelId = event.item.channel;
const originalContent = await Wbc.fetchReactedMessage(channelId, event.item.ts);
const messageLink = await Wbc.fetchMessageLink(channelId, event.item.ts)
const messageLink = await Wbc.fetchMessageLink(channelId, event.item.ts);
const { updates } = parseReactedMessage(event, originalContent, emojis);
if (updates.length) {
await handleBurritos(event.user, channelId, originalContent.text, messageLink,updates);
await handleBurritos(event.user, channelId, originalContent.text, messageLink, updates);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/database/drivers/GenericDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class GenericDriver extends Store implements Driver {
}
const selected = data
.filter((item: any) => {
if (item.given_at.getMonth() === month && item.given_at.getFullYear() === year) {
if (item.given_at.getMonth() + 1 == month && item.given_at.getFullYear() == year) {
if (user) {
if (item[listType] === user) return item;
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/slack/Wbc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,20 @@ class Wbc {
limit: 1,
});

log.info(res.messages[0])
log.info(res.messages[0]);

return res.messages[0];
}

async fetchMessageLink(channelId: string, ts: number) {
log.info('Fetching messageLink');
log.info(`channelid ${channelId} ts ${ts}`)
log.info(`channelid ${channelId} ts ${ts}`);
const res = await this.wbc.chat.getPermalink({
channel: channelId,
message_ts: ts,
});

return res.permalink
return res.permalink;
}
}

Expand Down
4 changes: 2 additions & 2 deletions theme/fun.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ const renderMonthPicker = () => {
const year = date.getFullYear();
console.log({ month, year });
fetcher('monthlyScore', { listType, scoreType, month, year }).then((response) => {
console.log(response);
store = response;
sortUsers();
render();
});
},
Expand Down Expand Up @@ -85,7 +85,7 @@ async function fetcher(type, { username, listType, scoreType, month, year }) {
return json;
}
case 'monthlyScore': {
const res = await fetch(`/api/scoreboard/${listType}/${scoreType}/${month}/${year}`);
const res = await fetch(`/api/monthlyScoreboard/${listType}/${scoreType}/${month}/${year}`);
const json = await res.json();
return json.data;
}
Expand Down

0 comments on commit 7bce1bb

Please sign in to comment.