Skip to content

Commit

Permalink
Merge pull request #8611 from ever-co/feat/dashboard-feature
Browse files Browse the repository at this point in the history
[Feat] Dashboard Feature
  • Loading branch information
rahul-rocket authored Dec 24, 2024
2 parents 0372435 + 128fe0d commit dd35538
Show file tree
Hide file tree
Showing 14 changed files with 326 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"start:api:forever": "cross-env NODE_OPTIONS=--max-old-space-size=12288 forever start node_modules/@angular/cli/bin/ng serve api --host 0.0.0.0",
"start:api:pm2": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn run build:api && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/pm2bootstrap.ts",
"start:api:core": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn nx run core:serve",
"db:migration": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn run config:dev && yarn run build:package:api && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/migration.ts",
"db:migration": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn run build:package:api && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/migration.ts",
"migration:run": "yarn db:migration migration:run",
"migration:revert": "yarn db:migration migration:revert",
"migration:generate": "yarn db:migration migration:generate",
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export * from './lib/country.model';
export * from './lib/currency.model';
export * from './lib/custom-smtp.model';
export * from './lib/date-picker.model';
export * from './lib/dashboard.model';
export * from './lib/deal.model';
export * from './lib/email-reset.model';
export * from './lib/email-template.model';
Expand Down
18 changes: 18 additions & 0 deletions packages/contracts/src/lib/dashboard.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { IBasePerTenantAndOrganizationEntityModel, JsonData } from './base-entity.model';
import { ExcludeCreatorFields, IHasCreator } from './user.model';

/**
* Interface representing a Dashboard entity.
*/
export interface IDashboard extends IBasePerTenantAndOrganizationEntityModel, IHasCreator {
name: string;
identifier: string;
description?: string;
contentHtml?: JsonData;
isDefault?: boolean;
}

/**
* Input interface for creating a Dashboard entity.
*/
export interface IDashboardCreateInput extends ExcludeCreatorFields<IDashboard> {}
13 changes: 13 additions & 0 deletions packages/contracts/src/lib/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ export interface IFindMeUser extends IBaseRelationsEntityModel {
readonly includeOrganization?: boolean;
}

/**
* Utility type to exclude `creator` and `creatorId` fields.
*/
export type ExcludeCreatorFields<T> = Omit<T, 'creator' | 'creatorId'>;

/**
* Interface representing a relationship with a creator.
*/
export interface IHasCreator {
creator?: IUser;
creatorId?: ID;
}

