54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
import axios from '../plugins/axios'
|
|
import { defineStore } from 'pinia'
|
|
|
|
export const useProductsStore = defineStore('products', {
|
|
state: () => ({
|
|
items: [],
|
|
brands: [],
|
|
categories: [],
|
|
fetching: true,
|
|
total: 0
|
|
}),
|
|
actions: {
|
|
async index(page, pageSize) {
|
|
this.items = [];
|
|
|
|
this.fetching = true
|
|
|
|
const params = { page, pageSize }
|
|
|
|
const { status, data } = await axios.get('/course', { params })
|
|
|
|
this.fetching = false
|
|
|
|
this.items = data
|
|
|
|
|
|
},
|
|
|
|
async create(newCourse) {
|
|
const { status, data } = await axios.post('/course', newCourse)
|
|
|
|
return data
|
|
|
|
},
|
|
async update(course) {
|
|
const { status, data } = await axios.put('/course', course)
|
|
return data
|
|
|
|
},
|
|
async delete(id) {
|
|
const { status, data } = await axios.delete(`/course/${id}`, id)
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
async edit(id) {
|
|
const { status, data } = await axios.get(`/course/${id}`)
|
|
return data
|
|
|
|
},
|
|
|
|
}
|
|
}) |