json-api-nestjs
Version:
JsonApi Plugin for NestJs
59 lines • 2.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MixinModule = void 0;
const helper_1 = require("./helper");
const constants_1 = require("../../constants");
const helper_2 = require("./helper");
const factory_1 = require("./factory");
const swagger_1 = require("./swagger");
const json_api_transformer_service_1 = require("./service/json-api-transformer.service");
class MixinModule {
static forRoot(options) {
const { entity, controller, imports, ormModule } = options;
const controllerClass = (0, helper_1.createController)(entity, controller);
const decoratorOptions = Reflect.getMetadata(constants_1.JSON_API_DECORATOR_OPTIONS, controllerClass) || {};
const moduleConfig = {
...options.config,
...decoratorOptions,
};
(0, helper_2.bindController)(controllerClass, entity, moduleConfig);
const optionProvider = {
provide: constants_1.CONTROL_OPTIONS_TOKEN,
useValue: moduleConfig,
};
const currentEntityProvider = {
provide: constants_1.CURRENT_ENTITY,
useValue: entity,
};
const findOneRowEntityProvider = {
provide: constants_1.FIND_ONE_ROW_ENTITY,
useValue: undefined,
};
const checkRelationNameProvider = {
provide: constants_1.CHECK_RELATION_NAME,
useValue: undefined,
};
return {
module: (0, helper_2.nameIt)((0, helper_2.getProviderName)(entity, constants_1.JSON_API_MODULE_POSTFIX), MixinModule),
controllers: [controllerClass],
providers: [
optionProvider,
currentEntityProvider,
findOneRowEntityProvider,
checkRelationNameProvider,
json_api_transformer_service_1.JsonApiTransformerService,
...ormModule.getUtilProviders(entity),
(0, factory_1.ZodInputQuerySchema)(entity),
(0, factory_1.ZodQuerySchema)(entity),
(0, factory_1.ZodPatchSchema)(entity),
(0, factory_1.ZodPostSchema)(entity),
swagger_1.SwaggerBindService,
factory_1.ZodInputPatchRelationshipSchema,
factory_1.ZodInputPostRelationshipSchema,
],
imports: imports,
};
}
}
exports.MixinModule = MixinModule;
//# sourceMappingURL=mixin.module.js.map