feat(events): add storefront event API client
This commit is contained in:
@@ -14,7 +14,6 @@ describe('isStoreCatalogRequest', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
['POST', 'http://localhost:8000/api/tenants/demo/catalog-items'],
|
|
||||||
['GET', 'http://localhost:8000/api/tenants/demo/productos'],
|
['GET', 'http://localhost:8000/api/tenants/demo/productos'],
|
||||||
['GET', 'http://localhost:8000/api/tenants/demo/categories/7'],
|
['GET', 'http://localhost:8000/api/tenants/demo/categories/7'],
|
||||||
['GET', 'http://localhost:8000/api/tenants/demo/catalog-items/42/variant-options'],
|
['GET', 'http://localhost:8000/api/tenants/demo/catalog-items/42/variant-options'],
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import { TenantUrlSerializer } from './core/services/tenant-url.serializer';
|
|||||||
export function isStoreCatalogRequest(request: HttpRequest<unknown>): boolean {
|
export function isStoreCatalogRequest(request: HttpRequest<unknown>): boolean {
|
||||||
return (
|
return (
|
||||||
request.method === 'GET' &&
|
request.method === 'GET' &&
|
||||||
/\/api\/tenants\/[^/?#]+\/(?:catalog(?:\/featured-groups\/\d+\/items)?|catalog-items(?:\/\d+)?)\/?(?:[?#]|$)/.test(
|
/\/api\/tenants\/[^/?#]+\/(?:catalog(?:\/featured-groups\/\d+\/items)?|catalog-items(?:\/\d+)?|events(?:\/\d+)?)\/?(?:[?#]|$)/.test(
|
||||||
request.urlWithParams,
|
request.urlWithParams,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
14
src/app/core/services/event/event.interface.ts
Normal file
14
src/app/core/services/event/event.interface.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { ApiPaginatedResponse } from '../api-paginated-response.interface';
|
||||||
|
|
||||||
|
export interface StoreEvent {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
subtitle: string | null;
|
||||||
|
description: string | null;
|
||||||
|
location: string | null;
|
||||||
|
date_text: string | null;
|
||||||
|
attachment_id: number | null;
|
||||||
|
image: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type StoreEventPage = ApiPaginatedResponse<StoreEvent[]>;
|
||||||
24
src/app/core/services/event/event.service.ts
Normal file
24
src/app/core/services/event/event.service.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { inject, Injectable } from '@angular/core';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
|
import { BaseApiService } from '../base-api.service';
|
||||||
|
import { ApiResponse } from '../api-response.interface';
|
||||||
|
import { TenantService } from '../tenant.service';
|
||||||
|
import { StoreEvent, StoreEventPage } from './event.interface';
|
||||||
|
|
||||||
|
@Injectable({ providedIn: 'root' })
|
||||||
|
export class EventService extends BaseApiService {
|
||||||
|
private readonly tenantService = inject(TenantService);
|
||||||
|
|
||||||
|
list(page: number, query = ''): Observable<StoreEventPage> {
|
||||||
|
return this.http.get<StoreEventPage>(`${this.tenantService.getTenantApiUrl()}/events`, {
|
||||||
|
params: { page, ...(query ? { q: query } : {}) },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get(id: number): Observable<ApiResponse<StoreEvent>> {
|
||||||
|
return this.http.get<ApiResponse<StoreEvent>>(
|
||||||
|
`${this.tenantService.getTenantApiUrl()}/events/${id}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user