model.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import samples from '../_sampleData.js'
  2. class ProjectMock {
  3. constructor (data) {
  4. for (let prop in data) {
  5. this[prop] = data[prop]
  6. }
  7. // use this switch to simulate save errors.
  8. this._saveError = false
  9. // use this switch to simulate remove errors.
  10. this._removeError = false
  11. }
  12. static findOne (criteria, callback) {
  13. const { id } = criteria
  14. // Find only the entry with id 58d3d6883d34293254afae42
  15. if (id === '58d3d6883d34293254afae42') {
  16. callback(undefined, samples[0])
  17. return
  18. }
  19. // else return 404
  20. callback(Error('item not found'), undefined)
  21. }
  22. static find (criteria, options, callback) {
  23. const { limit, offset } = options
  24. // apply criteria
  25. const sampleSlice = samples.slice(offset, offset + limit)
  26. // return the array
  27. if (sampleSlice) {
  28. callback(undefined, sampleSlice)
  29. return
  30. }
  31. // if nothing can be shown, return 404
  32. callback(Error('no items found'), undefined)
  33. }
  34. save (callback) {
  35. //
  36. }
  37. remove (callback) {
  38. //
  39. }
  40. }
  41. export default ProjectMock