export interface IRelationalUser {
user?: IUser; // User who performed the action (if applicable).
userId?: ID; // The ID of the user who performed the action (if applicable).
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/lib/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ import { TaskViewModule } from '../tasks/views/view.module';
import { ResourceLinkModule } from '../resource-link/resource-link.module';
import { MentionModule } from '../mention/mention.module';
import { SubscriptionModule } from '../subscription/subscription.module';
import { DashboardModule } from '../dashboard/dashboard.module';

const { unleashConfig } = environment;

Expand Down Expand Up @@ -458,7 +459,8 @@ if (environment.THROTTLE_ENABLED) {
TaskViewModule,
ResourceLinkModule,
MentionModule,
SubscriptionModule
SubscriptionModule,
DashboardModule
],
controllers: [AppController],
providers: [
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/lib/core/entities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
Currency,
CustomSmtp,
DailyPlan,
Dashboard,
Deal,
EmailHistory,
EmailReset,
Expand Down Expand Up @@ -178,6 +179,7 @@ export const coreEntities = [
Currency,
CustomSmtp,
DailyPlan,
Dashboard,
Deal,
EmailHistory,
EmailReset,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/lib/core/entities/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export * from '../../contact/contact.entity';
export * from '../../country/country.entity';
export * from '../../currency/currency.entity';
export * from '../../custom-smtp/custom-smtp.entity';
export * from '../../dashboard/dashboard.entity';
export * from '../../deal/deal.entity';
export * from '../../email-history/email-history.entity';
export * from '../../email-reset/email-reset.entity';
Expand Down
81 changes: 81 additions & 0 deletions packages/core/src/lib/dashboard/dashboard.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { EntityRepositoryType } from '@mikro-orm/core';
import { JoinColumn, RelationId } from 'typeorm';
import { IsArray, IsBoolean, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { isMySQL, isPostgres } from '@gauzy/config';
import { ID, IDashboard, IUser, JsonData } from '@gauzy/contracts';
import { TenantOrganizationBaseEntity, User } from '../core/entities/internal';
import { ColumnIndex, MultiORMColumn, MultiORMEntity, MultiORMManyToOne } from '../core/decorators/entity';
import { MikroOrmDashboardRepository } from './repository/mikro-orm-dashboard.repository';

@MultiORMEntity('dashboard', { mikroOrmRepository: () => MikroOrmDashboardRepository })
export class Dashboard extends TenantOrganizationBaseEntity implements IDashboard {
[EntityRepositoryType]?: MikroOrmDashboardRepository;

/**
* Name of the dashboard
*/
@ApiProperty({ type: () => String })
@IsNotEmpty()
@IsString()
@MultiORMColumn()
name: string;

/**
* Identifier of the dashboard
*/
@ApiProperty({ type: () => String })
@IsNotEmpty()
@IsString()
@MultiORMColumn()
identifier: string;

/**
* Description of the dashboard
*/
@ApiPropertyOptional({ type: () => String })
@IsOptional()
@IsString()
@MultiORMColumn({ type: 'text', nullable: true })
description?: string;

/**
* Content of the dashboard
*/
@ApiPropertyOptional({ type: () => Object })
@IsOptional()
@IsArray()
@MultiORMColumn({ type: isPostgres() ? 'jsonb' : isMySQL() ? 'json' : 'text', nullable: true })
contentHtml?: JsonData;

/**
* Indicates if the dashboard is the default dashboard
*/
@ApiPropertyOptional({ type: Boolean })
@IsOptional()
@IsBoolean()
@MultiORMColumn({ default: false })
isDefault: boolean;

/*
|--------------------------------------------------------------------------
| @ManyToOne
|--------------------------------------------------------------------------
*/

/**
* Who created the dashboard
*/
@MultiORMManyToOne(() => User, {
/** Database cascade action on delete. */
onDelete: 'CASCADE'
})
@JoinColumn()
creator?: IUser;

@RelationId((it: Dashboard) => it.creator)
@ColumnIndex()
@MultiORMColumn({ relationId: true })
creatorId?: ID;
}
15 changes: 15 additions & 0 deletions packages/core/src/lib/dashboard/dashboard.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Module } from '@nestjs/common';
import { Dashboard } from './dashboard.entity';

@Module({
imports: [
TypeOrmModule.forFeature([Dashboard]),
MikroOrmModule.forFeature([Dashboard]),
],
controllers: [],
providers: [],
exports: []
})
export class DashboardModule {}
2 changes: 2 additions & 0 deletions packages/core/src/lib/dashboard/repository/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './mikro-orm-dashboard.repository';
export * from './type-orm-dashboard.repository';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { MikroOrmBaseEntityRepository } from '../../core/repository/mikro-orm-base-entity.repository';
import { Dashboard } from '../dashboard.entity';

export class MikroOrmDashboardRepository extends MikroOrmBaseEntityRepository<Dashboard> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Dashboard } from '../dashboard.entity';

@Injectable()
export class TypeOrmDashboardRepository extends Repository<Dashboard> {
constructor(@InjectRepository(Dashboard) readonly repository: Repository<Dashboard>) {
super(repository.target, repository.manager, repository.queryRunner);
}
}
5 changes: 2 additions & 3 deletions packages/core/src/lib/database/migration-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,8 @@ function queryParams(parameters: any[] | undefined): string {
*/
function getTemplate(connection: DataSource, name: string, timestamp: number, upSqls: string[], downSqls: string[]): string {
return `
import { Logger } from '@nestjs/common';
import { MigrationInterface, QueryRunner } from "typeorm";
import { yellow } from "chalk";
import * as chalk from 'chalk';
import { DatabaseTypeEnum } from "@gauzy/config";
export class ${camelCase(name, true)}${timestamp} implements MigrationInterface {
Expand All @@ -280,7 +279,7 @@ export class ${camelCase(name, true)}${timestamp} implements MigrationInterface
* @param queryRunner
*/
public async up(queryRunner: QueryRunner): Promise<void> {
Logger.debug(yellow(this.name + ' start running!'), 'Migration');
console.log(chalk.yellow(this.name + ' start running!'));
switch (queryRunner.connection.options.type) {
case DatabaseTypeEnum.sqlite:
Expand Down
Loading

0 comments on commit dd35538

Please sign in to comment.