From 0bed18b4395357844eee6acc8975cb03178c2591 Mon Sep 17 00:00:00 2001 From: Firman Ramdhani <33869609+firmanramdhani@users.noreply.github.com> Date: Tue, 25 Jun 2024 13:45:23 +0700 Subject: [PATCH 1/2] feat: ini shared content report --- src/core/strings/constants/table.constants.ts | 3 ++ src/modules/reports/shared/constant/index.ts | 3 ++ .../shared/constant/report-config.constant.ts | 53 +++++++++++++++++++ .../shared/constant/report-group.constant.ts | 5 ++ .../shared/constant/report-status.constant.ts | 6 +++ .../entities/export-report-history.entity.ts | 19 +++++++ .../shared/entities/report-bookmark.entity.ts | 9 ++++ .../models/export-report-history.model.ts | 53 +++++++++++++++++++ .../shared/models/report-bookmark.model.ts | 25 +++++++++ 9 files changed, 176 insertions(+) create mode 100644 src/modules/reports/shared/constant/index.ts create mode 100644 src/modules/reports/shared/constant/report-config.constant.ts create mode 100644 src/modules/reports/shared/constant/report-group.constant.ts create mode 100644 src/modules/reports/shared/constant/report-status.constant.ts create mode 100644 src/modules/reports/shared/entities/export-report-history.entity.ts create mode 100644 src/modules/reports/shared/entities/report-bookmark.entity.ts create mode 100644 src/modules/reports/shared/models/export-report-history.model.ts create mode 100644 src/modules/reports/shared/models/report-bookmark.model.ts diff --git a/src/core/strings/constants/table.constants.ts b/src/core/strings/constants/table.constants.ts index 16f7897..53aa6bb 100644 --- a/src/core/strings/constants/table.constants.ts +++ b/src/core/strings/constants/table.constants.ts @@ -15,4 +15,7 @@ export enum TABLE_NAME { USER_PRIVILEGE_CONFIGURATION = 'user_privilege_configurations', VIP_CATEGORY = 'vip_categories', VIP_CODE = 'vip_codes', + + REPORT_BOOKMARK = 'report_bookmark', + EXPORT_REPORT_HISTORY = 'export_report_history', } diff --git a/src/modules/reports/shared/constant/index.ts b/src/modules/reports/shared/constant/index.ts new file mode 100644 index 0000000..3b44934 --- /dev/null +++ b/src/modules/reports/shared/constant/index.ts @@ -0,0 +1,3 @@ +export * from './report-config.constant'; +export * from './report-group.constant'; +export * from './report-status.constant'; diff --git a/src/modules/reports/shared/constant/report-config.constant.ts b/src/modules/reports/shared/constant/report-config.constant.ts new file mode 100644 index 0000000..b05f4d7 --- /dev/null +++ b/src/modules/reports/shared/constant/report-config.constant.ts @@ -0,0 +1,53 @@ +export enum DATA_FORMAT { + TEXT = 'text', + TEXT_UPPERCASE = 'text_uppercase', + TEXT_LOWERCASE = 'text_lowercase', + NUMBER = 'number', + MINUS_NUMBER = 'minus_number', + DATE_EPOCH = 'date_epoch', + DATE_TIMESTAMP = 'date_timestamp', + CURRENCY = 'currency', + MINUS_CURRENCY = 'minus_currency', + STATUS = 'status', + BOOLEAN = 'boolean', + PERCENTAGE = 'percentage', +} + +export enum DATA_TYPE { + DIMENSION = 'dimension', + MEASURE = 'measure', +} + +export enum FILTER_TYPE { + TEXT_EQUAL = 'text_equals', + TEXT_NOT_EQUAL = 'text_notEquals', + TEXT_CONTAINS = 'text_contains', + TEXT_MULTIPLE_CONTAINS = 'text_multiple_contains', + TEXT_MULTIPLE_REGEXP_CONTAINS = 'text_multiple_regexp_contains', + TEXT_NOT_CONTAINS = 'text_notContains', + TEXT_START_WITH = 'text_startWith', + TEXT_END_WITH = 'text_endWith', + TEXT_IN_MEMBER = 'text_inMemberText', + TEXT_IN_RANGE = 'text_inTextRange', + + DATE_IN_RANGE_EPOCH = 'text_inDateRange_epoch', + DATE_IN_RANGE_TIMESTAMP = 'text_inDateRange_timestamp', + + NUMBER_EQUAL = 'number_equals', + NUMBER_NOT_EQUAL = 'number_notEqual', + NUMBER_GREATER_THAN = 'number_greaterThan', + NUMBER_GREATER_THAN_OR_EQUAL = 'number_greaterThanOrEqual', + NUMBER_LESS_THAN = 'number_lessThan', + NUMBER_LESS_THAN_OR_EQUAL = 'number_lessThanOrEqual', + NUMBER_IN_RANGE = 'number_inRange', +} + +export enum FILTER_FIELD_TYPE { + select = 'select', + input_text = 'input_text', + input_number = 'input_number', + input_tag = 'input_tag', + date_picker = 'date_picker', + date_range_picker = 'date_range_picker', + month_range_picker = 'month_range_picker', +} diff --git a/src/modules/reports/shared/constant/report-group.constant.ts b/src/modules/reports/shared/constant/report-group.constant.ts new file mode 100644 index 0000000..80476fa --- /dev/null +++ b/src/modules/reports/shared/constant/report-group.constant.ts @@ -0,0 +1,5 @@ +export enum REPORT_GROUP { + // PATTERN => MODULE__MENU__SUB_MENU + // EXAMPLE: + contact__reports = 'contact__reports', +} diff --git a/src/modules/reports/shared/constant/report-status.constant.ts b/src/modules/reports/shared/constant/report-status.constant.ts new file mode 100644 index 0000000..ccb3195 --- /dev/null +++ b/src/modules/reports/shared/constant/report-status.constant.ts @@ -0,0 +1,6 @@ +export enum REPORT_HISTORY_STATUS { + PROCESSING = 'processing', + DONE = 'done', + FAILED = 'failed', + CANCEL = 'cancel', +} diff --git a/src/modules/reports/shared/entities/export-report-history.entity.ts b/src/modules/reports/shared/entities/export-report-history.entity.ts new file mode 100644 index 0000000..4c1afb3 --- /dev/null +++ b/src/modules/reports/shared/entities/export-report-history.entity.ts @@ -0,0 +1,19 @@ +import { BaseEntity } from 'src/core/modules/domain/entities/base.entity'; +import { REPORT_HISTORY_STATUS } from '../constant'; + +export interface ExportReportHistoryEntity extends BaseEntity { + group_name: string; + unique_name: string; + label: string; + file_name: string; + total_data: number; + processing_data: number; + file_url?: string; + status?: REPORT_HISTORY_STATUS; + last_process_offset?: number; + last_process_limit?: number; + total_resume?: number; + last_resume_created_at?: number; + query_export?: string; + canceled_at?: number; +} diff --git a/src/modules/reports/shared/entities/report-bookmark.entity.ts b/src/modules/reports/shared/entities/report-bookmark.entity.ts new file mode 100644 index 0000000..0a3ff3d --- /dev/null +++ b/src/modules/reports/shared/entities/report-bookmark.entity.ts @@ -0,0 +1,9 @@ +import { BaseEntity } from 'src/core/modules/domain/entities/base.entity'; + +export interface ReportBookmarkEntity extends BaseEntity { + group_name: string; + unique_name: string; + label: string; + applied?: boolean; + configuration?: any; +} diff --git a/src/modules/reports/shared/models/export-report-history.model.ts b/src/modules/reports/shared/models/export-report-history.model.ts new file mode 100644 index 0000000..2934bbf --- /dev/null +++ b/src/modules/reports/shared/models/export-report-history.model.ts @@ -0,0 +1,53 @@ +import { BaseModel } from 'src/core/modules/data/model/base.model'; +import { Entity, Column } from 'typeorm'; +import { REPORT_HISTORY_STATUS } from '../constant'; +import { TABLE_NAME } from 'src/core/strings/constants/table.constants'; +import { ExportReportHistoryEntity } from '../entities/export-report-history.entity'; + +@Entity(TABLE_NAME.EXPORT_REPORT_HISTORY) +export class ExportReportHistoryModel + extends BaseModel + implements ExportReportHistoryEntity +{ + @Column('varchar') + group_name: string; + + @Column('varchar') + unique_name: string; + + @Column('varchar') + label: string; + + @Column('varchar') + file_name: string; + + @Column('varchar', { nullable: true }) + file_url: string; + + @Column('int', { default: 0 }) + total_data: number; + + @Column('int', { default: 0 }) + processing_data: number; + + @Column('enum', { nullable: true, enum: REPORT_HISTORY_STATUS }) + status: REPORT_HISTORY_STATUS; + + @Column('int', { default: 0 }) + last_process_offset: number; + + @Column('int', { default: 0 }) + last_process_limit: number; + + @Column('int', { default: 0 }) + total_resume: number; + + @Column('bigint', { nullable: true }) + last_resume_created_at: number; + + @Column('varchar', { nullable: true }) + query_export: string; + + @Column({ type: 'bigint', nullable: true }) + canceled_at: number; +} diff --git a/src/modules/reports/shared/models/report-bookmark.model.ts b/src/modules/reports/shared/models/report-bookmark.model.ts new file mode 100644 index 0000000..38aa8dc --- /dev/null +++ b/src/modules/reports/shared/models/report-bookmark.model.ts @@ -0,0 +1,25 @@ +import { BaseModel } from 'src/core/modules/data/model/base.model'; +import { Entity, Column } from 'typeorm'; +import { ReportBookmarkEntity } from '../entities/report-bookmark.entity'; +import { TABLE_NAME } from 'src/core/strings/constants/table.constants'; + +@Entity(TABLE_NAME.REPORT_BOOKMARK) +export class ReportBookmarkModel + extends BaseModel + implements ReportBookmarkEntity +{ + @Column('varchar') + group_name: string; + + @Column('varchar') + unique_name: string; + + @Column('varchar') + label: string; + + @Column('bool', { nullable: true, default: false }) + applied: boolean; + + @Column('json', { nullable: true }) + configuration: any; +} From 655229ddbde955bce43085e44e80678bf4422259 Mon Sep 17 00:00:00 2001 From: Firman Ramdhani <33869609+firmanramdhani@users.noreply.github.com> Date: Tue, 25 Jun 2024 13:53:09 +0700 Subject: [PATCH 2/2] feat: setup migration table report --- package.json | 5 ++-- .../1719298201894-init-table-report.ts | 25 +++++++++++++++++++ src/database/ormconfig.ts | 5 +++- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/database/migrations/1719298201894-init-table-report.ts diff --git a/package.json b/package.json index 19790f1..6aaad51 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "seed:config": "ts-node -r tsconfig-paths/register ./node_modules/typeorm-seeding/dist/cli.js -n ./src/database/seed-ormconfig.ts config", "seed:run": "ts-node -r tsconfig-paths/register ./node_modules/typeorm-seeding/dist/cli.js -n ./src/database/seed-ormconfig.ts seed", "factory:config": "ts-node -r tsconfig-paths/register ./node_modules/typeorm-seeding/dist/cli.js -n ./src/database/seed-data-ormconfig.ts config", - "factory:run": "ts-node -r tsconfig-paths/register ./node_modules/typeorm-seeding/dist/cli.js -n ./src/database/seed-data-ormconfig.ts seed" + "factory:run": "ts-node -r tsconfig-paths/register ./node_modules/typeorm-seeding/dist/cli.js -n ./src/database/seed-data-ormconfig.ts seed", + "db:generate": "npm run orm migration:generate" }, "dependencies": { "@faker-js/faker": "^8.4.1", @@ -89,4 +90,4 @@ "coverageDirectory": "../coverage", "testEnvironment": "node" } -} +} \ No newline at end of file diff --git a/src/database/migrations/1719298201894-init-table-report.ts b/src/database/migrations/1719298201894-init-table-report.ts new file mode 100644 index 0000000..7d33f63 --- /dev/null +++ b/src/database/migrations/1719298201894-init-table-report.ts @@ -0,0 +1,25 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class InitTableReport1719298201894 implements MigrationInterface { + name = 'InitTableReport1719298201894'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `CREATE TABLE "report_bookmark" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "creator_id" character varying(36), "creator_name" character varying(125), "editor_id" character varying(36), "editor_name" character varying(125), "created_at" bigint NOT NULL, "updated_at" bigint NOT NULL, "group_name" character varying NOT NULL, "unique_name" character varying NOT NULL, "label" character varying NOT NULL, "applied" boolean DEFAULT false, "configuration" json, CONSTRAINT "PK_d72aa68a7ee505edf4f3e156946" PRIMARY KEY ("id"))`, + ); + await queryRunner.query( + `CREATE TYPE "public"."export_report_history_status_enum" AS ENUM('processing', 'done', 'failed', 'cancel')`, + ); + await queryRunner.query( + `CREATE TABLE "export_report_history" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "creator_id" character varying(36), "creator_name" character varying(125), "editor_id" character varying(36), "editor_name" character varying(125), "created_at" bigint NOT NULL, "updated_at" bigint NOT NULL, "group_name" character varying NOT NULL, "unique_name" character varying NOT NULL, "label" character varying NOT NULL, "file_name" character varying NOT NULL, "file_url" character varying, "total_data" integer NOT NULL DEFAULT '0', "processing_data" integer NOT NULL DEFAULT '0', "status" "public"."export_report_history_status_enum", "last_process_offset" integer NOT NULL DEFAULT '0', "last_process_limit" integer NOT NULL DEFAULT '0', "total_resume" integer NOT NULL DEFAULT '0', "last_resume_created_at" bigint, "query_export" character varying, "canceled_at" bigint, CONSTRAINT "PK_07a632c94dca0728ad1b51ed65c" PRIMARY KEY ("id"))`, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE "export_report_history"`); + await queryRunner.query( + `DROP TYPE "public"."export_report_history_status_enum"`, + ); + await queryRunner.query(`DROP TABLE "report_bookmark"`); + } +} diff --git a/src/database/ormconfig.ts b/src/database/ormconfig.ts index e0dadf5..31c172a 100644 --- a/src/database/ormconfig.ts +++ b/src/database/ormconfig.ts @@ -9,7 +9,10 @@ export const connectionSource = new DataSource({ username: process.env.DEFAULT_DB_USER, password: process.env.DEFAULT_DB_PASS, database: process.env.DEFAULT_DB_NAME, - entities: ['src/modules/**/**/data/models/*.ts'], + entities: [ + 'src/modules/**/**/data/models/*.ts', + 'src/modules/reports/shared/models/*.ts', + ], migrationsTableName: 'migrations', migrations: ['src/database/migrations/*.ts'], synchronize: false,