Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] 대시보드 조회시에 summary 여부 판단 추가 #376

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/api/src/dashboard/dashboard.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';

import { Applicant } from '@/entity/applicant.entity';
import { Summary } from '@/entity/summary.entity';
import { Ticle } from '@/entity/ticle.entity';

import { DashboardController } from './dashboard.controller';
import { DashboardService } from './dashboard.service';

@Module({
imports: [TypeOrmModule.forFeature([Ticle, Applicant])],
imports: [TypeOrmModule.forFeature([Ticle, Applicant, Summary])],
controllers: [DashboardController],
providers: [DashboardService],
})
Expand Down
30 changes: 26 additions & 4 deletions apps/api/src/dashboard/dashboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Repository } from 'typeorm';
import { ErrorMessage, TicleStatus } from '@repo/types';

import { Applicant } from '@/entity/applicant.entity';
import { Summary } from '@/entity/summary.entity';
import { Ticle } from '@/entity/ticle.entity';

@Injectable()
Expand All @@ -12,7 +13,9 @@ export class DashboardService {
@InjectRepository(Ticle)
private readonly ticleRepository: Repository<Ticle>,
@InjectRepository(Applicant)
private readonly applicantRepository: Repository<Applicant>
private readonly applicantRepository: Repository<Applicant>,
@InjectRepository(Summary)
private readonly summaryRepository: Repository<Summary>
) {}

async getCreatedTicleList(
Expand All @@ -25,7 +28,15 @@ export class DashboardService {

const queryBuilder = this.ticleRepository
.createQueryBuilder('ticle')
.select(['ticle.id', 'ticle.title', 'ticle.startTime', 'ticle.endTime', 'ticle.ticleStatus'])
.leftJoin('ticle.summary', 'summary')
.select([
'ticle.id',
'ticle.title',
'ticle.startTime',
'ticle.endTime',
'ticle.ticleStatus',
'summary.id',
])
.where('ticle.speaker = :speakerId', { speakerId })
.skip(skip)
.take(pageSize);
Expand All @@ -40,7 +51,12 @@ export class DashboardService {
}
}

const [ticles, totalItems] = await queryBuilder.getManyAndCount();
const [ticle, totalItems] = await queryBuilder.getManyAndCount();

const ticles = ticle.map((ticle) => ({
...ticle,
summary: ticle.summary ? ticle.summary.id !== null : false,
}));

const totalPages = Math.ceil(totalItems / pageSize);

Expand All @@ -62,6 +78,7 @@ export class DashboardService {
const queryBuilder = this.applicantRepository
.createQueryBuilder('applicant')
.leftJoinAndSelect('applicant.ticle', 'ticle')
.leftJoin('ticle.summary', 'summary')
.select([
'applicant.id',
'ticle.id',
Expand All @@ -70,6 +87,7 @@ export class DashboardService {
'ticle.startTime',
'ticle.endTime',
'ticle.ticleStatus',
'summary.id',
])
.where('applicant.user = :userId', { userId })
.skip(skip)
Expand All @@ -87,7 +105,11 @@ export class DashboardService {

const [applicants, totalItems] = await queryBuilder.getManyAndCount();

const ticles = applicants.map((applicant) => applicant.ticle);
const ticles = applicants.map((applicant) => ({
...applicant.ticle,
summary: applicant.ticle.summary ? applicant.ticle.summary.id !== null : false,
}));

const totalPages = Math.ceil(totalItems / pageSize);

return {
Expand Down
Loading