0.0.18 • Published 6 years ago

mongoose-draft-log v0.0.18

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

draft

draft provide log raw data change history and sync new data to use current plugin model collection

Prerequisites

  • nodejs (support async/await)
  • mongodb
  • mongoose

Installing

npm i mongoose-draft-log

Getting Started

const doc = { name: 'ada', age: 23 };
const person = new Person(doc);
const id = person._id;

await person.saveDraft(); // save draft collection

const item = await person.findPendingDraft(); // item.changes: { _id: { new: 5a97a189a72229035767aabd }, age: { new: 23 }, name: { new: 'ada' } }

await person.updateDraft({ t: 2 });

const item2 = await person.findPendingDraft(); // item2.extra {t: 2}

person.age = 20 // no effect

await person.applyDraft(); // update current draft status done. read draft changes new value save person collection

const p = Person.findById(id) // p.age is 23

p.draft() // p.draft() return a draft model, provide mongoose select in draft model

p.age = 20

await p.saveDraft() // changes.age: { new: 20, old: 23 }
await p.applyDraft() // p.age is 20

p.name = 'abc'

await p.saveDraft()
await p.discardDraft(); // remove all model_id(p._id) = p._id. model = 'person' status = 'pending' data. and update p.draft_status = done

Running the tests

npm i && npm test

Authors

License

MIT

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago