This commit is contained in:
louiscklaw
2025-01-31 20:14:02 +08:00
parent 49e275d85d
commit 5c584709c4
706 changed files with 40207 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
import axios from 'axios';
import { API_PREF } from './common';
const CancelOrder = ({ custom_id }) => {
return axios
.post(`/api/order/cancel-order`, { custom_id })
.then(response => {
return response['data']['state'];
})
.catch(error => {
console.error(error);
});
};
export default CancelOrder;

View File

@@ -0,0 +1,10 @@
import axios from 'axios';
const CheckSession = ({ session }) => {
return axios
.get(`/api/auth/check_session`, { headers: { session } })
.then(res => res['data'])
.catch(err => console.error(err));
};
export default CheckSession;

View File

@@ -0,0 +1,15 @@
import axios from 'axios';
import { API_PREF } from './common';
const checkoutCart = items_to_checkout => {
return axios
.post(`/api/inventory/check_out`, items_to_checkout)
.then(response => {
return response;
})
.catch(error => {
console.error(error);
});
};
export default checkoutCart;

View File

@@ -0,0 +1,3 @@
const API_PREF = process.env.NEXT_PUBLIC_API_PREF;
export { API_PREF };

View File

@@ -0,0 +1,22 @@
import axios from 'axios';
import { API_PREF } from './common';
const fetchAllOrders = ({ session }) => {
console.log({ session });
return axios
.get(`/api/order/list`, { headers: { session } })
.then(function (response) {
let { data } = response;
let { orders } = data;
return orders;
})
.catch(function (error) {
// handle error
console.log(error);
});
};
export default fetchAllOrders;

View File

@@ -0,0 +1,21 @@
import axios from 'axios';
import { API_PREF } from './common';
const fetchCategories = () => {
return axios
.get(`/api/categories/list`)
.then(function (response) {
let { data } = response;
let { categories } = data;
return categories;
})
.catch(function (error) {
// handle error
console.log(error);
})
.finally(function () {
// always executed
});
};
export default fetchCategories;

View File

@@ -0,0 +1,10 @@
import axios from 'axios';
const fetchCategory = async ({ cid }) => {
return axios
.get(`/api/categories/view?cid=${cid}`)
.then(res => res)
.catch(err => console.error(err));
};
export default fetchCategory;

View File

@@ -0,0 +1,18 @@
import axios from 'axios';
import { API_PREF } from './common';
const fetchCustomerOrders = ({ session }) => {
return axios
.get(`/api/order/listByCustomer`, { headers: { session } })
.then(function (response) {
let { data } = response;
let { orders } = data;
return orders;
})
.catch(function (error) {
// handle error
console.log(error);
});
};
export default fetchCustomerOrders;

View File

@@ -0,0 +1,10 @@
import axios from 'axios';
const fetchListByCategory = ({ cid }) => {
return axios
.get(`/api/products/listByCategory?cid=${cid}`)
.then(res => res)
.catch(err => console.error(err));
};
export default fetchListByCategory;

View File

@@ -0,0 +1,16 @@
import axios from 'axios';
import { API_PREF } from './common';
const fetchListByCategoryUnsold = ({ cid }) => {
return axios
.get(`/api/products/listByCategoryUnsold?cid=${cid}`)
.then(res => {
let {
data: { products },
} = res;
return products;
})
.catch(err => console.error(err));
};
export default fetchListByCategoryUnsold;

View File

@@ -0,0 +1,13 @@
import axios from 'axios';
import { API_PREF } from './common';
const fetchProduct = ({ pid }) => {
return axios
.get(`/api/products/view?pid=${pid}`)
.then(res => {
return res;
})
.catch(err => console.error(err));
};
export default fetchProduct;

View File

@@ -0,0 +1,19 @@
import axios from 'axios';
import { API_PREF } from './common';
const fetchProducts = () => {
return axios
.get(`/api/products/list`)
.then(function (response) {
let { data } = response;
let { products } = data;
return products;
})
.catch(function (error) {
// handle error
console.log(error);
});
};
export default fetchProducts;

View File

@@ -0,0 +1,18 @@
import axios from 'axios';
import { API_PREF } from './common';
const GetOrderDetails = ({ cart, currency_code }) => {
let session_raw = localStorage.getItem('session');
let { session } = JSON.parse(session_raw);
return axios
.post(`/api/order/get-order-details`, { cart, currency_code }, { headers: { session } })
.then(response => {
return response['data'];
})
.catch(error => {
console.error(error);
});
};
export default GetOrderDetails;

View File

@@ -0,0 +1,16 @@
import axios from 'axios';
import { API_PREF } from './common';
import { csrf } from 'src/lib/csrf';
const SaveOrder = ({ custom_id }) => {
return axios
.post(`/api/order/save-order`, { custom_id })
.then(response => {
return response['data']['state'];
})
.catch(error => {
console.error(error);
});
};
export default SaveOrder;