1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import samples from '../_sampleData.js'
- class ProjectMock {
- constructor (data) {
- for (let prop in data) {
- this[prop] = data[prop]
- }
- // use this switch to simulate save errors.
- this._saveError = false
- // use this switch to simulate remove errors.
- this._removeError = false
- }
- static findOne (criteria, callback) {
- const { id } = criteria
- // Find only the entry with id 58d3d6883d34293254afae42
- if (id === '58d3d6883d34293254afae42') {
- callback(undefined, samples[0])
- return
- }
- // else return 404
- callback(Error('item not found'), undefined)
- }
- static find (criteria, options, callback) {
- const { limit, offset } = options
- // apply criteria
- const sampleSlice = samples.slice(offset, offset + limit)
- // return the array
- if (sampleSlice) {
- callback(undefined, sampleSlice)
- return
- }
- // if nothing can be shown, return 404
- callback(Error('no items found'), undefined)
- }
- save (callback) {
- //
- }
- remove (callback) {
- //
- }
- }
- export default ProjectMock
|