@elsikora/nestjs-crud-automator
Version:
A library for automating the creation of CRUD operations in NestJS.
50 lines (47 loc) • 1.81 kB
JavaScript
import { ApiFunctionContextStorage } from './function/context-storage.class.js';
import { ErrorException } from '../../utility/error/exception.utility.js';
/**
* Base class for services providing CRUD operations.
* @see {@link https://elsikora.com/docs/nestjs-crud-automator/api-reference/classes#apiservicebase | API Reference - ApiServiceBase}
* @see {@link https://elsikora.com/docs/nestjs-crud-automator/core-concepts/services | Core Concepts - Services}
*/
class ApiServiceBase {
create(properties) {
return Promise.resolve({});
}
delete(criteria) {
return Promise.resolve();
}
// eslint-disable-next-line @elsikora/sonar/no-identical-functions
get(properties) {
return Promise.resolve({});
}
getList(properties) {
return Promise.resolve({ items: [], total: 0 });
}
getMany(properties) {
return Promise.resolve([]);
}
update(criteria, properties) {
return Promise.resolve({});
}
getApiFunctionContext() {
const context = ApiFunctionContextStorage.get();
if (!context && ApiFunctionContextStorage.getStep()) {
throw ErrorException("Api function context is not available inside a decorated ApiFunctionStep execution");
}
if (!context) {
throw ErrorException("Api function context is not available outside a decorated ApiFunction execution");
}
return context;
}
getApiFunctionStepContext() {
const context = ApiFunctionContextStorage.getStep();
if (!context) {
throw ErrorException("Api function step context is not available outside a decorated ApiFunctionStep execution");
}
return context;
}
}
export { ApiServiceBase };
//# sourceMappingURL=service-base.class.js.map