UNPKG

pocketbase-tools

Version:

A TypeScript toolkit for PocketBase, featuring a standard service/action/types layered structure. It provides interfaces and implementations for common business logic such as users, products, company profiles, and file utilities, making it suitable for se

57 lines (56 loc) 1.51 kB
import { ErrorHandler } from "../utils/errorHandler"; export class BaseService { constructor(client, collection) { this.client = client; this.collection = collection; this.errorHandler = new ErrorHandler(); } async getById(id) { try { return await this.client.collection(this.collection).getOne(id); } catch (error) { this.errorHandler.handle(error); throw error; } } async getList(page = 1, perPage = 50) { try { return await this.client .collection(this.collection) .getList(page, perPage); } catch (error) { this.errorHandler.handle(error); throw error; } } async create(data) { try { return await this.client.collection(this.collection).create(data); } catch (error) { this.errorHandler.handle(error); throw error; } } async update(id, data) { try { return await this.client.collection(this.collection).update(id, data); } catch (error) { this.errorHandler.handle(error); throw error; } } async delete(id) { try { await this.client.collection(this.collection).delete(id); return true; } catch (error) { this.errorHandler.handle(error); throw error; } } }