Skip to content

Commit d5e5f65

Browse files
committed
feat: MChartsService createHistory 메서드 수정
1 parent f6c2350 commit d5e5f65

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

backend/src/m-charts/m-charts.service.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export class MChartsService {
1414
constructor(
1515
@InjectRepository(M_Charts)
1616
private readonly chartsRepository: Repository<M_Charts>,
17-
@InjectRepository(Histories)
18-
private readonly historiesRepository: Repository<Histories>,
1917
@InjectRepository(M_Complaints)
2018
private readonly complaintsRepository: Repository<M_Complaints>,
19+
@InjectRepository(Histories)
20+
private readonly historiesRepository: Repository<Histories>,
2121
@InjectRepository(Orders)
2222
private readonly ordersRepository: Repository<Orders>,
2323
) {}
@@ -47,27 +47,20 @@ export class MChartsService {
4747
async createHistory(chartId: number, historyDto: CreateHistoryDto) {
4848
const chart = await this.chartsRepository.findOne({
4949
where: { id: chartId },
50-
relations: { patient: true },
50+
relations: { patient: { history: true } },
5151
});
5252

5353
if (!chart) {
5454
throw new NotFoundException();
5555
}
5656

57-
const existingHistory = await this.historiesRepository.findOne({
58-
where: { patient: { id: chart.patient.id } },
57+
return await this.historiesRepository.save({
58+
patient: {
59+
id: chart.patient.id,
60+
},
61+
...chart.patient.history,
62+
...historyDto,
5963
});
60-
61-
if (existingHistory) {
62-
Object.assign(existingHistory, historyDto);
63-
return this.historiesRepository.save(existingHistory);
64-
} else {
65-
const newHistory = this.historiesRepository.create({
66-
...historyDto,
67-
patient: { id: chart.patient.id },
68-
});
69-
return this.historiesRepository.save(newHistory);
70-
}
7164
}
7265

7366
async updateStatus(chartId: number) {

0 commit comments

Comments
 (0)