Skip to content

Commit

Permalink
remove need to pass in ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Tong committed Nov 13, 2017
1 parent dedc226 commit 94afbc5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ This you can start using as follows:

```js
// create
const model = await MyModel.audit({request,auth}).create({name: 'John'})
const model = await MyModel.audit().create({name: 'John'})

// update
const model = MyModel.find(1)
await model.audit({request, auth}).update({name: 'Simon'})
await model.audit().update({name: 'Simon'})

// delete
const model = MyModel.find(1)
await model.audit({request, auth}).delete()
await model.audit().delete()
```

## Built With
Expand All @@ -66,6 +66,10 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file

## Changelog

- v2.0.1
- Removed need to pass in `ctx` parameters.
- Update README and instructions.md files.

- v2.0.0
- Removed ctx injection on boot. `ctx` parameters need to be passed in manually now.
- Updated README to reflect new changes.
Expand Down
9 changes: 8 additions & 1 deletion instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,12 @@ class MyModel extends Model {
This you can start using as follows:

```js
await MyModel.createWithAudit(/** model data **/)
// create
await MyModel.audit().create(/** model data **/)

// update
await MyModel.audit().update(/** model data **/)

// delete
await MyModel.audit().delete()
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adonis-auditable",
"version": "2.0.0",
"version": "2.0.1",
"description": "Audit AdonisJS models",
"main": " ",
"scripts": {
Expand Down
14 changes: 7 additions & 7 deletions providers/AuditableProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class AuditableProvider extends ServiceProvider {
}

boot () {
// const Context = this.app.use('Adonis/Src/HttpContext')
// const Auditable = this.app.use('Auditable')
//
// // add ctx to datagrid
// Context.onReady(ctx => {
// Auditable.ctx = ctx
// })
const Context = this.app.use('Adonis/Src/HttpContext')
const Auditable = this.app.use('Auditable')

// add ctx to datagrid
Context.onReady(ctx => {
Auditable.ctx = ctx
})
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/Traits/Auditable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ const Audit = use('App/Models/Audit')
class Auditable {
register (Model) {
// create methods
Model.audit = function (ctx) {
const self = this
Model.audit = function () {
return {
create: createWithAudit(ctx).bind(this)
create: createWithAudit(self.ctx).bind(this)
}
}

// update/delete methods
Model.prototype.audit = function (ctx) {
Model.prototype.audit = function () {
return {
update: updateWithAudit(ctx).bind(this),
delete: deleteWithAudit(ctx).bind(this)
update: updateWithAudit(self.ctx).bind(this),
delete: deleteWithAudit(self.ctx).bind(this)
}
}
}
Expand Down

0 comments on commit 94afbc5

Please sign in to comment.