Skip to content

Commit

Permalink
Merge branch 'develop' into fix/some-permission-logic
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmbabhazi committed Feb 19, 2025
2 parents 73d8e4e + ab4a297 commit 4879211
Show file tree
Hide file tree
Showing 21 changed files with 2,331 additions and 347 deletions.
11 changes: 7 additions & 4 deletions packages/contracts/src/lib/dashboard.model.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { IBasePerTenantAndOrganizationEntityModel, JsonData } from './base-entity.model';
import { IBasePerTenantAndOrganizationEntityModel, JsonData, OmitFields } from './base-entity.model';
import { IDashboardWidget } from './dashboard-widget.model';
import { ExcludeCreatorFields, IHasCreator } from './user.model';
import { IEmployeeEntityInput } from './employee.model';
import { ExcludeUserCreatorFields, IHasUserCreator } from './user.model';

/**
* Interface representing a Dashboard entity.
*/
export interface IDashboard extends IBasePerTenantAndOrganizationEntityModel, IHasCreator {
export interface IDashboard extends IBasePerTenantAndOrganizationEntityModel, IEmployeeEntityInput, IHasUserCreator {
name: string;
identifier: string;
description?: string;
Expand All @@ -17,7 +18,9 @@ export interface IDashboard extends IBasePerTenantAndOrganizationEntityModel, IH
/**
* Input interface for creating a Dashboard entity.
*/
export interface IDashboardCreateInput extends ExcludeCreatorFields<IDashboard>, Omit<IDashboard, 'isDefault'> {}
export interface IDashboardCreateInput
extends OmitFields<IDashboard, 'isDefault'>,
ExcludeUserCreatorFields<IDashboard> {}

/**
* Input interface for updating a Dashboard entity.
Expand Down
5 changes: 5 additions & 0 deletions packages/contracts/src/lib/employee.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ import { IFavorite } from './favorite.model';
import { IComment } from './comment.model';
import { IOrganizationSprint } from './organization-sprint.model';

/**
* Utility type to exclude `employee` and `employeeId` fields.
*/
export type ExcludeEmployeeAuthorFields<T, K extends keyof T = never> = Omit<T, 'employee' | 'employeeId' | K>;

export interface IFindMembersInput extends IBasePerTenantAndOrganizationEntityModel {
organizationTeamId: ID;
organizationProjectId: ID;
Expand Down
12 changes: 6 additions & 6 deletions packages/contracts/src/lib/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ export interface IFindMeUser extends IBaseRelationsEntityModel {
}

/**
* Utility type to exclude `creator` and `creatorId` fields.
* Utility type to exclude `createdByUser` and `createdByUserId` fields.
*/
export type ExcludeCreatorFields<T> = Omit<T, 'creator' | 'creatorId'>;
export type ExcludeUserCreatorFields<T, K extends keyof T = never> = Omit<T, 'createdByUser' | 'createdByUserId' | K>;

/**
* Interface representing a relationship with a creator.
* Interface representing an entity with a creator association.
*/
export interface IHasCreator {
creator?: IUser; // TODO : Replace these properties with `createdBy` and `createdById`
creatorId?: ID;
export interface IHasUserCreator {
createdByUser?: IUser;
createdByUserId?: ID;
}

export interface IRelationalUser {
Expand Down
73 changes: 71 additions & 2 deletions packages/core/src/lib/core/seeds/seed-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
DEFAULT_EVER_ORGANIZATIONS,
DEFAULT_ORGANIZATIONS
} from '../../organization';
import { createDefaultEmployeeDashboards, createRandomEmployeeDashboards } from '../../dashboard/dashboard.seed';
import { createDefaultIncomes, createRandomIncomes } from '../../income/income.seed';
import { createDefaultExpenses, createRandomExpenses } from '../../expense/expense.seed';
import {
Expand Down Expand Up @@ -151,6 +152,14 @@ import {
} from '../../candidate-criterions-rating/candidate-criterion-rating.seed';
import { createDefaultGoalKpi } from '../../goal-kpi/goal-kpi.seed';
import { createRandomEmployeeSetting } from '../../employee-setting/employee-setting.seed';
import {
createDefaultEmployeeNotificationSettings,
createRandomEmployeeNotificationSettings
} from '../../employee-notification-setting/employee-notification-setting.seed';
import {
createDefaultEmployeeNotifications,
createRandomEmployeeNotifications
} from '../../employee-notification/employee-notification.seed';
import { createRandomEmployeeRecurringExpense } from '../../employee-recurring-expense/employee-recurring-expense.seed';
import {
createDefaultCandidateInterviewers,
Expand Down Expand Up @@ -712,17 +721,27 @@ export class SeedDataService {
createCandidateSkills(this.dataSource, this.tenant, defaultCandidates, this.defaultOrganization)
);

await this.tryExecute(
'Default Employee Dashboards',
createDefaultEmployeeDashboards(
this.dataSource,
this.tenant,
this.defaultOrganization,
this.defaultEmployees
)
);

await this.tryExecute(
'Default Incomes',
createDefaultIncomes(this.dataSource, this.tenant, [this.defaultOrganization], this.defaultEmployees)
createDefaultIncomes(this.dataSource, this.tenant, this.defaultOrganization, this.defaultEmployees)
);

await this.tryExecute(
'Default Expenses',
createDefaultExpenses(
this.dataSource,
this.organizations,
this.tenant,
this.organizations,
this.defaultEmployees,
categories,
organizationVendors
Expand All @@ -734,6 +753,26 @@ export class SeedDataService {
seedDefaultEmploymentTypes(this.dataSource, this.tenant, this.defaultEmployees, this.defaultOrganization)
);

await this.tryExecute(
'Default Employee Notification Settings',
createDefaultEmployeeNotificationSettings(
this.dataSource,
this.tenant,
this.defaultOrganization,
this.defaultEmployees
)
);

await this.tryExecute(
'Default Employee Notifications',
createDefaultEmployeeNotifications(
this.dataSource,
this.tenant,
this.defaultOrganization,
this.defaultEmployees
)
);

await this.tryExecute(
'Default Goal KPIs',
createDefaultGoalKpi(this.dataSource, this.tenant, this.organizations, this.defaultEmployees)
Expand Down Expand Up @@ -1382,6 +1421,16 @@ export class SeedDataService {
createRandomCandidateFeedbacks(this.dataSource, this.randomTenants, tenantCandidatesMap)
);

await this.tryExecute(
'Random Employee Dashboards',
createRandomEmployeeDashboards(
this.dataSource,
this.randomTenants,
this.randomTenantOrganizationsMap,
this.randomOrganizationEmployeesMap
)
);

await this.tryExecute(
'Random Employee Recurring Expenses',
createRandomEmployeeRecurringExpense(
Expand All @@ -1402,6 +1451,26 @@ export class SeedDataService {
)
);

await this.tryExecute(
'Random Employee Notification Settings',
createRandomEmployeeNotificationSettings(
this.dataSource,
this.randomTenants,
this.randomTenantOrganizationsMap,
this.randomOrganizationEmployeesMap
)
);

await this.tryExecute(
'Random Employee Notifications',
createRandomEmployeeNotifications(
this.dataSource,
this.randomTenants,
this.randomTenantOrganizationsMap,
this.randomOrganizationEmployeesMap
)
);

await this.tryExecute(
'Random Organization Languages',
createRandomOrganizationLanguage(this.dataSource, this.randomTenants, this.randomTenantOrganizationsMap)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import { HttpException, HttpStatus, Logger } from '@nestjs/common';
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { IDashboard } from '@gauzy/contracts';
import { DashboardService } from '../../dashboard.service';
import { DashboardCreateCommand } from '../dashboard.create.command';

@CommandHandler(DashboardCreateCommand)
export class DashboardCreateHandler implements ICommandHandler<DashboardCreateCommand> {
private readonly logger = new Logger(DashboardCreateHandler.name);

constructor(private readonly dashboardService: DashboardService) {}

/**
* Handles the DashboardCreateCommand to create a new dashboard.
*
* @param command - The command containing the input data for dashboard creation.
* @returns A promise that resolves to the created dashboard.
*/
public async execute(command: DashboardCreateCommand): Promise<IDashboard> {
const { input } = command;
return this.dashboardService.create(input);
}
/**
* Handles the DashboardCreateCommand to create a new dashboard.
*
* @param command - The command containing the input data for dashboard creation.
* @returns A promise that resolves to the created dashboard.
*/
public async execute(command: DashboardCreateCommand): Promise<IDashboard> {
try {
const { input } = command;
return await this.dashboardService.create(input);
} catch (error) {
this.logger.error('Failed to create dashboard', error.stack);
throw new HttpException(`Error while creating dashboard: ${error.message}`, HttpStatus.BAD_REQUEST);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { HttpException, Logger } from '@nestjs/common';
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { IDashboard } from '@gauzy/contracts';
import { HttpStatus, IDashboard } from '@gauzy/contracts';
import { DashboardService } from '../../dashboard.service';
import { DashboardUpdateCommand } from '../dashboard.update.command';

@CommandHandler(DashboardUpdateCommand)
export class DashboardUpdateHandler implements ICommandHandler<DashboardUpdateCommand> {
private readonly logger = new Logger(DashboardUpdateHandler.name);

constructor(private readonly dashboardService: DashboardService) {}

/**
Expand All @@ -14,7 +17,12 @@ export class DashboardUpdateHandler implements ICommandHandler<DashboardUpdateCo
* @returns A promise that resolves to the updated dashboard.
*/
public async execute(command: DashboardUpdateCommand): Promise<IDashboard> {
const { id, input } = command;
return this.dashboardService.update(id, input);
try {
const { id, input } = command;
return await this.dashboardService.update(id, input);
} catch (error) {
this.logger.error('Failed to update dashboard', error.stack);
throw new HttpException(`Error while updating dashboard: ${error.message}`, HttpStatus.BAD_REQUEST);
}
}
}
Loading

0 comments on commit 4879211

Please sign in to comment.