UNPKG

@on-time/core

Version:

core business logic for OT API

59 lines (52 loc) 1.29 kB
class Service{ constructor(repository){ this.repository = repository; this.create = this.create.bind(this); this.getAll = this.getAll.bind(this); this.getById = this.getById.bind(this); this.update = this.update.bind(this); this.delete = this.delete.bind(this); } /** * Create a new instance * @param data * @returns {Promise<data>} */ async create(data){ return this.repository.create(data); } /** * Get all instances matching query * @param query * @returns {Promise<*|string[]|{body, status}|IDBRequest<any[]>|FormDataEntryValue[]>} */ async getAll(query){ return this.repository.getAll(query); } /** * Get an instance by ID * @param id * @returns {Promise<*|void>} */ async getById(id){ return this.repository.getById(id); } /** * Update an instance * @param id * @param data * @returns {Promise<*>} */ async update(id, data){ return this.repository.update(id, data); } /** * Delete an instance * @param id * @returns {Promise<*>} */ async delete(id){ return this.repository.delete(id); } } module.exports = Service;