move mock customer api to service

This commit is contained in:
2017-03-21 19:45:12 -07:00
parent 2c11f883cd
commit be3b5cfeda
2 changed files with 76 additions and 52 deletions

View File

@@ -1,3 +1,5 @@
import { fetchAll } from '../services/customers';
export default {
namespaced: true,
state: {
@@ -31,58 +33,10 @@ export default {
fetchCustomers({ commit, state }, opts = {}) {
commit('setPagination', opts);
// TODO: fetch customers from server
return new Promise((resolve) => {
const customers = [{
id: 'ai7rgail73ria3uhr',
firstname: 'Peter',
lastname: 'Amaya',
email: 'PeterPAmaya@teleworm.us',
city: 'Greensboro',
state: 'NC',
}, {
id: '7a4toi7g4ot8jaefg',
firstname: 'Derrick',
lastname: 'Duplantis',
email: 'DerrickCDuplantis@dayrep.com',
city: 'Freeport',
state: 'NY',
}, {
id: 'q93r7ga4otilsghae',
firstname: 'Andrea',
lastname: 'Hernandez',
email: 'AndreaRHernandez@armyspy.com',
city: 'Maumee',
state: 'OH',
}, {
id: 'ia73groi7ah4oitgn',
firstname: 'Daniel',
lastname: 'Hurt',
email: 'DanielGHurt@teleworm.us',
city: 'Cedar Rapids',
state: 'IA',
}, {
id: '98hi3kubtksgli9rg',
firstname: 'Milagros',
lastname: 'Anderson',
email: 'MilagrosCAnderson@jourrapide.com',
city: 'Kansas City',
state: 'KS',
}, {
id: 'pl74p39otujs5kuhz',
firstname: 'An',
lastname: 'K\'ung',
email: 'AnKung@dayrep.com',
city: 'Benton Harbor',
state: 'MI',
}];
setTimeout(() => {
const { page, count } = state.pagination;
const results = customers.slice(page, count);
commit('setCustomers', results);
resolve();
}, 300);
fetchAll().then((customers) => {
const { page, count } = state.pagination;
const results = customers.slice(page, count);
commit('setCustomers', results);
});
},
},