Skip to content

Commit

Permalink
Merge pull request #45 from TeamCatchMe/fix/character/#43
Browse files Browse the repository at this point in the history
[fix] 캐릭터 조회 관련 QA 수정
  • Loading branch information
realwhyjay authored May 29, 2023
2 parents d378b8e + 87788a4 commit 83d7fa5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/modules/v1/activity/activity.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class ActivityRepository implements ActivityRepositoryInterface {
},
id: { lte: id },
is_delete: false,
Character: { is_public: true },
Character: { is_public: true, is_delete: false },
},
orderBy: { created_at: 'desc' },
take: limit,
Expand Down
50 changes: 29 additions & 21 deletions src/modules/v1/character/character.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,11 @@ export class CharacterService {

async getCharactersForLookingList(date: string, activityId: number) {
const limit = 10;
let offsetDate = new Date();
let offsetDate = dayjs().toDate();
let offsetId = 99999999;

if (date) {
offsetDate = dayjs(date).toDate();
console.info(offsetDate);
}
if (activityId) {
offsetId = activityId;
Expand Down Expand Up @@ -235,7 +234,6 @@ export class CharacterService {
return null;
})
.filter((item) => item !== null);

return result;
}

Expand All @@ -254,20 +252,32 @@ export class CharacterService {
const end = DateUtil.toDate(endDate);

const daysByMonth = {};
let currMonth = dayjs(start).clone().startOf('month');
let currMonth = dayjs(start).date(1);

while (currMonth.isBefore(end)) {
const monthDays = currMonth.daysInMonth();
const daysInRange = Math.min(
monthDays,
dayjs(end).diff(currMonth, 'day') + 1,
);
daysByMonth[currMonth.format('M')] = daysInRange;
const startDateOfMonth = currMonth.startOf('month').toDate();
const endDateOfMonth = currMonth.endOf('month').toDate();

const startDay = dayjs(startDateOfMonth).isAfter(start)
? dayjs(startDateOfMonth)
: dayjs(start);
const endDay = dayjs(endDateOfMonth).isBefore(end)
? dayjs(endDateOfMonth)
: dayjs(end);

const daysInRange = Math.max(endDay.diff(startDay, 'day') + 1, 0);

daysByMonth[currMonth.format('M')] = Math.min(monthDays, daysInRange);
currMonth = currMonth.add(1, 'month').startOf('month');
}

const mainMonth = +Object.keys(daysByMonth).reduce((a, b) =>
daysByMonth[a] > daysByMonth[b] ? a : b,
);
// console.info('daysByMonth', daysByMonth);
// console.info('mainMonth', mainMonth);

const activity = await this.activityRepository.findAllBetweenDateAndDate(
userId,
start,
Expand Down Expand Up @@ -360,7 +370,6 @@ export class CharacterService {
const activity = await this.activityRepository.findByDate(userId, target);

const dailyActivitiesCount: { [key: string]: number } = {};

activity.map((o) => {
dailyActivitiesCount[o.character_id] =
(dailyActivitiesCount[o.character_id] || 0) + 1;
Expand All @@ -375,17 +384,16 @@ export class CharacterService {
);

const result: Pick<Character, 'id' | 'name' | 'type' | 'level'>[] =
character.reduce((acc, cur) => {
const characterData: Pick<Character, 'id' | 'name' | 'type' | 'level'> =
{
id: cur.id,
name: cur.name,
type: cur.type,
level: cur.level,
};
acc.push(characterData);
return acc;
}, []);
characterIds.map((characterId) => {
const characterInfo = character.find((c) => c.id === characterId);
return {
id: characterInfo.id,
name: characterInfo.name,
type: characterInfo.type,
level: characterInfo.level,
};
});

return result;
}
}

0 comments on commit 83d7fa5

Please sign in to comment.