dependencies Legend  Declarations  Module  Bootstrap  Providers  Exports cluster_AttachmentsModule cluster_AttachmentsModule_providers cluster_AttachmentsModule_exports AttachmentsService AttachmentsService AttachmentsModule AttachmentsModule AttachmentsModule->AttachmentsService AttachmentsService AttachmentsService AttachmentsService->AttachmentsModule

File

src/attachments/attachments.module.ts

import { Module } from "@nestjs/common";
import { MongooseModule } from "@nestjs/mongoose";
import { AttachmentsService } from "./attachments.service";
import { Attachment, AttachmentSchema } from "./schemas/attachment.schema";

@Module({
  imports: [
    MongooseModule.forFeatureAsync([
      {
        name: Attachment.name,
        //schema: AttachmentSchema,

        useFactory: () => {
          const schema = AttachmentSchema;

          schema.pre<Attachment>("save", function (next) {
            // if _id is empty or differnet than pid,
            // set _id to pid
            if (!this._id) {
              this._id = this.id;
            }
            next();
          });

          return schema;
        },
      },
    ]),
  ],
  providers: [AttachmentsService],
  exports: [AttachmentsService],
})
export class AttachmentsModule {}

results matching ""

    No results matching ""