File

apps/recallassess/recallassess-api/src/api/admin/company/config/company-config.service.ts

Extends

ModuleConfigBase

Index

Methods

Methods

getConfiguration
getConfiguration()
Returns : ModuleConfig
import { ColumnConfig, ColumnType } from "@bish-nest/core/app-config/column-config.class";
import { ModuleConfig } from "@bish-nest/core/app-config/module-config.class";
import { ModuleConfigBase } from "@bish-nest/core/app-config/module-config-base.class";
import { Injectable } from "@nestjs/common";
import { SubscriptionPlan } from "@prisma/client";
import { CompanyAddDto } from "../dto/company-add.dto";
import { CompanyDetailDto } from "../dto/company-detail.dto";
import { CompanyListDto } from "../dto/company-list.dto";
import { CompanySaveDto } from "../dto/company-save.dto";

@Injectable()
export class CompanyConfig extends ModuleConfigBase {
  getConfiguration(): ModuleConfig {
    const columns: ColumnConfig[] = [
      new ColumnConfig({ name: "id", type: ColumnType.Integer }),
      new ColumnConfig({ name: "name" }),
      new ColumnConfig({ name: "email" }),
      new ColumnConfig({ name: "phone" }),
      new ColumnConfig({ name: "country" }),
      new ColumnConfig({ name: "preferred_timezone" }),
      new ColumnConfig({
        name: "plan",
        isEnumType: true,
        enumValues: Object.values(SubscriptionPlan),
      }),
      new ColumnConfig({ name: "stripe_customer_id" }),
      new ColumnConfig({ name: "stripe_subscription_id" }),
      new ColumnConfig({ name: "trial_start_date", type: ColumnType.DateTime }),
      new ColumnConfig({ name: "trial_end_date", type: ColumnType.DateTime }),
      new ColumnConfig({ name: "is_active", type: ColumnType.Boolean }),
      new ColumnConfig({ name: "is_subscription_expiry", type: ColumnType.Boolean }),
      new ColumnConfig({ name: "created_at", type: ColumnType.DateTime }),
      new ColumnConfig({ name: "updated_at", type: ColumnType.DateTime }),
    ];

    return new ModuleConfig({
      name: "company",
      columns,
      keywordSearchCols: [
        "id",
        "name",
        "email",
        "phone",
        "country",
        "preferred_timezone",
        "plan",
        "stripe_customer_id",
        "stripe_subscription_id",
        "trial_start_date",
        "trial_end_date",
        "is_active",
        "is_subscription_expiry",
        "created_at",
        "updated_at",
      ],

      // Show next_billing_date even after cron expiry (is_current becomes false on that row).
      relationObjToIncludeForList: {
        subscriptions: {
          where: { is_current: true },
          orderBy: { id: "desc" },
          take: 1,
          select: {
            next_billing_date: true,
            stripe_cancel_at_period_end: true,
            package: { select: { name: true } },
          },
        },
      },

      relationObjToIncludeForDetail: {
        userCreatedBy: true,
        userUpdatedBy: true,
        subscriptions: {
          where: { is_current: true },
          orderBy: { id: "desc" },
          take: 1,
          select: {
            next_billing_date: true,
            stripe_cancel_at_period_end: true,
            package: { select: { name: true } },
          },
        },
      },

      listDto: CompanyListDto,
      // Company list in admin often requests with `vl=1`; without a simpleDto the derived fields
      // (e.g. stripe_cancel_at_period_end/current_plan) can be missing in that path.
      // Reuse list DTO so list/value-list payloads stay consistent for Auto-renew rendering.
      simpleDto: CompanyListDto,
      detailDto: CompanyDetailDto,
      addDto: CompanyAddDto,
      saveDto: CompanySaveDto,
    });
  }
}

results matching ""

    No results matching ""