wip: demography data
parent
fa286820fc
commit
6227555671
|
@ -21,6 +21,7 @@ export enum TABLE_NAME {
|
||||||
TRANSACTION = 'transactions',
|
TRANSACTION = 'transactions',
|
||||||
TRANSACTION_ITEM = 'transaction_items',
|
TRANSACTION_ITEM = 'transaction_items',
|
||||||
TRANSACTION_TAX = 'transaction_taxes',
|
TRANSACTION_TAX = 'transaction_taxes',
|
||||||
|
TRANSACTION_DEMOGRAPHY = 'transaction_demographies',
|
||||||
USER = 'users',
|
USER = 'users',
|
||||||
USER_PRIVILEGE = 'user_privileges',
|
USER_PRIVILEGE = 'user_privileges',
|
||||||
USER_PRIVILEGE_CONFIGURATION = 'user_privilege_configurations',
|
USER_PRIVILEGE_CONFIGURATION = 'user_privilege_configurations',
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class AddItemProfit1723706764654 implements MigrationInterface {
|
||||||
|
name = 'AddOtherType1723706764655';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "items" ADD "breakdown_bundling" boolean NOT NULL DEFAULT false`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TYPE "public"."item_categories_item_type_enum" RENAME TO "item_categories_item_type_enum_old"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TYPE "public"."item_categories_item_type_enum" AS ENUM('tiket masuk', 'wahana', 'bundling', 'free gift', 'other')`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "item_categories" ALTER COLUMN "item_type" DROP DEFAULT`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "item_categories" ALTER COLUMN "item_type" TYPE "public"."item_categories_item_type_enum" USING "item_type"::"text"::"public"."item_categories_item_type_enum"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "item_categories" ALTER COLUMN "item_type" SET DEFAULT 'tiket masuk'`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`DROP TYPE "public"."item_categories_item_type_enum_old"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TYPE "public"."items_item_type_enum" RENAME TO "items_item_type_enum_old"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TYPE "public"."items_item_type_enum" AS ENUM('tiket masuk', 'wahana', 'bundling', 'free gift', 'other')`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "items" ALTER COLUMN "item_type" DROP DEFAULT`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "items" ALTER COLUMN "item_type" TYPE "public"."items_item_type_enum" USING "item_type"::"text"::"public"."items_item_type_enum"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "items" ALTER COLUMN "item_type" SET DEFAULT 'tiket masuk'`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(`DROP TYPE "public"."items_item_type_enum_old"`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TYPE "public"."items_item_type_enum_old" AS ENUM('bundling', 'free gift', 'tiket masuk', 'wahana')`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "items" ALTER COLUMN "item_type" DROP DEFAULT`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "items" ALTER COLUMN "item_type" TYPE "public"."items_item_type_enum_old" USING "item_type"::"text"::"public"."items_item_type_enum_old"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "items" ALTER COLUMN "item_type" SET DEFAULT 'tiket masuk'`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(`DROP TYPE "public"."items_item_type_enum"`);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TYPE "public"."items_item_type_enum_old" RENAME TO "items_item_type_enum"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TYPE "public"."item_categories_item_type_enum_old" AS ENUM('bundling', 'free gift', 'tiket masuk', 'wahana')`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "item_categories" ALTER COLUMN "item_type" DROP DEFAULT`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "item_categories" ALTER COLUMN "item_type" TYPE "public"."item_categories_item_type_enum_old" USING "item_type"::"text"::"public"."item_categories_item_type_enum_old"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "item_categories" ALTER COLUMN "item_type" SET DEFAULT 'tiket masuk'`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`DROP TYPE "public"."item_categories_item_type_enum"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TYPE "public"."item_categories_item_type_enum_old" RENAME TO "item_categories_item_type_enum"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "items" DROP COLUMN "breakdown_bundling"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class AddDemographyTransaction1723713873756
|
||||||
|
implements MigrationInterface
|
||||||
|
{
|
||||||
|
name = 'AddDemographyTransaction1723713873756';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TABLE "transaction_demographies" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "man" integer NOT NULL DEFAULT '0', "woman" integer NOT NULL DEFAULT '0', "teen" integer NOT NULL DEFAULT '0', "child" integer NOT NULL DEFAULT '0', "local" integer NOT NULL DEFAULT '0', "foreign" integer NOT NULL DEFAULT '0', "transaction_id" uuid, CONSTRAINT "PK_84083b782ebc2c6cb2a2dab8e2d" PRIMARY KEY ("id"))`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "transaction_demographies" ADD CONSTRAINT "FK_a2b705884bca06c148e3b35ab04" FOREIGN KEY ("transaction_id") REFERENCES "transactions"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "transaction_demographies" DROP CONSTRAINT "FK_a2b705884bca06c148e3b35ab04"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(`DROP TABLE "transaction_demographies"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class FixDemographyNationality1723716561482
|
||||||
|
implements MigrationInterface
|
||||||
|
{
|
||||||
|
name = 'FixDemographyNationality1723716561482';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "transaction_demographies" DROP COLUMN "local"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "transaction_demographies" DROP COLUMN "foreign"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TYPE "public"."transaction_demographies_nationality_enum" AS ENUM('local', 'foreign')`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "transaction_demographies" ADD "nationality" "public"."transaction_demographies_nationality_enum" NOT NULL DEFAULT 'local'`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "transaction_demographies" DROP CONSTRAINT "FK_a2b705884bca06c148e3b35ab04"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "transaction_demographies" ADD CONSTRAINT "UQ_a2b705884bca06c148e3b35ab04" UNIQUE ("transaction_id")`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "transaction_demographies" ADD CONSTRAINT "FK_a2b705884bca06c148e3b35ab04" FOREIGN KEY ("transaction_id") REFERENCES "transactions"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "transaction_demographies" DROP CONSTRAINT "FK_a2b705884bca06c148e3b35ab04"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "transaction_demographies" DROP CONSTRAINT "UQ_a2b705884bca06c148e3b35ab04"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "transaction_demographies" ADD CONSTRAINT "FK_a2b705884bca06c148e3b35ab04" FOREIGN KEY ("transaction_id") REFERENCES "transactions"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "transaction_demographies" DROP COLUMN "nationality"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`DROP TYPE "public"."transaction_demographies_nationality_enum"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "transaction_demographies" ADD "foreign" integer NOT NULL DEFAULT '0'`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "transaction_demographies" ADD "local" integer NOT NULL DEFAULT '0'`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,3 +29,8 @@ export const TransactionModels = [
|
||||||
TransactionItemModel,
|
TransactionItemModel,
|
||||||
TransactionTaxModel,
|
TransactionTaxModel,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export enum DemographyNationality {
|
||||||
|
LOCAL = 'local',
|
||||||
|
FOREIGN = 'foreign',
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
import { Column, Entity, JoinColumn, OneToOne } from 'typeorm';
|
||||||
|
import { BaseCoreModel } from 'src/core/modules/data/model/base-core.model';
|
||||||
|
import { TransactionModel } from './transaction.model';
|
||||||
|
import { TransactionDemographyEntity } from '../../domain/entities/transaction-graphy.entity';
|
||||||
|
import { DemographyNationality } from '../../constants';
|
||||||
|
|
||||||
|
@Entity(TABLE_NAME.TRANSACTION_DEMOGRAPHY)
|
||||||
|
export class TransactionDemographyModel
|
||||||
|
extends BaseCoreModel<TransactionDemographyEntity>
|
||||||
|
implements TransactionDemographyEntity
|
||||||
|
{
|
||||||
|
@Column('int', { default: 0 })
|
||||||
|
man: number;
|
||||||
|
|
||||||
|
@Column('int', { default: 0 })
|
||||||
|
woman: number;
|
||||||
|
|
||||||
|
@Column('int', { default: 0 })
|
||||||
|
teen: number;
|
||||||
|
|
||||||
|
@Column('int', { default: 0 })
|
||||||
|
child: number;
|
||||||
|
|
||||||
|
@Column('enum', {
|
||||||
|
name: 'nationality',
|
||||||
|
enum: DemographyNationality,
|
||||||
|
default: DemographyNationality.LOCAL,
|
||||||
|
})
|
||||||
|
nationality: DemographyNationality;
|
||||||
|
|
||||||
|
@Column('varchar', { name: 'transaction_id', nullable: true })
|
||||||
|
transaction_id: string;
|
||||||
|
|
||||||
|
@OneToOne(() => TransactionModel, (model) => model.demographies, {
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
onUpdate: 'CASCADE',
|
||||||
|
})
|
||||||
|
@JoinColumn({ name: 'transaction_id' })
|
||||||
|
transaction: TransactionModel;
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
import { TransactionEntity } from '../../domain/entities/transaction.entity';
|
import { TransactionEntity } from '../../domain/entities/transaction.entity';
|
||||||
import { Column, Entity, OneToMany } from 'typeorm';
|
import { Column, Entity, OneToMany, OneToOne } from 'typeorm';
|
||||||
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
|
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
|
||||||
import {
|
import {
|
||||||
TransactionType,
|
TransactionType,
|
||||||
|
@ -12,6 +12,7 @@ import { TransactionItemModel } from './transaction-item.model';
|
||||||
import { TransactionTaxModel } from './transaction-tax.model';
|
import { TransactionTaxModel } from './transaction-tax.model';
|
||||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
import { RefundModel } from 'src/modules/transaction/refund/data/models/refund.model';
|
import { RefundModel } from 'src/modules/transaction/refund/data/models/refund.model';
|
||||||
|
import { TransactionDemographyModel } from './transaction-demography.model';
|
||||||
|
|
||||||
@Entity(TABLE_NAME.TRANSACTION)
|
@Entity(TABLE_NAME.TRANSACTION)
|
||||||
export class TransactionModel
|
export class TransactionModel
|
||||||
|
@ -242,6 +243,13 @@ export class TransactionModel
|
||||||
})
|
})
|
||||||
taxes: TransactionTaxModel[];
|
taxes: TransactionTaxModel[];
|
||||||
|
|
||||||
|
@OneToOne(() => TransactionDemographyModel, (model) => model.transaction, {
|
||||||
|
cascade: true,
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
onUpdate: 'CASCADE',
|
||||||
|
})
|
||||||
|
demographies: TransactionDemographyModel;
|
||||||
|
|
||||||
// relations to refund
|
// relations to refund
|
||||||
@OneToMany(() => RefundModel, (model) => model.transaction, {
|
@OneToMany(() => RefundModel, (model) => model.transaction, {
|
||||||
cascade: true,
|
cascade: true,
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { BaseCoreEntity } from 'src/core/modules/domain/entities/base-core.entity';
|
||||||
|
import { DemographyNationality } from '../../constants';
|
||||||
|
|
||||||
|
export interface TransactionDemographyEntity extends BaseCoreEntity {
|
||||||
|
man: number;
|
||||||
|
woman: number;
|
||||||
|
teen: number;
|
||||||
|
child: number;
|
||||||
|
nationality: DemographyNationality;
|
||||||
|
}
|
Loading…
Reference in New Issue