@symanticreative/vendure-admin-client
Version:
A TypeScript GraphQL client for Vendure Admin API to create custom dashboards
71 lines • 2.04 kB
JavaScript
/**
* Base service implementation
* Implements common service methods using a repository
* Note: Abstract classes don't need @Injectable decorator
*/
export class BaseService {
constructor(repository) {
this.repository = repository;
}
/**
* Get entity by ID
* @param id - Entity identifier
* @returns Promise resolving to entity
*/
async getById(id) {
return this.repository.findById(id);
}
/**
* Get all entities with optional filtering
* @param filter - Optional filter criteria
* @returns Promise resolving to array of entities
*/
async getAll(filter) {
return this.repository.findAll(filter);
}
/**
* Create a new entity
* @param data - Entity data
* @returns Promise resolving to created entity
*/
async create(data) {
return this.repository.create(data);
}
/**
* Update an existing entity
* @param id - Entity identifier
* @param data - Updated entity data
* @returns Promise resolving to updated entity
*/
async update(id, data) {
return this.repository.update(id, data);
}
/**
* Delete an entity
* @param id - Entity identifier
* @returns Promise resolving to boolean indicating success
*/
async delete(id) {
return this.repository.delete(id);
}
}
/**
* Base paginated service implementation
* Extends base service with pagination capabilities
* Note: Abstract classes don't need @Injectable decorator
*/
export class BasePaginatedService extends BaseService {
constructor(paginatedRepository) {
super(paginatedRepository);
this.paginatedRepository = paginatedRepository;
}
/**
* Get entities with pagination
* @param options - Pagination options
* @returns Promise resolving to paginated result
*/
async getPaginated(options) {
return this.paginatedRepository.findWithPagination(options);
}
}
//# sourceMappingURL=base.service.js.map