Skip to content

Commit 192df9f

Browse files
committed
refactor: fix inaccurate names
1 parent 127f623 commit 192df9f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/strategies/document-group.strategy.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,16 @@ export class DocumentGroupStrategy implements BuilderStrategy {
109109
function resolveCollisions(docs: VersionRestDocument[], field: 'fileId' | 'filename'): VersionRestDocument[] {
110110
const fileIdMap = groupBy(docs, (document) => document[field])
111111
return ([...fileIdMap.values()] as VersionRestDocument[][]).reduce((acc, docs) => {
112-
const [_, ...rest] = docs
113-
rest.forEach((document, index) => {document[field] = addPostfix(` ${index + 1}`, document[field])})
112+
const [_, ...duplicates] = docs
113+
duplicates.forEach((document, index) => {document[field] = rename(document[field], index)})
114114
return [...acc, ...docs]
115115
}, [] as VersionRestDocument[])
116116
}
117117

118-
function addPostfix(postfix: string, fileName: string): string {
118+
function rename(fileName: string, index: number): string {
119119
const nameParts = fileName.split('.')
120120
const extension = nameParts.length > 1 ? nameParts[nameParts?.length - 1] : ''
121-
const nameWithPostfix = `${nameParts[0]}${postfix}`
121+
const nameWithPostfix = `${nameParts[0]} ${index + 1}`
122122

123123
if (extension) {
124124
return `${nameWithPostfix}.${extension}`

0 commit comments

Comments
 (0)