feat: initialize master data module with new entity definitions, cohort module, and SQL seeding script

This commit is contained in:
azeeee05
2026-08-10 17:17:06 +05:30
parent e920c9e3b5
commit 5f95a5c341
12 changed files with 380 additions and 2 deletions
+83 -2
View File
@@ -261,7 +261,14 @@ SELECT code, name, "tableName", description, "displayOrder", true FROM (VALUES
('revenue-segment', 'Revenue Segment', 'tbl_revenue_segments', 'Revenue Segment master', 31),
('jurisdiction', 'Jurisdiction', 'tbl_jurisdictions', 'Jurisdiction master', 32),
('operator', 'Operator', 'tbl_operators', 'Operator master', 33),
('amount-type', 'Amount Type', 'tbl_amount_types', 'Amount Type master', 34)
('amount-type', 'Amount Type', 'tbl_amount_types', 'Amount Type master', 34),
('baggage-type', 'Baggage Type', 'tbl_baggage_types', 'Baggage Type master', 35),
('compensation-rule', 'Compensation Rule', 'tbl_compensation_rules', 'Compensation Rule master', 36),
('approval-level', 'Approval Level', 'tbl_approval_levels', 'Approval Level master', 37),
('eligible-fare-type', 'Eligible Fare Type', 'tbl_eligible_fare_types', 'Eligible Fare Type master', 38),
('applicable-product', 'Applicable Product', 'tbl_applicable_products', 'Applicable Product master', 39),
('meal-type', 'Meal Type', 'tbl_meal_types', 'Meal Type master', 40),
('airport-restriction', 'Airport Restriction', 'tbl_airport_restrictions', 'Airport Restriction master', 41)
) AS t(code, name, "tableName", description, "displayOrder")
WHERE NOT EXISTS (SELECT 1 FROM masters.tbl_rules_categories WHERE masters.tbl_rules_categories.code = t.code);
@@ -302,7 +309,14 @@ FROM (VALUES
('revenue-segment', 'tbl_revenue_segments'),
('jurisdiction', 'tbl_jurisdictions'),
('operator', 'tbl_operators'),
('amount-type', 'tbl_amount_types')
('amount-type', 'tbl_amount_types'),
('baggage-type', 'tbl_baggage_types'),
('compensation-rule', 'tbl_compensation_rules'),
('approval-level', 'tbl_approval_levels'),
('eligible-fare-type', 'tbl_eligible_fare_types'),
('applicable-product', 'tbl_applicable_products'),
('meal-type', 'tbl_meal_types'),
('airport-restriction', 'tbl_airport_restrictions')
) AS v(code, "tableName")
WHERE c.code = v.code AND (c."tableName" IS NULL OR c."tableName" != v."tableName");
@@ -631,5 +645,72 @@ SELECT label, value, true FROM (VALUES
) AS t(label, value)
WHERE NOT EXISTS (SELECT 1 FROM masters.tbl_amount_types WHERE masters.tbl_amount_types.value = t.value);
-- 38. Baggage Types
INSERT INTO masters.tbl_baggage_types (label, value, "isActive")
SELECT label, value, true FROM (VALUES
('Checked Bag', 'checked-bag'),
('Cabin Bag', 'cabin-bag'),
('Oversized Baggage', 'oversized-baggage'),
('Sports Equipment', 'sports-equipment'),
('Special Baggage', 'special-baggage')
) AS t(label, value)
WHERE NOT EXISTS (SELECT 1 FROM masters.tbl_baggage_types WHERE masters.tbl_baggage_types.value = t.value);
-- 39. Compensation Rules
INSERT INTO masters.tbl_compensation_rules (label, value, "isActive")
SELECT label, value, true FROM (VALUES
('EU261', 'eu261'),
('UK261', 'uk261'),
('APPR', 'appr'),
('DGCA', 'dgca'),
('DOT', 'dot'),
('Airline Policy', 'airline-policy')
) AS t(label, value)
WHERE NOT EXISTS (SELECT 1 FROM masters.tbl_compensation_rules WHERE masters.tbl_compensation_rules.value = t.value);
-- 40. Approval Levels
INSERT INTO masters.tbl_approval_levels (label, value, "isActive")
SELECT label, value, true FROM (VALUES
('Supervisor', 'supervisor'),
('Manager', 'manager'),
('Director', 'director')
) AS t(label, value)
WHERE NOT EXISTS (SELECT 1 FROM masters.tbl_approval_levels WHERE masters.tbl_approval_levels.value = t.value);
-- 41. Eligible Fare Types
INSERT INTO masters.tbl_eligible_fare_types (label, value, "isActive")
SELECT label, value, true FROM (VALUES
('Published Fares', 'published-fares'),
('Promo Fares', 'promo-fares')
) AS t(label, value)
WHERE NOT EXISTS (SELECT 1 FROM masters.tbl_eligible_fare_types WHERE masters.tbl_eligible_fare_types.value = t.value);
-- 42. Applicable Products
INSERT INTO masters.tbl_applicable_products (label, value, "isActive")
SELECT label, value, true FROM (VALUES
('Flights', 'flights'),
('Ancillary', 'ancillary'),
('Lounge', 'lounge')
) AS t(label, value)
WHERE NOT EXISTS (SELECT 1 FROM masters.tbl_applicable_products WHERE masters.tbl_applicable_products.value = t.value);
-- 43. Meal Types
INSERT INTO masters.tbl_meal_types (label, value, "isActive")
SELECT label, value, true FROM (VALUES
('Breakfast', 'breakfast'),
('Lunch', 'lunch'),
('Dinner', 'dinner'),
('Snack', 'snack'),
('Any', 'any')
) AS t(label, value)
WHERE NOT EXISTS (SELECT 1 FROM masters.tbl_meal_types WHERE masters.tbl_meal_types.value = t.value);
-- 44. Airport Restrictions
INSERT INTO masters.tbl_airport_restrictions (label, value, "isActive")
SELECT label, value, true FROM (VALUES
('Departure', 'departure'),
('Transit', 'transit'),
('Arrival', 'arrival'),
('Any Airport', 'any-airport')
) AS t(label, value)
WHERE NOT EXISTS (SELECT 1 FROM masters.tbl_airport_restrictions WHERE masters.tbl_airport_restrictions.value = t.value);
+1
View File
@@ -1,3 +1,4 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { CohortController } from './cohort.controller';
@@ -0,0 +1,28 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm';
@Entity({ name: 'tbl_airport_restrictions', schema: 'masters' })
export class AirportRestriction {
@PrimaryGeneratedColumn('uuid')
id!: string;
@Column()
label!: string;
@Column()
value!: string;
@Column({ default: true })
isActive!: boolean;
@CreateDateColumn()
createdAt!: Date;
@UpdateDateColumn()
updatedAt!: Date;
}
@@ -0,0 +1,28 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm';
@Entity({ name: 'tbl_applicable_products', schema: 'masters' })
export class ApplicableProduct {
@PrimaryGeneratedColumn('uuid')
id!: string;
@Column()
label!: string;
@Column()
value!: string;
@Column({ default: true })
isActive!: boolean;
@CreateDateColumn()
createdAt!: Date;
@UpdateDateColumn()
updatedAt!: Date;
}
@@ -0,0 +1,28 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm';
@Entity({ name: 'tbl_approval_levels', schema: 'masters' })
export class ApprovalLevel {
@PrimaryGeneratedColumn('uuid')
id!: string;
@Column()
label!: string;
@Column()
value!: string;
@Column({ default: true })
isActive!: boolean;
@CreateDateColumn()
createdAt!: Date;
@UpdateDateColumn()
updatedAt!: Date;
}
@@ -0,0 +1,28 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm';
@Entity({ name: 'tbl_baggage_types', schema: 'masters' })
export class BaggageType {
@PrimaryGeneratedColumn('uuid')
id!: string;
@Column()
label!: string;
@Column()
value!: string;
@Column({ default: true })
isActive!: boolean;
@CreateDateColumn()
createdAt!: Date;
@UpdateDateColumn()
updatedAt!: Date;
}
@@ -0,0 +1,28 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm';
@Entity({ name: 'tbl_compensation_rules', schema: 'masters' })
export class CompensationRule {
@PrimaryGeneratedColumn('uuid')
id!: string;
@Column()
label!: string;
@Column()
value!: string;
@Column({ default: true })
isActive!: boolean;
@CreateDateColumn()
createdAt!: Date;
@UpdateDateColumn()
updatedAt!: Date;
}
@@ -0,0 +1,28 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm';
@Entity({ name: 'tbl_destination_types', schema: 'masters' })
export class DestinationType {
@PrimaryGeneratedColumn('uuid')
id!: string;
@Column()
label!: string;
@Column()
value!: string;
@Column({ default: true })
isActive!: boolean;
@CreateDateColumn()
createdAt!: Date;
@UpdateDateColumn()
updatedAt!: Date;
}
@@ -0,0 +1,28 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm';
@Entity({ name: 'tbl_eligible_fare_types', schema: 'masters' })
export class EligibleFareType {
@PrimaryGeneratedColumn('uuid')
id!: string;
@Column()
label!: string;
@Column()
value!: string;
@Column({ default: true })
isActive!: boolean;
@CreateDateColumn()
createdAt!: Date;
@UpdateDateColumn()
updatedAt!: Date;
}
@@ -0,0 +1,28 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm';
@Entity({ name: 'tbl_meal_types', schema: 'masters' })
export class MealType {
@PrimaryGeneratedColumn('uuid')
id!: string;
@Column()
label!: string;
@Column()
value!: string;
@Column({ default: true })
isActive!: boolean;
@CreateDateColumn()
createdAt!: Date;
@UpdateDateColumn()
updatedAt!: Date;
}
@@ -44,6 +44,14 @@ import { RefundBasis } from './entities/refund-basis.entity';
import { Currency } from './entities/currency.entity';
import { RefundMethod } from './entities/refund-method.entity';
import { AmountType } from './entities/amount-type.entity';
import { BaggageType } from './entities/baggage-type.entity';
import { CompensationRule } from './entities/compensation-rule.entity';
import { ApprovalLevel } from './entities/approval-level.entity';
import { EligibleFareType } from './entities/eligible-fare-type.entity';
import { ApplicableProduct } from './entities/applicable-product.entity';
import { MealType } from './entities/meal-type.entity';
import { AirportRestriction } from './entities/airport-restriction.entity';
import { DestinationType } from './entities/destination-type.entity';
@Module({
imports: [
@@ -88,6 +96,14 @@ import { AmountType } from './entities/amount-type.entity';
Currency,
RefundMethod,
AmountType,
BaggageType,
CompensationRule,
ApprovalLevel,
EligibleFareType,
ApplicableProduct,
MealType,
AirportRestriction,
DestinationType,
]),
],
controllers: [MasterDataController],
@@ -45,6 +45,14 @@ import { RefundBasis } from './entities/refund-basis.entity';
import { Currency } from './entities/currency.entity';
import { RefundMethod } from './entities/refund-method.entity';
import { AmountType } from './entities/amount-type.entity';
import { BaggageType } from './entities/baggage-type.entity';
import { CompensationRule } from './entities/compensation-rule.entity';
import { ApprovalLevel } from './entities/approval-level.entity';
import { EligibleFareType } from './entities/eligible-fare-type.entity';
import { ApplicableProduct } from './entities/applicable-product.entity';
import { MealType } from './entities/meal-type.entity';
import { AirportRestriction } from './entities/airport-restriction.entity';
import { DestinationType } from './entities/destination-type.entity';
import { CreateActionCategoryDto } from './dto/create-action-category.dto';
import { UpdateActionCategoryDto } from './dto/update-action-category.dto';
@@ -101,6 +109,14 @@ export class MasterDataService implements OnModuleInit {
@InjectRepository(Currency) private currencyRepo: Repository<Currency>,
@InjectRepository(RefundMethod) private refundMethodRepo: Repository<RefundMethod>,
@InjectRepository(AmountType) private amountTypeRepo: Repository<AmountType>,
@InjectRepository(BaggageType) private baggageTypeRepo: Repository<BaggageType>,
@InjectRepository(CompensationRule) private compensationRuleRepo: Repository<CompensationRule>,
@InjectRepository(ApprovalLevel) private approvalLevelRepo: Repository<ApprovalLevel>,
@InjectRepository(EligibleFareType) private eligibleFareTypeRepo: Repository<EligibleFareType>,
@InjectRepository(ApplicableProduct) private applicableProductRepo: Repository<ApplicableProduct>,
@InjectRepository(MealType) private mealTypeRepo: Repository<MealType>,
@InjectRepository(AirportRestriction) private airportRestrictionRepo: Repository<AirportRestriction>,
@InjectRepository(DestinationType) private destinationTypeRepo: Repository<DestinationType>,
) { }
private getRepositoryByCategory(category: string): Repository<any> {
@@ -252,6 +268,46 @@ export class MasterDataService implements OnModuleInit {
case 'TBL_AMOUNT_TYPES':
return this.amountTypeRepo;
case 'BAGGAGE_TYPE':
case 'BAGGAGE_TYPES':
case 'TBL_BAGGAGE_TYPES':
return this.baggageTypeRepo;
case 'COMPENSATION_RULE':
case 'COMPENSATION_RULES':
case 'TBL_COMPENSATION_RULES':
return this.compensationRuleRepo;
case 'APPROVAL_LEVEL':
case 'APPROVAL_LEVELS':
case 'TBL_APPROVAL_LEVELS':
return this.approvalLevelRepo;
case 'ELIGIBLE_FARE_TYPE':
case 'ELIGIBLE_FARE_TYPES':
case 'TBL_ELIGIBLE_FARE_TYPES':
return this.eligibleFareTypeRepo;
case 'APPLICABLE_PRODUCT':
case 'APPLICABLE_PRODUCTS':
case 'TBL_APPLICABLE_PRODUCTS':
return this.applicableProductRepo;
case 'MEAL_TYPE':
case 'MEAL_TYPES':
case 'TBL_MEAL_TYPES':
return this.mealTypeRepo;
case 'AIRPORT_RESTRICTION':
case 'AIRPORT_RESTRICTIONS':
case 'TBL_AIRPORT_RESTRICTIONS':
return this.airportRestrictionRepo;
case 'DESTINATION_TYPE':
case 'DESTINATION_TYPES':
case 'TBL_DESTINATION_TYPES':
return this.destinationTypeRepo;
default:
throw new BadRequestException(`Invalid category: ${category}`);
}