Skip to content

Commit

Permalink
refactor(model): disable soft delete by default
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Sep 1, 2022
1 parent d085e9d commit 53df870
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/Models/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class Model {
* @return {boolean}
*/
static get isSoftDelete() {
return true
return false
}

/**
Expand All @@ -80,9 +80,13 @@ export class Model {
* @return {any}
*/
static get criterias() {
return {
deletedAt: Criteria.whereNull(this.DELETED_AT).get(),
if (this.isSoftDelete) {
return {
deletedAt: Criteria.whereNull(this.DELETED_AT).get(),
}
}

return {}
}

/**
Expand Down
12 changes: 12 additions & 0 deletions templates/__name__.js.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Model } from '@athenna/database'

export class <%= namePascal %> extends Model {
/**
* Run your test.
*
* @param {import('@athenna/test').HttpTestContext} ctx
*/
async shouldBeAbleToRunTests({ assert }) {
assert.equal(2 + 2, 4)
}
}
9 changes: 9 additions & 0 deletions tests/Stubs/models/Product.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ export class Product extends Model {
return ['id', 'name', 'userId']
}

/**
* Return a boolean specifying if Model will use soft delete.
*
* @return {boolean}
*/
static get isSoftDelete() {
return true
}

/**
* The default schema for model instances.
*
Expand Down
9 changes: 9 additions & 0 deletions tests/Stubs/models/ProductMySql.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ export class ProductMySql extends Model {
return ['id', 'name', 'userId']
}

/**
* Return a boolean specifying if Model will use soft delete.
*
* @return {boolean}
*/
static get isSoftDelete() {
return true
}

/**
* The default schema for model instances.
*
Expand Down
9 changes: 9 additions & 0 deletions tests/Stubs/models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ export class User extends Model {
return ['id', 'name', 'email']
}

/**
* Return a boolean specifying if Model will use soft delete.
*
* @return {boolean}
*/
static get isSoftDelete() {
return true
}

/**
* The default schema for model instances.
*
Expand Down
9 changes: 9 additions & 0 deletions tests/Stubs/models/UserMySql.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ export class UserMySql extends Model {
return ['id', 'name', 'email']
}

/**
* Return a boolean specifying if Model will use soft delete.
*
* @return {boolean}
*/
static get isSoftDelete() {
return true
}

/**
* The default schema for model instances.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Models/ModelTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ test.group('ModelTest', group => {
test('should be able to list criterias', async ({ assert }) => {
const criterias = Model.query().listCriterias()

assert.isDefined(criterias.deletedAt)
assert.isDefined(criterias)
})
})

0 comments on commit 53df870

Please sign in to comment.