Last active
July 30, 2021 01:29
-
-
Save touhidrahman/55a8a6241cd309afd8b95ca81f0b5b13 to your computer and use it in GitHub Desktop.
product.service.ts - supabase base service implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Injectable } from '@angular/core' | |
| import { BaseService } from '@core/services/base.service' | |
| import { SupabaseService } from '@core/services/supabase.service' | |
| import { Product } from '@features/products/types/product' | |
| const TABLE_PRODUCT = 'products' | |
| @Injectable({ | |
| providedIn: 'root', | |
| }) | |
| export class ProductService extends BaseService<Product> { | |
| constructor(protected supabaseService: SupabaseService) { | |
| super(supabaseService, TABLE_PRODUCT) | |
| } | |
| // a custom method | |
| findByCategory(categoryId: number, range = [0, 10]): Observable<Product[]> { | |
| const filters: FindFilter[] = [['category_id', 'eq', categoryId]] | |
| const select = '*,category:categories(*)' // select all columns from product, populate category | |
| const orderBy: FindOrder[] = ['published', false] | |
| const query = this.find(filters, select, range, orderBy) | |
| return this.returnList(query) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment