Skip to content

Instantly share code, notes, and snippets.

@touhidrahman
Last active July 30, 2021 01:29
Show Gist options
  • Select an option

  • Save touhidrahman/55a8a6241cd309afd8b95ca81f0b5b13 to your computer and use it in GitHub Desktop.

Select an option

Save touhidrahman/55a8a6241cd309afd8b95ca81f0b5b13 to your computer and use it in GitHub Desktop.
product.service.ts - supabase base service implementation
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