Skip to content

Commit

Permalink
simplified array indexing since the value is constant, passes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-jp committed Jun 15, 2023
1 parent d1ddfea commit cded51f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/model/MutableAreaDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,12 @@ export default class MutableAreaDataSource extends AreaDataSource {
* @param newAreaName new area name
* @param depth tree depth
*/
async updatePathTokens (session: ClientSession, changeRecord: ChangeRecordMetadataType, area: AreaDocumnent, newAreaName: string, depth: number = 1): Promise<void> {
async updatePathTokens (session: ClientSession, changeRecord: ChangeRecordMetadataType, area: AreaDocumnent, newAreaName: string, changeIndex: number = -1): Promise<void> {
if (area.pathTokens.length > 1) {
if (changeIndex === -1) { changeIndex = area.pathTokens.length - 1 }

const newPath = [...area.pathTokens]
newPath[newPath.length - depth] = newAreaName
newPath[changeIndex] = newAreaName
area.set({ pathTokens: newPath })
area.set({ _change: changeRecord })
await area.save({ session })
Expand All @@ -391,7 +393,7 @@ export default class MutableAreaDataSource extends AreaDataSource {
// TS complains about ObjectId type
// Fix this when we upgrade Mongoose library
// @ts-expect-error
await this.updatePathTokens(session, changeRecord, childArea, newAreaName, depth + 1)
await this.updatePathTokens(session, changeRecord, childArea, newAreaName, changeIndex)
}))
}
}
Expand Down

0 comments on commit cded51f

Please sign in to comment.