Skip to content

Commit

Permalink
fix: don't mutate objects
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosantangelo committed May 28, 2019
1 parent b8f7c67 commit 5b56340
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Model.ts
Expand Up @@ -159,14 +159,17 @@ export class Model<T> {
row: U,
onConflict?: OnConflict
): Promise<U> {
const createdAt = new Date()
const updatedAt = new Date()
row = Object.assign({}, row) // Shallow copy, we only modify top level props

if (onConflict) {
onConflict.changes = onConflict.changes || row
const changes = Object.assign({}, onConflict.changes) // Shallow copy, we only modify top level props
onConflict.changes = onConflict.changes ? changes : row
}

if (this.withTimestamps) {
const createdAt = new Date()
const updatedAt = new Date()

row.created_at = row.created_at || createdAt
row.updated_at = row.updated_at || updatedAt

Expand Down

0 comments on commit 5b56340

Please sign in to comment.