@benjy2976/pmsg 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@benjy2976/pmsg",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "generator of models and store default for pinia",
5
5
  "main": "src/Model.js",
6
6
  "scripts": {
package/src/Model.js CHANGED
@@ -23,10 +23,7 @@ export default class Model {
23
23
  params : { modeljs: true },// Aquí se configuran parámetros adicionales a enviar en los request excepto DELETE
24
24
  modelGetters : {},// Aquí se configuran parámetros adicionales a enviar en los request excepto DELETE
25
25
  paginate : false,// Condicional para definir si el modelo tiene paginación
26
- pagination : {
27
- current_page : 1,
28
- per_page : 10
29
- }
26
+ pagination : {current_page: 1, per_page: 10},// Configuración de paginación
30
27
  }
31
28
  //config.hasKey=config.hasKey!=undefined?config.hasKey:config.key!=undefined
32
29
  defaultValues = Object.assign(defaultValues, config)
@@ -50,16 +47,16 @@ export default class Model {
50
47
  this.params = defaultValues.params
51
48
  this.modelGetters = defaultValues.modelGetters
52
49
  this.paginate = defaultValues.paginate
53
- this.pagination = {...defaultValues.pagination}
50
+ this.pagination = defaultValues.pagination
54
51
  this.state = {}
55
52
  this.getters = {}
56
53
  this.actions = {}
57
54
  }
58
55
 
59
- get(url = '', params = {}) {
56
+ get(url = '', params = {}, config = {}) {
60
57
  params = Object.assign(params, this.params)
61
58
  url = this.route + '/' + url
62
- return this.instance.get(url, params)
59
+ return this.instance.get(url, params, config)
63
60
  }
64
61
 
65
62
  post(url = '', params = {}) {
@@ -69,9 +66,9 @@ export default class Model {
69
66
  }
70
67
 
71
68
  // Función para obtener el listado de Objetos de la base de datos
72
- getAll(params = {}) {
69
+ getAll(params = {}, config = {}) {
73
70
  params = Object.assign(params, this.params)
74
- return this.instance.get(this.route, params)
71
+ return this.instance.get(this.route, params, config)
75
72
  }
76
73
 
77
74
  // Función para crear un objeto en la base de datos
@@ -193,7 +190,9 @@ export default class Model {
193
190
 
194
191
  }
195
192
  }),
196
- sync : this.sync
193
+ sync : this.sync,
194
+ paginate : this.paginate,
195
+ pagination : this.pagination,
197
196
  }
198
197
  }
199
198
 
@@ -217,5 +216,4 @@ export default class Model {
217
216
  getNameAttribute() {
218
217
  return this.name
219
218
  }
220
- }
221
-
219
+ }
@@ -22,7 +22,6 @@ export default function createModelStore (model, state = {}, getters = {}, actio
22
22
  return areObjEquals(d,data)
23
23
  }
24
24
  }
25
- const resolveR = (item) => item
26
25
  return {
27
26
  state : {
28
27
  itemSelected : { loading: false, ...model.getDefault() },
@@ -34,10 +33,12 @@ export default function createModelStore (model, state = {}, getters = {}, actio
34
33
  maxRelationsResolve : config.maxRelationsResolve,
35
34
  relations : config.relations,
36
35
  syncStatus : config.sync,
37
- pagination : {...config.paginate, last_page: 1, total: 0},
36
+ paginate : config.paginate,
37
+ pagination : config.pagination,
38
38
  selectedStatus : false,
39
39
  timeOutAsinc : null,
40
40
  check : check,
41
+ resolve : (item) => item,
41
42
  ...state
42
43
  },
43
44
  getters : {
@@ -51,21 +52,21 @@ export default function createModelStore (model, state = {}, getters = {}, actio
51
52
  return item ? item[model.getNameAttribute()] : null
52
53
  },
53
54
  // Getter para obtener el objeto seleccionado
54
- find : ({ items, key }) => (id, level = 1) => {
55
- const item = items.find(d => d[key] === id)
56
- return item ? resolveR(item, level):model.getDefault()
55
+ find : ({ items, key, resolve }) => (id, level = 1) => {
56
+ const item = items.find(d => d[key] === Number(id))
57
+ return item ? resolve(item, level):model.getDefault()
57
58
  },
58
59
  // Getter para obtener la lista de objetos
59
- list : ({items}) => {
60
- return items.map(resolveR)
60
+ list : ({items, resolve}) => {
61
+ return items.map(resolve)
61
62
  },
62
63
  // Getter para obtener la lista de objetos filtrados
63
- filter : ({items}) => (filter, level = 1) => {
64
- return items.filter(filter).map(item => resolveR(item, level))
64
+ filter : ({items,resolve}) => (filter, level = 1) => {
65
+ return items.filter(filter).map(item => resolve(item, level))
65
66
  },
66
67
  // Getter para obtener el objeto seleccionado o falso si no hay seleccion
67
- selected : ({ itemSelected, selectedStatus }) => {
68
- return selectedStatus ? resolveR(itemSelected) : selectedStatus
68
+ selected : ({ itemSelected, selectedStatus, resolve }) => {
69
+ return selectedStatus ? resolve(itemSelected) : selectedStatus
69
70
  },
70
71
  ...getters
71
72
  },
@@ -130,10 +131,10 @@ export default function createModelStore (model, state = {}, getters = {}, actio
130
131
  },
131
132
  // Action para obtener la lista de objetos de el servidor
132
133
  async get (params = {}, pagination={}) {
133
- //var commit = store.commit
134
+ //var commit = store.commit
134
135
  const action = this.syncStatus ? 'sync' : 'setItems';
135
-
136
- if (model.paginate) {
136
+
137
+ if (this.paginate) {
137
138
  params = {...params, ...Object.assign({
138
139
  page : this.pagination.current_page, per_page : this.pagination.per_page
139
140
  }, pagination) };
@@ -143,10 +144,12 @@ export default function createModelStore (model, state = {}, getters = {}, actio
143
144
  model.getAll(params).then(response => {
144
145
  const data = response.data;
145
146
  model.save(data.data);
146
- this[action](data.data);
147
- const { data: _ , ...pagination } = data;
148
- this.pagination = Object.assign(this.pagination, pagination);
149
- //console.log('get', this.pagination)
147
+ this[action](data.data);
148
+ if (this.paginate) {
149
+ // eslint-disable-next-line no-unused-vars
150
+ const { data: _, ...pagination } = data.meta;
151
+ this.pagination = Object.assign(this.pagination, pagination);
152
+ }
150
153
  this.afterGet();
151
154
  resolve(response);
152
155
  }).catch(reject);
@@ -174,7 +177,7 @@ export default function createModelStore (model, state = {}, getters = {}, actio
174
177
  //var commit = store.commit
175
178
  return new Promise((resolve, reject) => {
176
179
  model.getAll(params).then(response => {
177
- this.sync(response.data);
180
+ this.sync(response.data.data);
178
181
  this.afterGet();
179
182
  resolve(response);
180
183
  }).catch(reject);
@@ -187,7 +190,7 @@ export default function createModelStore (model, state = {}, getters = {}, actio
187
190
  // divide y vencceras
188
191
  this.setItems([]);
189
192
  model.getAll(params).then(response => {
190
- this.setItems(response.data);
193
+ this.setItems(response.data.data);
191
194
  this.afterGet();
192
195
  resolve(response);
193
196
  }).catch(reject);
@@ -346,4 +349,4 @@ export default function createModelStore (model, state = {}, getters = {}, actio
346
349
  ...actions
347
350
  }
348
351
  };
349
- }
352
+ }