Skip to content

Commit cc940f8

Browse files
committed
Code cleanup
1 parent 5a6f1d6 commit cc940f8

File tree

1 file changed

+7
-30
lines changed

1 file changed

+7
-30
lines changed

src/api/scorecard/scorecard.service.ts

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ import {
66
import { Prisma } from '@prisma/client';
77
import {
88
mapScorecardRequestToDto,
9+
ScorecardGroupBaseDto,
910
ScorecardPaginatedResponseDto,
1011
ScorecardQueryDto,
12+
ScorecardQuestionBaseDto,
1113
ScorecardRequestDto,
1214
ScorecardResponseDto,
15+
ScorecardSectionBaseDto,
1316
ScorecardWithGroupResponseDto,
1417
} from 'src/dto/scorecard.dto';
1518
import { PrismaService } from 'src/shared/modules/global/prisma.service';
@@ -204,30 +207,22 @@ export class ScoreCardService {
204207
},
205208
},
206209
},
207-
})
208-
.catch((error) => {
209-
if (error.code !== 'P2025') {
210-
throw new NotFoundException({ message: `Scorecard not found.` });
211-
}
212-
throw new InternalServerErrorException({
213-
message: `Error: ${error.code}`,
214-
});
215210
});
216211

217212
if (!original) {
218213
throw new NotFoundException({ message: `Scorecard not found.` });
219214
}
220215

221216
// Remove id fields from nested objects for cloning
222-
const cloneGroups = original.scorecardGroups.map((group: any) => ({
217+
const cloneGroups = original.scorecardGroups.map((group: ScorecardGroupBaseDto) => ({
223218
...group,
224219
id: undefined,
225220
scorecardId: undefined,
226-
sections: group.sections.map((section: any) => ({
221+
sections: group.sections.map((section: ScorecardSectionBaseDto) => ({
227222
...section,
228223
id: undefined,
229224
scorecardGroupId: undefined,
230-
questions: section.questions.map((question: any) => ({
225+
questions: section.questions.map((question: ScorecardQuestionBaseDto) => ({
231226
...question,
232227
id: undefined,
233228
sectionId: undefined,
@@ -244,25 +239,7 @@ export class ScoreCardService {
244239
createdAt: undefined,
245240
updatedAt: undefined,
246241
scorecardGroups: {
247-
create: cloneGroups.map((group: any) => ({
248-
...group,
249-
createdAt: undefined,
250-
updatedAt: undefined,
251-
sections: {
252-
create: group.sections.map((section: any) => ({
253-
...section,
254-
createdAt: undefined,
255-
updatedAt: undefined,
256-
questions: {
257-
create: section.questions.map((question: any) => ({
258-
...question,
259-
createdAt: undefined,
260-
updatedAt: undefined,
261-
})),
262-
},
263-
})),
264-
},
265-
})),
242+
create: cloneGroups,
266243
},
267244
},
268245
include: {

0 commit comments

Comments
 (0)