pagination users, locations, vehicles, loads
This commit is contained in:
@@ -12,11 +12,15 @@ export const useCompanyStore = defineStore('company', () => {
|
||||
const usersTotal = ref(0);
|
||||
const usersCurrentPage = ref(1);
|
||||
const budgets = ref([]);
|
||||
const budgetsTotal = ref(0);
|
||||
const budgetsCurrentPage = ref(1);
|
||||
const locations = ref([]);
|
||||
const locationsLoads = ref([]);
|
||||
const locationsTotal = ref(0);
|
||||
const locationsCurrentPage = ref(1);
|
||||
const proposals = ref([])
|
||||
const proposals = ref([]);
|
||||
const proposalsTotal = ref(0);
|
||||
const proposalsCurrentPage = ref(1)
|
||||
const loading = ref(false);
|
||||
|
||||
const getCompanyData = async() => {
|
||||
@@ -33,7 +37,7 @@ export const useCompanyStore = defineStore('company', () => {
|
||||
const getUsersCompany = async(limit = 10, skip = 0, reload = false) => {
|
||||
const companyId = localStorage.getItem('id');
|
||||
if(users.value.length <= 0 || reload === true) {
|
||||
const filter = `company=${companyId}&&$sort%5BcreatedAt%5D=-1&$limit=${limit}&$skip=${skip}`
|
||||
const filter = `company=${companyId}&$sort%5BcreatedAt%5D=-1&$limit=${limit}&$skip=${skip}`
|
||||
const resp = await getUsers(filter);
|
||||
if(resp !== null && resp.total > 0) {
|
||||
usersTotal.value = resp.total;
|
||||
@@ -157,20 +161,26 @@ export const useCompanyStore = defineStore('company', () => {
|
||||
|
||||
///loads?company=64fa70c130d2650011ac4f3a&status[$ne]=Closed,posted_by_name[$regex]=ju&posted_by_name[$options]=i
|
||||
|
||||
const getProposalsCompany = async() => {
|
||||
const getProposalsCompany = async(filter, reload = false) => {
|
||||
const companyId = localStorage.getItem('id');
|
||||
try {
|
||||
const endpoint = `/proposals?carrier=${companyId}`;
|
||||
const {data} = await api.get(endpoint);
|
||||
proposals.value = data.data;
|
||||
if(proposals.value.length <= 0 || reload) {
|
||||
const endpoint = `/proposals?carrier=${companyId}&$sort%5BcreatedAt%5D=-1&${filter}`;
|
||||
console.log(endpoint)
|
||||
const {data} = await api.get(endpoint);
|
||||
proposals.value = data.data;
|
||||
proposalsTotal.value = data.total;
|
||||
}
|
||||
} catch (error) {
|
||||
proposals.value = [];
|
||||
proposalsTotal.value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
const createPropsal = async(formData) => {
|
||||
const data = await saveProposal(formData);
|
||||
if(data) {
|
||||
proposalsTotal.value++;
|
||||
return 'success';
|
||||
} else {
|
||||
return 'Algo salio mal, intente más tarde';
|
||||
@@ -203,10 +213,13 @@ export const useCompanyStore = defineStore('company', () => {
|
||||
|
||||
if(budgets.value.length <= 0 || reload === true) {
|
||||
try {
|
||||
const data = await getBudgets(filterStr);
|
||||
const data = await getBudgets(filterStr + '&$sort%5BcreatedAt%5D=-1');
|
||||
console.log(data.total);
|
||||
if(data.total > 0) {
|
||||
budgets.value = data.data;
|
||||
budgetsTotal.value = data.total;
|
||||
} else {
|
||||
budgetsTotal.value = 0;
|
||||
budgets.value = [];
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -238,6 +251,7 @@ export const useCompanyStore = defineStore('company', () => {
|
||||
try {
|
||||
const data = await createBudget(formData);
|
||||
if(data) {
|
||||
budgetsTotal.value++;
|
||||
budgets.value.push({
|
||||
...data,
|
||||
...localData
|
||||
@@ -255,6 +269,7 @@ export const useCompanyStore = defineStore('company', () => {
|
||||
try {
|
||||
const data = await deleteBudget(id);
|
||||
if(data) {
|
||||
budgetsTotal.value--;
|
||||
budgets.value = budgets.value.filter(budget => budget._id !== id);
|
||||
return data;
|
||||
} else {
|
||||
@@ -387,6 +402,8 @@ export const useCompanyStore = defineStore('company', () => {
|
||||
$reset,
|
||||
loading,
|
||||
proposals,
|
||||
proposalsCurrentPage,
|
||||
proposalsTotal,
|
||||
company,
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user