import data from './tasks.json';
import fixture from 'can/util/fixture/';

//a mock ajax service
fixture({
  'GET /tasks' () {
    return data;
  },
  'POST /tasks' (params, response) {
    let newId = data[data.length - 1].id + 1;
    data.push(can.extend({
      id: newId
    }, params.data));
    response(data[data.length - 1])
  },
  'GET /tasks/{id}' (params, response) {
    let items = data.filter((item) => {
      return item.id == params.data.id;
    });
    if (!items.length) {
      response(404, 'Not Found');
      return;
    }
    return items[0];
  },
  'PUT /tasks/{id}' (params, response) {
    let item = data.filter(i => {
      return i.id === params.data.id;
    });
    let index = data.indexOf(item);
    if (index !== -1) {
      data[index] = can.extend(item, params.data);
      response(data);
    } else {
      response(404, 'Not Found');
    }
  },
  'DELETE /tasks/{id}' (params, response) {
    let item = data.filter(i => {
      return i.id === params.data.id;
    });
    let index = data.indexOf(item);
    if (index !== -1) {
      data.splice(data.indexOf(item), 1);
      response(data);
    } else {
      response(404, 'Not Found');
    }
  }
});

@@ -325,16 +325,17 @@
 th - 1%5D)
+;
 %0A  %7D,%0A  

fix missing semicolon