dependencies Legend  Declarations  Module  Bootstrap  Providers  Exports cluster_ProposalsModule cluster_ProposalsModule_imports cluster_ProposalsModule_exports cluster_ProposalsModule_providers AttachmentsModule AttachmentsModule ProposalsModule ProposalsModule AttachmentsModule->ProposalsModule ProposalsService ProposalsService ProposalsModule->ProposalsService CaslAbilityFactory CaslAbilityFactory CaslAbilityFactory->ProposalsModule ProposalsService ProposalsService ProposalsService->ProposalsModule

File

src/proposals/proposals.module.ts

import { forwardRef, Module } from "@nestjs/common";
import { ProposalsService } from "./proposals.service";
import { ProposalsController } from "./proposals.controller";
import { MongooseModule } from "@nestjs/mongoose";
import { ProposalClass, ProposalSchema } from "./schemas/proposal.schema";
import { CaslAbilityFactory } from "src/casl/casl-ability.factory";
import { AttachmentsModule } from "src/attachments/attachments.module";
import { DatasetsModule } from "src/datasets/datasets.module";

@Module({
  imports: [
    AttachmentsModule,
    forwardRef(() => DatasetsModule),
    MongooseModule.forFeatureAsync([
      {
        name: ProposalClass.name,
        useFactory: () => {
          const schema = ProposalSchema;

          schema.pre<ProposalClass>("save", function (next) {
            // if _id is empty or different than proposalId,
            // set _id to proposalId
            if (!this._id) {
              this._id = this.proposalId;
            }
            next();
          });
          return schema;
        },
      },
    ]),
  ],
  exports: [ProposalsService],
  controllers: [ProposalsController],
  providers: [ProposalsService, CaslAbilityFactory],
})
export class ProposalsModule {}

results matching ""

    No results matching ""