add: view users of company
This commit is contained in:
@@ -52,15 +52,16 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
});
|
||||
|
||||
const logout = () => {
|
||||
|
||||
localStorage.removeItem('session');
|
||||
localStorage.removeItem('access');
|
||||
localStorage.removeItem('id');
|
||||
company.clear();
|
||||
router.push({name: 'login'});
|
||||
console.log('logoo....');
|
||||
sesion.value = '';
|
||||
token.value = '';
|
||||
company.clear();
|
||||
user.value = null;
|
||||
console.log(company.company);
|
||||
localStorage.removeItem('access');
|
||||
localStorage.removeItem('id');
|
||||
localStorage.removeItem('session');
|
||||
router.push({name: 'login'});
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,27 +1,41 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
import { getBudgets, getCompany, updateBudget, updateCompany, deleteBudget, createBudget } from "../services/company";
|
||||
import { getBudgets, getCompany, updateBudget, updateCompany, deleteBudget, createBudget, getUsers } from "../services/company";
|
||||
import api from "../lib/axios";
|
||||
|
||||
export const useCompanyStore = defineStore('company', () => {
|
||||
|
||||
const companyid = localStorage.getItem('id');
|
||||
const company = ref(null)
|
||||
const users = ref([]);
|
||||
const budgets = ref([]);
|
||||
const proposals = ref([])
|
||||
const loading = ref(false);
|
||||
|
||||
const getCompanyData = async() => {
|
||||
const companyId = localStorage.getItem('id');
|
||||
loading.value = true;
|
||||
if(!company.value) {
|
||||
loading.value = true;
|
||||
const resp = await getCompany(companyid);
|
||||
const resp = await getCompany(companyId);
|
||||
console.log(resp);
|
||||
company.value = resp;
|
||||
}
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
const getUsersCompany = async() => {
|
||||
const companyId = localStorage.getItem('id');
|
||||
if(users.value.length <= 0) {
|
||||
const resp = await getUsers(companyId);
|
||||
console.log(resp);
|
||||
if(resp !== null && resp.total > 0) {
|
||||
users.value = resp.data;
|
||||
} else {
|
||||
users.value = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const editCompany = async(formData) => {
|
||||
const data = await updateCompany(company.value._id, formData);
|
||||
if(data === null) {
|
||||
@@ -32,14 +46,19 @@ export const useCompanyStore = defineStore('company', () => {
|
||||
...formData,
|
||||
};
|
||||
|
||||
console.log(company.value);
|
||||
return 'success';
|
||||
}
|
||||
}
|
||||
|
||||
const clear = () => {
|
||||
company.value = null;
|
||||
companyid = null;
|
||||
// companyid = null;
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
const $reset = () => {
|
||||
company.value = null;
|
||||
// companyid = null;
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
@@ -47,8 +66,9 @@ 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 companyId = localStorage.getItem('id');
|
||||
try {
|
||||
const endpoint = `/proposals?carrier=${companyid}`;
|
||||
const endpoint = `/proposals?carrier=${companyId}`;
|
||||
const {data} = await api.get(endpoint);
|
||||
proposals.value = data.data;
|
||||
console.log(data);
|
||||
@@ -137,12 +157,15 @@ export const useCompanyStore = defineStore('company', () => {
|
||||
getCompanyData,
|
||||
getProposalsCompany,
|
||||
getBudgetsCompany,
|
||||
getUsersCompany,
|
||||
editCompany,
|
||||
updateBudgetCompany,
|
||||
createBudgetCompany,
|
||||
deleteBudgetCompany,
|
||||
budgets,
|
||||
users,
|
||||
clear,
|
||||
$reset,
|
||||
loading,
|
||||
proposals,
|
||||
company,
|
||||
|
||||
Reference in New Issue
Block a user