Skip to content

Commit

Permalink
fix: 고전독서 인증 현황 업데이트 시 입력 순서 보장하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
therealjamesjung committed Aug 27, 2024
1 parent f5ddfb4 commit bf86405
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/godok/dto/godok-status.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { GodokCategoryStatus, GodokStatus } from '../types/godokStatus.type';
import { count } from 'console';

class GodokCategoryStatusDto {
@ApiProperty({
Expand Down
19 changes: 7 additions & 12 deletions src/godok/godok.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import { Injectable } from '@nestjs/common';
import { GodokSlot } from '@prisma/client';
import * as _ from 'lodash';
import { PrismaService } from 'src/common/services/prisma.service';
import { GodokReservationResponse } from './types/godokReservationResponse.type';
import { GodokBook } from './types/godokBook.type';
import { GodokReservationInfo } from './types/godokReservationInfo.type';
import { GodokStatusInfo } from './types/godokStatusInfo.type';
import { GodokReservationResponse } from './types/godokReservationResponse.type';
import { GodokStatus } from './types/godokStatus.type';
import { GodokCategory } from './types/godokCategory.type';
import { count } from 'console';
import { GodokStatusInfo } from './types/godokStatusInfo.type';

@Injectable()
export class GodokRepository {
Expand Down Expand Up @@ -180,7 +178,10 @@ export class GodokRepository {
userId: string,
status: GodokStatusInfo,
): Promise<void> {
const counts = Object.values(status.values);
const counts = Object.keys(status.values)
.sort((a, b) => Number(a) - Number(b))
.map((key) => status.values[key]);

await this.prismaService.godokStatus.upsert({
where: {
studentId: userId,
Expand Down Expand Up @@ -208,21 +209,15 @@ export class GodokRepository {
},
});

const categoryIds = Object.values(GodokCategory) as number[];
const categories = await this.prismaService.bookCategory.findMany({
where: {
id: {
in: categoryIds,
},
},
orderBy: {
id: 'asc',
},
});

const categoryStatuses = status.counts.map((count, idx) => {
return {
categoryCode: GodokCategory[idx] as number,
categoryCode: categories[idx].id,
categoryName: categories[idx].name,
categoryStatus: count >= categories[idx].targetCount,
count: count,
Expand Down
6 changes: 0 additions & 6 deletions src/godok/types/godokCategory.type.ts

This file was deleted.

0 comments on commit bf86405

Please sign in to comment.