Skip to content

Commit 79ade1f

Browse files
committed
feat: Add conditional check for updating file path in FilestorageService
1 parent 4c638f5 commit 79ade1f

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/core/filestorage/filestorage.service.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,22 @@ export class FilestorageService extends AbstractServiceSchema {
135135
let updated: ModifyResult<Query<T, T, any, T>>
136136
const data = await super.findById<Document<any, any, Filestorage> & Filestorage>(_id)
137137
if (!data) throw new BadRequestException(`Filestorage ${_id} not found`)
138-
await this._model.db.transaction(async (session) => {
139-
updated = await super.update(_id, update, { ...options, session })
140-
try {
141-
await this.storage.getDisk(data.namespace).move(data.path, update.path)
142-
} catch (e) {
143-
if (e.code === 'E_UNKNOWN') {
144-
const err = new BadRequestException(`Impossible de déplacer le fichier ${data.path} vers ${update.path}`)
145-
err.stack = e.stack
146-
throw err
138+
139+
if (update.path && data.path !== update.path) {
140+
await this._model.db.transaction(async (session) => {
141+
updated = await super.update(_id, update, { ...options, session })
142+
try {
143+
await this.storage.getDisk(data.namespace).move(data.path, update.path)
144+
} catch (e) {
145+
if (e.code === 'E_UNKNOWN') {
146+
const err = new BadRequestException(`Impossible de déplacer le fichier ${data.path} vers ${update.path}`)
147+
err.stack = e.stack
148+
throw err
149+
}
150+
throw e
147151
}
148-
throw e
149-
}
150-
})
152+
})
153+
}
151154
return updated
152155
}
153156
/* eslint-enable */

0 commit comments

Comments
 (0)