summaryrefslogtreecommitdiff
path: root/src-migrate/services
diff options
context:
space:
mode:
authortrisusilo48 <tri.susilo@altama.co.id>2024-07-10 15:58:51 +0700
committertrisusilo48 <tri.susilo@altama.co.id>2024-07-10 15:58:51 +0700
commit2e3c726bc8217f3960cfecec44b81303b03de72b (patch)
tree1b85ced7f61f3e4c3f1f27b577b37aa161615065 /src-migrate/services
parent2b3bd9c0a454dbad69ce29cee877bfb1fca5dfa6 (diff)
parenta99bf6480eea556e53b85e6db45f3b8c2361e693 (diff)
Merge branch 'release' into development
# Conflicts: # src/pages/shop/product/variant/[slug].jsx
Diffstat (limited to 'src-migrate/services')
-rw-r--r--src-migrate/services/auth.ts28
-rw-r--r--src-migrate/services/banner.ts11
-rw-r--r--src-migrate/services/cart.ts41
-rw-r--r--src-migrate/services/checkout.ts5
-rw-r--r--src-migrate/services/pageContent.ts13
-rw-r--r--src-migrate/services/product.ts66
-rw-r--r--src-migrate/services/productVariant.ts23
-rw-r--r--src-migrate/services/promotionProgram.ts8
-rw-r--r--src-migrate/services/wishlist.ts23
9 files changed, 186 insertions, 32 deletions
diff --git a/src-migrate/services/auth.ts b/src-migrate/services/auth.ts
index a5d02754..35ba290a 100644
--- a/src-migrate/services/auth.ts
+++ b/src-migrate/services/auth.ts
@@ -1,4 +1,4 @@
-import odooApi from '~/common/libs/odooApi';
+import odooApi from '~/libs/odooApi';
import {
RegisterResApiProps,
RegisterProps,
@@ -8,46 +8,30 @@ import {
ActivationOtpResApiProps,
ActivationReqProps,
ActivationReqResApiProps,
-} from '~/common/types/auth';
+} from '~/types/auth';
const BASE_PATH = '/api/v1/user';
export const registerUser = async (
data: RegisterProps
): Promise<RegisterResApiProps> => {
- const response = await odooApi('POST', `${BASE_PATH}/register`, data);
-
- return response;
+ return await odooApi('POST', `${BASE_PATH}/register`, data);
};
export const activationUserToken = async (
params: ActivationTokenProps
): Promise<ActivationTokenResApiProps> => {
- const response = await odooApi(
- 'POST',
- `${BASE_PATH}/activation-token`,
- params
- );
-
- return response;
+ return await odooApi('POST', `${BASE_PATH}/activation-token`, params);
};
export const activationUserOTP = async (
params: ActivationOtpProps
): Promise<ActivationOtpResApiProps> => {
- const response = await odooApi('POST', `${BASE_PATH}/activation-otp`, params);
-
- return response;
+ return await odooApi('POST', `${BASE_PATH}/activation-otp`, params);
};
export const activationReq = async (
params: ActivationReqProps
): Promise<ActivationReqResApiProps> => {
- const response = await odooApi(
- 'POST',
- `${BASE_PATH}/activation-request`,
- params
- );
-
- return response;
+ return await odooApi('POST', `${BASE_PATH}/activation-request`, params);
};
diff --git a/src-migrate/services/banner.ts b/src-migrate/services/banner.ts
index e69de29b..1b46ba06 100644
--- a/src-migrate/services/banner.ts
+++ b/src-migrate/services/banner.ts
@@ -0,0 +1,11 @@
+import odooApi from '~/libs/odooApi';
+import { IBanner } from '~/types/banner';
+
+export const getBanner = async ({
+ type,
+}: {
+ type: string;
+}): Promise<IBanner[]> => {
+ const searchParams = new URLSearchParams({ type });
+ return await odooApi('GET', `/api/v1/banner?${searchParams.toString()}`);
+};
diff --git a/src-migrate/services/cart.ts b/src-migrate/services/cart.ts
new file mode 100644
index 00000000..11f87125
--- /dev/null
+++ b/src-migrate/services/cart.ts
@@ -0,0 +1,41 @@
+import odooApi from '~/libs/odooApi';
+
+export const getUserCart = async (userId: number) => {
+ return await odooApi('GET', `/api/v1/user/${userId}/cart`);
+};
+
+interface UpsertUserCartProps {
+ userId: number;
+ type: 'product' | 'promotion';
+ id: number;
+ qty: number;
+ selected: boolean;
+ source?: 'buy' | 'add_to_cart';
+ qtyAppend?: boolean;
+}
+
+export const upsertUserCart = async ({
+ userId,
+ type,
+ id,
+ qty,
+ selected,
+ source = 'add_to_cart',
+ qtyAppend = false,
+}: UpsertUserCartProps) => {
+ return await odooApi('POST', `/api/v1/user/${userId}/cart/create-or-update`, {
+ product_id: type === 'product' ? id : null,
+ qty,
+ selected,
+ program_line_id: type === 'promotion' ? id : null,
+ source,
+ qty_append: qtyAppend,
+ });
+};
+
+export const deleteUserCart = async (userId: number, ids: number[]) => {
+ return await odooApi(
+ 'DELETE',
+ `/api/v1/user/${userId}/cart?ids=${ids.join(',')}`
+ );
+};
diff --git a/src-migrate/services/checkout.ts b/src-migrate/services/checkout.ts
new file mode 100644
index 00000000..e6642ccb
--- /dev/null
+++ b/src-migrate/services/checkout.ts
@@ -0,0 +1,5 @@
+import odooApi from '~/libs/odooApi';
+
+export const getUserCheckout = async (userId: number) => {
+ return await odooApi('GET', `/api/v1/user/${userId}/sale_order/checkout`);
+}; \ No newline at end of file
diff --git a/src-migrate/services/pageContent.ts b/src-migrate/services/pageContent.ts
index 24f2c2f0..516b4bed 100644
--- a/src-migrate/services/pageContent.ts
+++ b/src-migrate/services/pageContent.ts
@@ -1,14 +1,7 @@
-import odooApi from '~/common/libs/odooApi';
+import odooApi from '~/libs/odooApi';
export const getPageContent = async ({ path }: { path: string }) => {
- const params = new URLSearchParams({
- url_path: path,
- });
+ const params = new URLSearchParams({ url_path: path });
- const pageContent = await odooApi(
- 'GET',
- `/api/v1/page-content?${params.toString()}`
- );
-
- return pageContent;
+ return await odooApi('GET', `/api/v1/page-content?${params.toString()}`);
};
diff --git a/src-migrate/services/product.ts b/src-migrate/services/product.ts
new file mode 100644
index 00000000..fe415d11
--- /dev/null
+++ b/src-migrate/services/product.ts
@@ -0,0 +1,66 @@
+import { IProduct, IProductDetail } from '~/types/product';
+import snakeCase from 'snakecase-keys';
+import odooApi from '~/libs/odooApi';
+import { ICategoryBreadcrumb } from '~/types/category';
+
+const SELF_HOST = process.env.NEXT_PUBLIC_SELF_HOST;
+
+export const getProductById = async (
+ id: string,
+ tier: string
+): Promise<IProductDetail | null> => {
+ const url = `${SELF_HOST}/api/shop/product-detail`;
+ const params = new URLSearchParams({ id, auth: tier });
+ return await fetch(`${url}?${params.toString()}`)
+ .then((res) => res.json())
+ .then((res) => {
+ if (res.length > 0) return snakeCase(res[0]) as IProductDetail;
+ return null;
+ });
+};
+
+export interface GetProductSimilarProps {
+ name: string;
+ except?: {
+ productId?: number;
+ manufactureId?: number;
+ };
+ limit?: number;
+}
+
+export interface GetProductSimilarRes {
+ products: IProduct[];
+ num_found: number;
+ num_found_exact: boolean;
+ start: number;
+}
+
+export const getProductSimilar = async ({
+ name,
+ except,
+ limit = 30,
+}: GetProductSimilarProps): Promise<GetProductSimilarRes> => {
+ const query = [
+ `q=${name}`,
+ 'page=1',
+ 'orderBy=popular-weekly',
+ 'operation=OR',
+ 'priceFrom=1',
+ ];
+
+ if (except?.productId) query.push(`fq=-product_id_i:${except.productId}`);
+ if (except?.manufactureId)
+ query.push(`fq=-manufacture_id_i:${except.manufactureId}`);
+
+ const url = `${SELF_HOST}/api/shop/search?${query.join('&')}`;
+
+ return await fetch(url)
+ .then((res) => res.json())
+ .then((res) => snakeCase(res.response));
+};
+
+export const getProductCategoryBreadcrumb = async (
+ id: number
+): Promise<ICategoryBreadcrumb[]> => {
+ return await odooApi('GET', `/api/v1/product/${id}/category-breadcrumb`);
+};
diff --git a/src-migrate/services/productVariant.ts b/src-migrate/services/productVariant.ts
new file mode 100644
index 00000000..9fec4d1f
--- /dev/null
+++ b/src-migrate/services/productVariant.ts
@@ -0,0 +1,23 @@
+import odooApi from '~/libs/odooApi';
+import { IProductVariantSLA } from '~/types/productVariant';
+import { CategoryPromo, IPromotion } from '~/types/promotion';
+
+export const getVariantById = async (variantId: number) => {
+ const url = `/api/product-variant/${variantId}`;
+ return await fetch(url).then((res) => res.json());
+};
+
+export const getVariantPromoByCategory = async (
+ variantId: number,
+ type: CategoryPromo
+): Promise<{ data: IPromotion[] }> => {
+ const url = `/api/product-variant/${variantId}/promotion/${type}`;
+ return await fetch(url).then((res) => res.json());
+};
+
+export const getVariantSLA = async (
+ variantId: number
+): Promise<IProductVariantSLA> => {
+ const url = `/api/v1/product_variant/${variantId}/stock`;
+ return await odooApi('GET', url);
+};
diff --git a/src-migrate/services/promotionProgram.ts b/src-migrate/services/promotionProgram.ts
new file mode 100644
index 00000000..c8c46c65
--- /dev/null
+++ b/src-migrate/services/promotionProgram.ts
@@ -0,0 +1,8 @@
+import { IPromotionProgram } from '~/types/promotionProgram';
+
+export const getPromotionProgram = async (
+ programId: number
+): Promise<{ data: IPromotionProgram }> => {
+ const url = `/api/promotion-program/${programId}`;
+ return await fetch(url).then((res) => res.json());
+};
diff --git a/src-migrate/services/wishlist.ts b/src-migrate/services/wishlist.ts
new file mode 100644
index 00000000..6fb8cb2e
--- /dev/null
+++ b/src-migrate/services/wishlist.ts
@@ -0,0 +1,23 @@
+import odooApi from '~/libs/odooApi';
+
+export const getUserWishlist = async (
+ userId: number,
+ searchParams: {
+ product_id?: string;
+ } = {}
+): Promise<{ product_total: number }> => {
+ const url = `/api/v1/user/${userId}/wishlist`;
+ const searchParamsObj = new URLSearchParams(searchParams);
+
+ return await odooApi('GET', url + '?' + searchParamsObj.toString());
+};
+
+export const upsertUserWishlist = async (
+ userId: number,
+ productId: number
+): Promise<{ id: number }> => {
+ const url = `/api/v1/user/${userId}/wishlist/create-or-delete`;
+ const data = { product_id: productId };
+
+ return await odooApi('POST', url, data);
+};