From 3712e11f2d3eb892e8314d2a17c2a8a6991c02ae Mon Sep 17 00:00:00 2001 From: "Rahul R." Date: Thu, 23 Jan 2025 14:57:35 +0530 Subject: [PATCH 1/3] feat(constants): add @gauzy/constants package --- packages/constants/.dockerignore | 20 +++++++++++++ packages/constants/.gitignore | 6 ++++ packages/constants/.npmignore | 4 +++ packages/constants/CHANGELOG.md | 3 ++ packages/constants/README.md | 25 ++++++++++++++++ packages/constants/eslint.config.js | 19 ++++++++++++ packages/constants/jest.config.ts | 10 +++++++ packages/constants/package.json | 41 ++++++++++++++++++++++++++ packages/constants/project.json | 42 +++++++++++++++++++++++++++ packages/constants/src/index.ts | 1 + packages/constants/tsconfig.json | 21 ++++++++++++++ packages/constants/tsconfig.lib.json | 10 +++++++ packages/constants/tsconfig.spec.json | 9 ++++++ tsconfig.json | 1 + 14 files changed, 212 insertions(+) create mode 100644 packages/constants/.dockerignore create mode 100644 packages/constants/.gitignore create mode 100644 packages/constants/.npmignore create mode 100644 packages/constants/CHANGELOG.md create mode 100644 packages/constants/README.md create mode 100644 packages/constants/eslint.config.js create mode 100644 packages/constants/jest.config.ts create mode 100644 packages/constants/package.json create mode 100644 packages/constants/project.json create mode 100644 packages/constants/src/index.ts create mode 100644 packages/constants/tsconfig.json create mode 100644 packages/constants/tsconfig.lib.json create mode 100644 packages/constants/tsconfig.spec.json diff --git a/packages/constants/.dockerignore b/packages/constants/.dockerignore new file mode 100644 index 00000000000..6edd0523636 --- /dev/null +++ b/packages/constants/.dockerignore @@ -0,0 +1,20 @@ +docker +tmp +README.md +.env + +# git + +.git +.gitignore +.gitmodules + +# dependencies + +node_modules + +# misc + +npm-debug.log +dist +build diff --git a/packages/constants/.gitignore b/packages/constants/.gitignore new file mode 100644 index 00000000000..a34877c2c0e --- /dev/null +++ b/packages/constants/.gitignore @@ -0,0 +1,6 @@ +# dependencies +node_modules/ + +# misc +npm-debug.log +dist \ No newline at end of file diff --git a/packages/constants/.npmignore b/packages/constants/.npmignore new file mode 100644 index 00000000000..1eb4beb9572 --- /dev/null +++ b/packages/constants/.npmignore @@ -0,0 +1,4 @@ +# .npmignore + +src/ +node_modules/ diff --git a/packages/constants/CHANGELOG.md b/packages/constants/CHANGELOG.md new file mode 100644 index 00000000000..fc6c2032f95 --- /dev/null +++ b/packages/constants/CHANGELOG.md @@ -0,0 +1,3 @@ +# Changelog for @gauzy/constants + +## [Unreleased] diff --git a/packages/constants/README.md b/packages/constants/README.md new file mode 100644 index 00000000000..f988a28c4f5 --- /dev/null +++ b/packages/constants/README.md @@ -0,0 +1,25 @@ +# @gauzy/constants + +This library was generated with [Nx](https://nx.dev). It contains constants used internally in different UI/API packages. + +## Building + +Run `yarn nx build constants` to build the library. + +## Running unit tests + +Run `yarn nx test constants` to execute the unit tests via [Jest](https://jestjs.io). + +## Publishing + +After building your library with `yarn nx build constants`, go to the dist folder `dist/packages/constants` and run `npm publish`. + +## Installation + +Install the Package using your preferred package manager: + +```bash +npm install @gauzy/constants +# or +yarn add @gauzy/constants +``` diff --git a/packages/constants/eslint.config.js b/packages/constants/eslint.config.js new file mode 100644 index 00000000000..b4cb7a081b8 --- /dev/null +++ b/packages/constants/eslint.config.js @@ -0,0 +1,19 @@ +const baseConfig = require('../../.eslintrc.json'); + +module.exports = [ + ...baseConfig, + { + files: ['**/*.json'], + rules: { + '@nx/dependency-checks': [ + 'error', + { + ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'] + } + ] + }, + languageOptions: { + parser: require('jsonc-eslint-parser') + } + } +]; diff --git a/packages/constants/jest.config.ts b/packages/constants/jest.config.ts new file mode 100644 index 00000000000..1ae072004e9 --- /dev/null +++ b/packages/constants/jest.config.ts @@ -0,0 +1,10 @@ +export default { + displayName: 'constants', + preset: '../../jest.preset.js', + testEnvironment: 'node', + transform: { + '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }] + }, + moduleFileExtensions: ['ts', 'js', 'html'], + coverageDirectory: '../../coverage/packages/constants' +}; diff --git a/packages/constants/package.json b/packages/constants/package.json new file mode 100644 index 00000000000..2245c407eb4 --- /dev/null +++ b/packages/constants/package.json @@ -0,0 +1,41 @@ +{ + "name": "@gauzy/constants", + "version": "0.1.0", + "description": "", + "author": { + "name": "Ever Co. LTD", + "email": "ever@ever.co", + "url": "https://ever.co" + }, + "repository": { + "type": "git", + "url": "https://github.com/ever-co/ever-gauzy", + "directory": "packages/constants" + }, + "bugs": { + "url": "https://github.com/ever-co/ever-gauzy/issues" + }, + "homepage": "https://ever.co", + "license": "AGPL-3.0", + "private": true, + "type": "commonjs", + "main": "./src/index.js", + "typings": "./src/index.d.ts", + "scripts": { + "lib:build": "yarn nx build constants", + "lib:build:prod": "yarn nx build constants", + "lib:watch": "yarn nx build constants --watch" + }, + "dependencies": { + "tslib": "^2.6.2" + }, + "devDependencies": { + "@types/node": "^20.14.9" + }, + "keywords": [], + "engines": { + "node": ">=20.11.1", + "yarn": ">=1.22.19" + }, + "sideEffects": false +} diff --git a/packages/constants/project.json b/packages/constants/project.json new file mode 100644 index 00000000000..523da46c3d8 --- /dev/null +++ b/packages/constants/project.json @@ -0,0 +1,42 @@ +{ + "name": "constants", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "packages/constants/src", + "projectType": "library", + "release": { + "version": { + "generatorOptions": { + "packageRoot": "dist/{projectRoot}", + "currentVersionResolver": "git-tag" + } + } + }, + "tags": [], + "targets": { + "build": { + "executor": "@nx/js:tsc", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/packages/constants", + "main": "packages/constants/src/index.ts", + "tsConfig": "packages/constants/tsconfig.lib.json", + "assets": ["packages/constants/*.md"] + } + }, + "nx-release-publish": { + "options": { + "packageRoot": "dist/{projectRoot}" + } + }, + "lint": { + "executor": "@nx/eslint:lint" + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "packages/constants/jest.config.ts" + } + } + } +} diff --git a/packages/constants/src/index.ts b/packages/constants/src/index.ts new file mode 100644 index 00000000000..e136809733a --- /dev/null +++ b/packages/constants/src/index.ts @@ -0,0 +1 @@ +export const placeholder = '@gauzy/constants'; diff --git a/packages/constants/tsconfig.json b/packages/constants/tsconfig.json new file mode 100644 index 00000000000..f762511ee1d --- /dev/null +++ b/packages/constants/tsconfig.json @@ -0,0 +1,21 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "noPropertyAccessFromIndexSignature": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/packages/constants/tsconfig.lib.json b/packages/constants/tsconfig.lib.json new file mode 100644 index 00000000000..94b20c39e81 --- /dev/null +++ b/packages/constants/tsconfig.lib.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "declaration": true, + "types": ["node"] + }, + "include": ["src/**/*.ts"], + "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"] +} diff --git a/packages/constants/tsconfig.spec.json b/packages/constants/tsconfig.spec.json new file mode 100644 index 00000000000..ceb45ea29a4 --- /dev/null +++ b/packages/constants/tsconfig.spec.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"] +} diff --git a/tsconfig.json b/tsconfig.json index 80bfd5d2d00..1e9cbbf1d3e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,7 @@ "@gauzy/common": ["./packages/common/src/index.ts"], "@gauzy/config": ["./packages/config/src/index.ts"], "@gauzy/contracts": ["./packages/contracts/src/index.ts"], + "@gauzy/constants": ["./packages/constants/src/index.ts"], "@gauzy/core": ["./packages/core/src/index.ts"], "@gauzy/desktop-core": ["./packages/desktop-core/src/index.ts"], "@gauzy/desktop-timer": ["./packages/desktop-timer/src/index.ts"], From e918c70635eaf0152f4f21f17e43390628c5f52d Mon Sep 17 00:00:00 2001 From: "Rahul R." Date: Thu, 23 Jan 2025 15:51:11 +0530 Subject: [PATCH 2/3] feat(constants): add constants to @gauzy/constants package --- .../edit-employee-other-settings.component.ts | 14 +- ...t-organization-other-settings.component.ts | 24 +- packages/constants/src/index.ts | 2 +- packages/constants/src/lib/organization.ts | 57 +++ .../contracts/src/lib/organization.model.ts | 10 - packages/core/package.json | 1 + .../employee-statistics.service.ts | 7 +- .../core/src/lib/invite/invite.service.ts | 2 +- .../lib/organization/organization.entity.ts | 10 +- .../src/lib/organization/organization.seed.ts | 409 +++++++++--------- packages/core/src/lib/tenant/tenant.entity.ts | 11 +- packages/ui-core/package.json | 1 + .../organizations-step-form.component.ts | 2 +- .../charts/line-chart/line-chart.component.ts | 2 +- .../timezone-filter.component.ts | 10 +- .../edit-profile-form.component.ts | 7 +- 16 files changed, 300 insertions(+), 269 deletions(-) create mode 100644 packages/constants/src/lib/organization.ts diff --git a/apps/gauzy/src/app/pages/employees/edit-employee/edit-employee-profile/edit-employee-settings/edit-employee-other-settings.component.ts b/apps/gauzy/src/app/pages/employees/edit-employee/edit-employee-profile/edit-employee-settings/edit-employee-other-settings.component.ts index e3d2655b1af..52987af3c8c 100644 --- a/apps/gauzy/src/app/pages/employees/edit-employee/edit-employee-profile/edit-employee-settings/edit-employee-other-settings.component.ts +++ b/apps/gauzy/src/app/pages/employees/edit-employee/edit-employee-profile/edit-employee-settings/edit-employee-other-settings.component.ts @@ -4,7 +4,8 @@ import { filter, tap } from 'rxjs'; import { NbAccordionComponent, NbAccordionItemComponent } from '@nebular/theme'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import * as moment from 'moment'; -import { DEFAULT_TIME_FORMATS, IEmployee } from '@gauzy/contracts'; +import { DEFAULT_TIME_FORMATS } from '@gauzy/constants'; +import { IEmployee } from '@gauzy/contracts'; import { EmployeeStore } from '@gauzy/ui-core/core'; @UntilDestroy({ checkProperties: true }) @@ -82,7 +83,15 @@ export class EditEmployeeOtherSettingsComponent implements OnInit, OnDestroy { private _patchFormValue(employee: IEmployee): void { if (!employee) return; - const { user, upworkId, linkedInId, allowManualTime, allowDeleteTime, allowModifyTime, allowScreenshotCapture } = employee; + const { + user, + upworkId, + linkedInId, + allowManualTime, + allowDeleteTime, + allowModifyTime, + allowScreenshotCapture + } = employee; this.form.patchValue({ timeZone: user?.timeZone ?? moment.tz.guess(), timeFormat: user?.timeFormat, @@ -130,7 +139,6 @@ export class EditEmployeeOtherSettingsComponent implements OnInit, OnDestroy { }); } - /** * */ diff --git a/apps/gauzy/src/app/pages/organizations/edit-organization/edit-organization-settings/edit-organization-other-settings/edit-organization-other-settings.component.ts b/apps/gauzy/src/app/pages/organizations/edit-organization/edit-organization-settings/edit-organization-other-settings/edit-organization-other-settings.component.ts index f2c603318f0..37950b68cda 100644 --- a/apps/gauzy/src/app/pages/organizations/edit-organization/edit-organization-settings/edit-organization-other-settings/edit-organization-other-settings.component.ts +++ b/apps/gauzy/src/app/pages/organizations/edit-organization/edit-organization-settings/edit-organization-other-settings/edit-organization-other-settings.component.ts @@ -7,6 +7,17 @@ import * as moment from 'moment'; import { TranslateService } from '@ngx-translate/core'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { NbAccordionComponent, NbAccordionItemComponent, NbThemeService } from '@nebular/theme'; +import { + DEFAULT_ACTIVITY_PROOF_DURATIONS, + DEFAULT_DATE_FORMATS, + DEFAULT_INACTIVITY_TIME_LIMITS, + DEFAULT_REVENUE_BASED_BONUS, + DEFAULT_PROFIT_BASED_BONUS, + DEFAULT_SCREENSHOT_FREQUENCY_OPTIONS, + DEFAULT_TIME_FORMATS, + DEFAULT_STANDARD_WORK_HOURS_PER_DAY, + DEFAULT_INVITE_EXPIRY_PERIOD +} from '@gauzy/constants'; import { AccountingTemplateTypeEnum, AlignmentOptions, @@ -14,13 +25,6 @@ import { CrudActionEnum, CurrenciesEnum, CurrencyPosition, - DEFAULT_ACTIVITY_PROOF_DURATIONS, - DEFAULT_DATE_FORMATS, - DEFAULT_INACTIVITY_TIME_LIMITS, - DEFAULT_INVITE_EXPIRY_PERIOD, - DEFAULT_PROFIT_BASED_BONUS, - DEFAULT_REVENUE_BASED_BONUS, - DEFAULT_TIME_FORMATS, DEFAULT_TASK_NOTIFY_PERIOD, DEFAULT_PROOF_COMPLETION_TYPE, DefaultValueDateTypeEnum, @@ -32,9 +36,7 @@ import { IOrganizationTaskSetting, TaskProofOfCompletionTypeEnum, DEFAULT_AUTO_CLOSE_ISSUE_PERIOD, - DEFAULT_AUTO_ARCHIVE_ISSUE_PERIOD, - DEFAULT_SCREENSHOT_FREQUENCY_OPTIONS, - DEFAULT_STANDARD_WORK_HOURS_PER_DAY + DEFAULT_AUTO_ARCHIVE_ISSUE_PERIOD } from '@gauzy/contracts'; import { isEmpty } from '@gauzy/ui-core/common'; import { @@ -83,13 +85,13 @@ export class EditOrganizationOtherSettingsComponent listOfTimeFormats = DEFAULT_TIME_FORMATS; listOfInactivityLimits = DEFAULT_INACTIVITY_TIME_LIMITS; listOfActivityProofDuration = DEFAULT_ACTIVITY_PROOF_DURATIONS; + screenshotFrequencyOptions = DEFAULT_SCREENSHOT_FREQUENCY_OPTIONS; numberFormats = ['USD', 'BGN', 'ILS']; numberFormat: string; weekdays: WeekDaysEnum[] = Object.values(WeekDaysEnum); regionCodes = Object.keys(RegionsEnum); regionCode: string; regions = Object.values(RegionsEnum); - screenshotFrequencyOptions = DEFAULT_SCREENSHOT_FREQUENCY_OPTIONS; standardWorkHoursPerDayOptions: number[] = Array.from({ length: 24 }, (_, i) => i + 1); // Creates an array from 1 to 24 /* diff --git a/packages/constants/src/index.ts b/packages/constants/src/index.ts index e136809733a..6fcedfbb434 100644 --- a/packages/constants/src/index.ts +++ b/packages/constants/src/index.ts @@ -1 +1 @@ -export const placeholder = '@gauzy/constants'; +export * from './lib/organization'; diff --git a/packages/constants/src/lib/organization.ts b/packages/constants/src/lib/organization.ts new file mode 100644 index 00000000000..43f76b176f9 --- /dev/null +++ b/packages/constants/src/lib/organization.ts @@ -0,0 +1,57 @@ +/** + * Array containing the default time formats. + */ +export const DEFAULT_TIME_FORMATS: number[] = [12, 24]; + +/** + * Default standard work hours per day. + * - Typically set to 8 hours, aligning with standard full-time work schedules. + */ +export const DEFAULT_STANDARD_WORK_HOURS_PER_DAY = 8; + +/** + * Default profit-based bonus percentage. + * - Represents a 75% bonus based on profit metrics. + */ +export const DEFAULT_PROFIT_BASED_BONUS = 75; + +/** + * Default revenue-based bonus percentage. + * - Represents a 10% bonus based on revenue metrics. + */ +export const DEFAULT_REVENUE_BASED_BONUS = 10; + +/** + * Default invite expiry period in days. + * - Invitations expire after 7 days by default. + */ +export const DEFAULT_INVITE_EXPIRY_PERIOD = 7; + +/** + * Array of default date formats. + * - 'L': Locale-specific date representation (e.g., 09/04/1986). + * - 'LL': Full month name, day, and year (e.g., September 4, 1986). + * - 'dddd, LL': Day of the week, full month name, day, and year (e.g., Thursday, September 4, 1986). + */ +export const DEFAULT_DATE_FORMATS: string[] = ['L', 'LL', 'dddd, LL']; + +/** + * Array of default inactivity time limits in minutes. + * - Specifies time limits after which a user is considered inactive. + * - Common values: 1, 5, 10, 20, 30 minutes. + */ +export const DEFAULT_INACTIVITY_TIME_LIMITS: number[] = [1, 5, 10, 20, 30]; + +/** + * Array of default activity proof durations in minutes. + * - Defines durations for capturing proof of activity. + * - Common values: 1, 3, 5, 10 minutes. + */ +export const DEFAULT_ACTIVITY_PROOF_DURATIONS: number[] = [1, 3, 5, 10]; + +/** + * Array of default screenshot frequency options in minutes. + * - Determines how frequently screenshots are taken to monitor activity. + * - Common values: 1, 3, 5, 10 minutes. + */ +export const DEFAULT_SCREENSHOT_FREQUENCY_OPTIONS: number[] = [1, 3, 5, 10]; diff --git a/packages/contracts/src/lib/organization.model.ts b/packages/contracts/src/lib/organization.model.ts index cc3c0adc7a7..311cb73f1a5 100644 --- a/packages/contracts/src/lib/organization.model.ts +++ b/packages/contracts/src/lib/organization.model.ts @@ -305,16 +305,6 @@ export interface IKeyValuePair { value: boolean | string; } -export const DEFAULT_STANDARD_WORK_HOURS_PER_DAY = 8; // Adjust the default value if needed -export const DEFAULT_TIME_FORMATS: number[] = [TimeFormatEnum.FORMAT_12_HOURS, TimeFormatEnum.FORMAT_24_HOURS]; -export const DEFAULT_PROFIT_BASED_BONUS = 75; -export const DEFAULT_REVENUE_BASED_BONUS = 10; -export const DEFAULT_INVITE_EXPIRY_PERIOD = 7; -export const DEFAULT_DATE_FORMATS: string[] = ['L', 'LL', 'dddd, LL']; -export const DEFAULT_INACTIVITY_TIME_LIMITS: number[] = [1, 5, 10, 20, 30]; -export const DEFAULT_ACTIVITY_PROOF_DURATIONS: number[] = [1, 3, 5, 10]; -export const DEFAULT_SCREENSHOT_FREQUENCY_OPTIONS: number[] = [1, 3, 5, 10]; - export interface IOrganizationTimerSetting { allowTrackInactivity?: boolean; inactivityTimeLimit?: number; diff --git a/packages/core/package.json b/packages/core/package.json index 034c9405d74..3201326f019 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -43,6 +43,7 @@ "@gauzy/auth": "^0.1.0", "@gauzy/common": "^0.1.0", "@gauzy/config": "^0.1.0", + "@gauzy/constants": "^0.1.0", "@gauzy/contracts": "^0.1.0", "@gauzy/plugin": "^0.1.0", "@gauzy/utils": "^0.1.0", diff --git a/packages/core/src/lib/employee-statistics/employee-statistics.service.ts b/packages/core/src/lib/employee-statistics/employee-statistics.service.ts index 1df9c61f8d4..6cbf990d134 100644 --- a/packages/core/src/lib/employee-statistics/employee-statistics.service.ts +++ b/packages/core/src/lib/employee-statistics/employee-statistics.service.ts @@ -1,14 +1,13 @@ +import { Injectable } from '@nestjs/common'; +import * as moment from 'moment'; +import { DEFAULT_PROFIT_BASED_BONUS, DEFAULT_REVENUE_BASED_BONUS } from '@gauzy/constants'; import { BonusTypeEnum, IEmployeeStatistics, IEmployeeStatisticsFindInput, - DEFAULT_PROFIT_BASED_BONUS, - DEFAULT_REVENUE_BASED_BONUS, IMonthAggregatedSplitExpense, IDateRangePicker } from '@gauzy/contracts'; -import { Injectable } from '@nestjs/common'; -import * as moment from 'moment'; import { EmployeeService } from '../employee/employee.service'; import { ExpenseService } from '../expense/expense.service'; import { IncomeService } from '../income/income.service'; diff --git a/packages/core/src/lib/invite/invite.service.ts b/packages/core/src/lib/invite/invite.service.ts index d8c574040d5..594e92c4cdf 100644 --- a/packages/core/src/lib/invite/invite.service.ts +++ b/packages/core/src/lib/invite/invite.service.ts @@ -5,6 +5,7 @@ import { FindManyOptions, FindOptionsWhere, In, IsNull, MoreThanOrEqual, Not, Se import { addDays } from 'date-fns'; import { pick } from 'underscore'; import { ConfigService, environment } from '@gauzy/config'; +import { DEFAULT_INVITE_EXPIRY_PERIOD } from '@gauzy/constants'; import { ICreateEmailInvitesInput, ICreateEmailInvitesOutput, @@ -14,7 +15,6 @@ import { ICreateOrganizationContactInviteInput, RolesEnum, LanguagesEnum, - DEFAULT_INVITE_EXPIRY_PERIOD, IOrganization, IEmployee, IRole, diff --git a/packages/core/src/lib/organization/organization.entity.ts b/packages/core/src/lib/organization/organization.entity.ts index e108ad35f32..0978e5a641e 100644 --- a/packages/core/src/lib/organization/organization.entity.ts +++ b/packages/core/src/lib/organization/organization.entity.ts @@ -2,6 +2,11 @@ import { JoinColumn, JoinTable, RelationId } from 'typeorm'; import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { Transform, TransformFnParams } from 'class-transformer'; import { IsBoolean, IsEnum, IsNotEmpty, IsNumber, IsOptional, IsString, IsUUID, Max, Min } from 'class-validator'; +import { + DEFAULT_INVITE_EXPIRY_PERIOD, + DEFAULT_PROFIT_BASED_BONUS, + DEFAULT_STANDARD_WORK_HOURS_PER_DAY +} from '@gauzy/constants'; import { DefaultValueDateTypeEnum, IOrganization, @@ -23,11 +28,8 @@ import { IReportOrganization, IImageAsset, ID, - DEFAULT_PROFIT_BASED_BONUS, BonusTypeEnum, - CurrenciesEnum, - DEFAULT_INVITE_EXPIRY_PERIOD, - DEFAULT_STANDARD_WORK_HOURS_PER_DAY + CurrenciesEnum } from '@gauzy/contracts'; import { AccountingTemplate, diff --git a/packages/core/src/lib/organization/organization.seed.ts b/packages/core/src/lib/organization/organization.seed.ts index 6e633438fc1..628b5bed341 100644 --- a/packages/core/src/lib/organization/organization.seed.ts +++ b/packages/core/src/lib/organization/organization.seed.ts @@ -3,6 +3,7 @@ import * as moment from 'moment'; import * as timezone from 'moment-timezone'; import { DataSource } from 'typeorm'; import { faker } from '@faker-js/faker'; +import { DEFAULT_DATE_FORMATS } from '@gauzy/constants'; import { DefaultValueDateTypeEnum, BonusTypeEnum, @@ -10,7 +11,6 @@ import { AlignmentOptions, IOrganization, ITenant, - DEFAULT_DATE_FORMATS, ISkill, IContact } from '@gauzy/contracts'; @@ -27,16 +27,16 @@ import { Contact, Organization, Skill } from '../core/entities/internal'; * @returns A promise that resolves to the default organization if it exists, otherwise `null`. */ export const getDefaultOrganization = async ( - dataSource: DataSource, - tenant: ITenant + dataSource: DataSource, + tenant: ITenant ): Promise => { - if (!tenant?.id) { - throw new Error('Invalid tenant: Tenant ID is required.'); - } + if (!tenant?.id) { + throw new Error('Invalid tenant: Tenant ID is required.'); + } - return dataSource.getRepository(Organization).findOne({ - where: { tenantId: tenant.id, isDefault: true }, - }); + return dataSource.getRepository(Organization).findOne({ + where: { tenantId: tenant.id, isDefault: true } + }); }; /** @@ -47,17 +47,14 @@ export const getDefaultOrganization = async ( * @returns A promise that resolves to an array of organizations for the specified tenant. * @throws Error if the tenant ID is not provided or invalid. */ -export const getDefaultOrganizations = async ( - dataSource: DataSource, - tenant: ITenant -): Promise => { - if (!tenant?.id) { - throw new Error('Invalid tenant: Tenant ID is required.'); - } - - return dataSource.getRepository(Organization).find({ - where: { tenantId: tenant.id }, - }); +export const getDefaultOrganizations = async (dataSource: DataSource, tenant: ITenant): Promise => { + if (!tenant?.id) { + throw new Error('Invalid tenant: Tenant ID is required.'); + } + + return dataSource.getRepository(Organization).find({ + where: { tenantId: tenant.id } + }); }; let defaultOrganizationsInserted = []; @@ -76,64 +73,64 @@ export const createDefaultOrganizations = async ( organizations: any ): Promise => { if (!tenant) { - throw new Error('Tenant is required to create default organizations.'); - } + throw new Error('Tenant is required to create default organizations.'); + } const defaultOrganizations: IOrganization[] = []; const skills = await getRandomSkills(dataSource, faker.number.int({ min: 1, max: 4 })); - const contacts = await getRandomContacts(dataSource); + const contacts = await getRandomContacts(dataSource); for (const organization of organizations) { - const { name, currency, defaultValueDateType, imageUrl, isDefault, totalEmployees } = organization; - - const defaultOrganization = new Organization(); - defaultOrganization.name = name; - defaultOrganization.isDefault = isDefault || false; - defaultOrganization.totalEmployees = totalEmployees || 0; - defaultOrganization.profile_link = generateLink(name); - defaultOrganization.currency = currency || 'USD'; - defaultOrganization.defaultValueDateType = defaultValueDateType || 'CURRENT_DATE'; + const { name, currency, defaultValueDateType, imageUrl, isDefault, totalEmployees } = organization; + + const defaultOrganization = new Organization(); + defaultOrganization.name = name; + defaultOrganization.isDefault = isDefault || false; + defaultOrganization.totalEmployees = totalEmployees || 0; + defaultOrganization.profile_link = generateLink(name); + defaultOrganization.currency = currency || 'USD'; + defaultOrganization.defaultValueDateType = defaultValueDateType || 'CURRENT_DATE'; defaultOrganization.imageUrl = imageUrl; - defaultOrganization.invitesAllowed = true; - defaultOrganization.bonusType = BonusTypeEnum.REVENUE_BASED_BONUS; - defaultOrganization.bonusPercentage = 10; - defaultOrganization.registrationDate = faker.date.past({ years: 5 }); - defaultOrganization.overview = faker.lorem.sentence(); - defaultOrganization.short_description = faker.lorem.sentence(); - defaultOrganization.client_focus = faker.lorem.sentence(); - defaultOrganization.show_profits = false; - defaultOrganization.show_bonuses_paid = false; - defaultOrganization.show_income = false; - defaultOrganization.show_total_hours = false; - defaultOrganization.show_projects_count = true; - defaultOrganization.show_minimum_project_size = true; - defaultOrganization.show_clients_count = true; - defaultOrganization.show_clients = true; - defaultOrganization.show_employees_count = true; - defaultOrganization.banner = faker.lorem.sentence(); - defaultOrganization.skills = skills; - defaultOrganization.brandColor = faker.internet.color(); - defaultOrganization.timeZone = faker.helpers.arrayElement( - timezone.tz.names().filter((zone) => zone.includes('/')) - ); - defaultOrganization.dateFormat = faker.helpers.arrayElement(DEFAULT_DATE_FORMATS); - defaultOrganization.contact = getRandomElement(contacts); - defaultOrganization.defaultAlignmentType = faker.helpers.arrayElement(Object.keys(AlignmentOptions)); - defaultOrganization.fiscalStartDate = moment().add(faker.number.int(10), 'days').toDate(); - defaultOrganization.fiscalEndDate = moment(defaultOrganization.fiscalStartDate) - .add(faker.number.int({ min: 10, max: 20 }), 'days') - .toDate(); - defaultOrganization.futureDateAllowed = true; - defaultOrganization.inviteExpiryPeriod = faker.number.int(50); - defaultOrganization.numberFormat = faker.helpers.arrayElement(['USD', 'BGN', 'ILS']); - defaultOrganization.officialName = faker.company.name(); - defaultOrganization.separateInvoiceItemTaxAndDiscount = faker.datatype.boolean(); - defaultOrganization.startWeekOn = WeekDaysEnum.MONDAY; - defaultOrganization.tenant = tenant; - defaultOrganization.valueDate = moment().add(faker.number.int(10), 'days').toDate(); - - defaultOrganizations.push(defaultOrganization); - } + defaultOrganization.invitesAllowed = true; + defaultOrganization.bonusType = BonusTypeEnum.REVENUE_BASED_BONUS; + defaultOrganization.bonusPercentage = 10; + defaultOrganization.registrationDate = faker.date.past({ years: 5 }); + defaultOrganization.overview = faker.lorem.sentence(); + defaultOrganization.short_description = faker.lorem.sentence(); + defaultOrganization.client_focus = faker.lorem.sentence(); + defaultOrganization.show_profits = false; + defaultOrganization.show_bonuses_paid = false; + defaultOrganization.show_income = false; + defaultOrganization.show_total_hours = false; + defaultOrganization.show_projects_count = true; + defaultOrganization.show_minimum_project_size = true; + defaultOrganization.show_clients_count = true; + defaultOrganization.show_clients = true; + defaultOrganization.show_employees_count = true; + defaultOrganization.banner = faker.lorem.sentence(); + defaultOrganization.skills = skills; + defaultOrganization.brandColor = faker.internet.color(); + defaultOrganization.timeZone = faker.helpers.arrayElement( + timezone.tz.names().filter((zone) => zone.includes('/')) + ); + defaultOrganization.dateFormat = faker.helpers.arrayElement(DEFAULT_DATE_FORMATS); + defaultOrganization.contact = getRandomElement(contacts); + defaultOrganization.defaultAlignmentType = faker.helpers.arrayElement(Object.keys(AlignmentOptions)); + defaultOrganization.fiscalStartDate = moment().add(faker.number.int(10), 'days').toDate(); + defaultOrganization.fiscalEndDate = moment(defaultOrganization.fiscalStartDate) + .add(faker.number.int({ min: 10, max: 20 }), 'days') + .toDate(); + defaultOrganization.futureDateAllowed = true; + defaultOrganization.inviteExpiryPeriod = faker.number.int(50); + defaultOrganization.numberFormat = faker.helpers.arrayElement(['USD', 'BGN', 'ILS']); + defaultOrganization.officialName = faker.company.name(); + defaultOrganization.separateInvoiceItemTaxAndDiscount = faker.datatype.boolean(); + defaultOrganization.startWeekOn = WeekDaysEnum.MONDAY; + defaultOrganization.tenant = tenant; + defaultOrganization.valueDate = moment().add(faker.number.int(10), 'days').toDate(); + + defaultOrganizations.push(defaultOrganization); + } await insertOrganizations(dataSource, defaultOrganizations); defaultOrganizationsInserted = [...defaultOrganizations]; @@ -150,44 +147,43 @@ export const createDefaultOrganizations = async ( * @returns A promise that resolves to a map of tenants and their corresponding organizations. */ export const createRandomOrganizations = async ( - dataSource: DataSource, - tenants: ITenant[], - organizationsPerTenant: number + dataSource: DataSource, + tenants: ITenant[], + organizationsPerTenant: number ): Promise> => { - if (!tenants || tenants.length === 0) { - throw new Error('Tenants are required to create random organizations.'); - } - - const skills = await getRandomSkills(dataSource, faker.number.int({ min: 1, max: 4 })); - const defaultDateTypes = Object.values(DefaultValueDateTypeEnum); - const tenantOrganizations: Map = new Map(); - - for await (const tenant of tenants) { - const randomOrganizations: IOrganization[] = []; - - if (tenant.name === 'Ever') { - tenantOrganizations.set(tenant, defaultOrganizationsInserted); - } else { - for (let index = 0; index < organizationsPerTenant; index++) { - const organization = await generateRandomOrganization( - tenant, - index === 0, // Set the first organization as default - defaultDateTypes[index % defaultDateTypes.length], - skills, - dataSource - ); - randomOrganizations.push(organization); - } + if (!tenants || tenants.length === 0) { + throw new Error('Tenants are required to create random organizations.'); + } + + const skills = await getRandomSkills(dataSource, faker.number.int({ min: 1, max: 4 })); + const defaultDateTypes = Object.values(DefaultValueDateTypeEnum); + const tenantOrganizations: Map = new Map(); + + for await (const tenant of tenants) { + const randomOrganizations: IOrganization[] = []; + + if (tenant.name === 'Ever') { + tenantOrganizations.set(tenant, defaultOrganizationsInserted); + } else { + for (let index = 0; index < organizationsPerTenant; index++) { + const organization = await generateRandomOrganization( + tenant, + index === 0, // Set the first organization as default + defaultDateTypes[index % defaultDateTypes.length], + skills, + dataSource + ); + randomOrganizations.push(organization); + } await insertOrganizations(dataSource, randomOrganizations); - tenantOrganizations.set(tenant, randomOrganizations); - } - } + tenantOrganizations.set(tenant, randomOrganizations); + } + } - return tenantOrganizations; + return tenantOrganizations; }; - /** * Generates a random organization entity. * @@ -199,62 +195,60 @@ export const createRandomOrganizations = async ( * @returns A randomly generated organization entity. */ const generateRandomOrganization = async ( - tenant: ITenant, - isDefault: boolean, - defaultValueDateType: DefaultValueDateTypeEnum, - skills: ISkill[], - dataSource: DataSource + tenant: ITenant, + isDefault: boolean, + defaultValueDateType: DefaultValueDateTypeEnum, + skills: ISkill[], + dataSource: DataSource ): Promise => { - const timeZone = faker.helpers.arrayElement(timezone.tz.names().filter((zone) => zone.includes('/'))); - const companyName = faker.company.name(); - const logoAbbreviation = _extractLogoAbbreviation(companyName); - const contacts = await getRandomContacts(dataSource); - const { bonusType, bonusPercentage } = randomBonus(); - - const organization = new Organization(); - organization.name = companyName; - organization.isDefault = isDefault; - organization.totalEmployees = 5; - organization.profile_link = generateLink(companyName); - organization.currency = env.defaultCurrency; - organization.defaultValueDateType = defaultValueDateType; - organization.imageUrl = getDummyImage(330, 300, logoAbbreviation); - organization.invitesAllowed = true; - organization.bonusType = bonusType; - organization.bonusPercentage = bonusPercentage; - organization.registrationDate = faker.date.past({ years: Math.floor(Math.random() * 10) + 1 }); - organization.overview = faker.lorem.sentence(); - organization.short_description = faker.lorem.sentence(); - organization.client_focus = faker.lorem.sentence(); - organization.show_profits = false; - organization.show_bonuses_paid = false; - organization.show_income = false; - organization.show_total_hours = false; - organization.show_projects_count = true; - organization.show_minimum_project_size = true; - organization.show_clients_count = true; - organization.show_employees_count = true; - organization.banner = faker.lorem.sentence(); - organization.skills = skills; - organization.brandColor = faker.internet.color(); - organization.contact = getRandomElement(contacts); - organization.timeZone = timeZone; - organization.dateFormat = faker.helpers.arrayElement(DEFAULT_DATE_FORMATS); - organization.defaultAlignmentType = faker.helpers.arrayElement(Object.keys(AlignmentOptions)); - organization.fiscalStartDate = moment().add(faker.number.int(10), 'days').toDate(); - organization.fiscalEndDate = moment(organization.fiscalStartDate) - .add(faker.number.int(10), 'days') - .toDate(); - organization.futureDateAllowed = true; - organization.inviteExpiryPeriod = faker.number.int(50); - organization.numberFormat = faker.helpers.arrayElement(['USD', 'BGN', 'ILS']); - organization.officialName = faker.company.name(); - organization.separateInvoiceItemTaxAndDiscount = faker.datatype.boolean(); - organization.startWeekOn = WeekDaysEnum.MONDAY; - organization.tenant = tenant; - organization.valueDate = moment().add(faker.number.int(10), 'days').toDate(); - - return organization; + const timeZone = faker.helpers.arrayElement(timezone.tz.names().filter((zone) => zone.includes('/'))); + const companyName = faker.company.name(); + const logoAbbreviation = _extractLogoAbbreviation(companyName); + const contacts = await getRandomContacts(dataSource); + const { bonusType, bonusPercentage } = randomBonus(); + + const organization = new Organization(); + organization.name = companyName; + organization.isDefault = isDefault; + organization.totalEmployees = 5; + organization.profile_link = generateLink(companyName); + organization.currency = env.defaultCurrency; + organization.defaultValueDateType = defaultValueDateType; + organization.imageUrl = getDummyImage(330, 300, logoAbbreviation); + organization.invitesAllowed = true; + organization.bonusType = bonusType; + organization.bonusPercentage = bonusPercentage; + organization.registrationDate = faker.date.past({ years: Math.floor(Math.random() * 10) + 1 }); + organization.overview = faker.lorem.sentence(); + organization.short_description = faker.lorem.sentence(); + organization.client_focus = faker.lorem.sentence(); + organization.show_profits = false; + organization.show_bonuses_paid = false; + organization.show_income = false; + organization.show_total_hours = false; + organization.show_projects_count = true; + organization.show_minimum_project_size = true; + organization.show_clients_count = true; + organization.show_employees_count = true; + organization.banner = faker.lorem.sentence(); + organization.skills = skills; + organization.brandColor = faker.internet.color(); + organization.contact = getRandomElement(contacts); + organization.timeZone = timeZone; + organization.dateFormat = faker.helpers.arrayElement(DEFAULT_DATE_FORMATS); + organization.defaultAlignmentType = faker.helpers.arrayElement(Object.keys(AlignmentOptions)); + organization.fiscalStartDate = moment().add(faker.number.int(10), 'days').toDate(); + organization.fiscalEndDate = moment(organization.fiscalStartDate).add(faker.number.int(10), 'days').toDate(); + organization.futureDateAllowed = true; + organization.inviteExpiryPeriod = faker.number.int(50); + organization.numberFormat = faker.helpers.arrayElement(['USD', 'BGN', 'ILS']); + organization.officialName = faker.company.name(); + organization.separateInvoiceItemTaxAndDiscount = faker.datatype.boolean(); + organization.startWeekOn = WeekDaysEnum.MONDAY; + organization.tenant = tenant; + organization.valueDate = moment().add(faker.number.int(10), 'days').toDate(); + + return organization; }; /** @@ -265,19 +259,16 @@ const generateRandomOrganization = async ( * @returns A promise that resolves once the organizations are successfully inserted. * @throws Error if the `organizations` array is empty or invalid. */ -const insertOrganizations = async ( - dataSource: DataSource, - organizations: IOrganization[] -): Promise => { - if (!organizations || organizations.length === 0) { - throw new Error('The organizations array must not be empty.'); - } - - try { - await dataSource.manager.save(organizations); - } catch (error) { - throw new Error(`Failed to insert organizations: ${error.message}`); - } +const insertOrganizations = async (dataSource: DataSource, organizations: IOrganization[]): Promise => { + if (!organizations || organizations.length === 0) { + throw new Error('The organizations array must not be empty.'); + } + + try { + await dataSource.manager.save(organizations); + } catch (error) { + throw new Error(`Failed to insert organizations: ${error.message}`); + } }; /** @@ -290,38 +281,35 @@ const insertOrganizations = async ( * @throws Error if `companyName` is empty or not a valid string. */ const _extractLogoAbbreviation = (companyName: string): string => { - if (!companyName || typeof companyName !== 'string') { - throw new Error('Invalid company name. A non-empty string is required.'); - } + if (!companyName || typeof companyName !== 'string') { + throw new Error('Invalid company name. A non-empty string is required.'); + } - const trimmedName = companyName.trim(); - const words = trimmedName.split(/\s+/); // Split by one or more spaces + const trimmedName = companyName.trim(); + const words = trimmedName.split(/\s+/); // Split by one or more spaces - // Get the first letter of the first word - const firstLetter = words[0][0]; + // Get the first letter of the first word + const firstLetter = words[0][0]; - // Get the first letter of the last word if there are multiple words - const lastLetter = words.length > 1 ? words[words.length - 1][0] : ''; + // Get the first letter of the last word if there are multiple words + const lastLetter = words.length > 1 ? words[words.length - 1][0] : ''; - return `${firstLetter}${lastLetter}`.toUpperCase(); + return `${firstLetter}${lastLetter}`.toUpperCase(); }; - /** * Generates a random bonus type and percentage. * * @returns An object containing the bonus type and the corresponding percentage. */ const randomBonus = (): { bonusType: BonusTypeEnum; bonusPercentage: number } => { - const randomNumberBetween = (min: number, max: number): number => Math.floor(Math.random() * (max - min + 1) + min); + const randomNumberBetween = (min: number, max: number): number => Math.floor(Math.random() * (max - min + 1) + min); - const bonusType = Object.values(BonusTypeEnum)[randomNumberBetween(0, 1)]; - const bonusPercentage = - bonusType === BonusTypeEnum.PROFIT_BASED_BONUS - ? randomNumberBetween(65, 75) - : randomNumberBetween(5, 10); + const bonusType = Object.values(BonusTypeEnum)[randomNumberBetween(0, 1)]; + const bonusPercentage = + bonusType === BonusTypeEnum.PROFIT_BASED_BONUS ? randomNumberBetween(65, 75) : randomNumberBetween(5, 10); - return { bonusType, bonusPercentage }; + return { bonusType, bonusPercentage }; }; /** @@ -331,10 +319,10 @@ const randomBonus = (): { bonusType: BonusTypeEnum; bonusPercentage: number } => * @returns The generated slug as a string. */ const generateLink = (name: string): string => { - if (!name) { - throw new Error('Name is required to generate a link.'); - } - return name.replace(/[^A-Z0-9]+/gi, '-').toLowerCase(); + if (!name) { + throw new Error('Name is required to generate a link.'); + } + return name.replace(/[^A-Z0-9]+/gi, '-').toLowerCase(); }; /** @@ -345,19 +333,16 @@ const generateLink = (name: string): string => { * @returns A promise that resolves to an array of randomly selected skills. * @throws Error if there is an issue retrieving skills from the database. */ -const getRandomSkills = async ( - dataSource: DataSource, - count: number -): Promise => { - if (!dataSource) { - throw new Error('Invalid data source: DataSource is required.'); - } - - // Retrieve all skills from the database - const skills = await dataSource.manager.find(Skill, {}); - - // Shuffle and select a subset of skills - return chain(skills).shuffle().take(count).value(); +const getRandomSkills = async (dataSource: DataSource, count: number): Promise => { + if (!dataSource) { + throw new Error('Invalid data source: DataSource is required.'); + } + + // Retrieve all skills from the database + const skills = await dataSource.manager.find(Skill, {}); + + // Shuffle and select a subset of skills + return chain(skills).shuffle().take(count).value(); }; /** @@ -368,10 +353,10 @@ const getRandomSkills = async ( * @throws Error if the data source is invalid or contacts cannot be retrieved. */ const getRandomContacts = async (dataSource: DataSource): Promise => { - if (!dataSource) { - throw new Error('Invalid data source: DataSource is required.'); - } + if (!dataSource) { + throw new Error('Invalid data source: DataSource is required.'); + } - // Retrieve all contacts from the database - return await dataSource.getRepository(Contact).find(); + // Retrieve all contacts from the database + return await dataSource.getRepository(Contact).find(); }; diff --git a/packages/core/src/lib/tenant/tenant.entity.ts b/packages/core/src/lib/tenant/tenant.entity.ts index 67548bb3628..4e5b7529b15 100644 --- a/packages/core/src/lib/tenant/tenant.entity.ts +++ b/packages/core/src/lib/tenant/tenant.entity.ts @@ -1,15 +1,8 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { JoinColumn, RelationId } from 'typeorm'; import { IsNumber, IsOptional, IsUUID, Max, Min } from 'class-validator'; -import { - ITenant, - IOrganization, - IRolePermission, - IFeatureOrganization, - DEFAULT_STANDARD_WORK_HOURS_PER_DAY, - ID, - IImageAsset -} from '@gauzy/contracts'; +import { DEFAULT_STANDARD_WORK_HOURS_PER_DAY } from '@gauzy/constants'; +import { ITenant, IOrganization, IRolePermission, IFeatureOrganization, ID, IImageAsset } from '@gauzy/contracts'; import { BaseEntity, FeatureOrganization, ImageAsset, Organization, RolePermission } from '../core/entities/internal'; import { ColumnIndex, diff --git a/packages/ui-core/package.json b/packages/ui-core/package.json index b8dea49adfc..8d78d6040d1 100644 --- a/packages/ui-core/package.json +++ b/packages/ui-core/package.json @@ -52,6 +52,7 @@ "@fullcalendar/interaction": "^6.1.15", "@fullcalendar/moment-timezone": "^6.1.15", "@fullcalendar/timegrid": "^6.1.15", + "@gauzy/constants": "^0.1.0", "@gauzy/contracts": "^0.1.0", "@jitsu/js": "^1.9.12", "@kurkle/color": "^0.3.2", diff --git a/packages/ui-core/shared/src/lib/organizations/organizations-step-form/organizations-step-form.component.ts b/packages/ui-core/shared/src/lib/organizations/organizations-step-form/organizations-step-form.component.ts index b50c6e59dcd..0c5026851ef 100644 --- a/packages/ui-core/shared/src/lib/organizations/organizations-step-form/organizations-step-form.component.ts +++ b/packages/ui-core/shared/src/lib/organizations/organizations-step-form/organizations-step-form.component.ts @@ -16,6 +16,7 @@ import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { LatLng } from 'leaflet'; import * as moment from 'moment'; import { filter, tap } from 'rxjs/operators'; +import { DEFAULT_DATE_FORMATS } from '@gauzy/constants'; import { BonusTypeEnum, ICountry, @@ -26,7 +27,6 @@ import { ICurrency, IUser, CurrenciesEnum, - DEFAULT_DATE_FORMATS, IImageAsset } from '@gauzy/contracts'; import { environment as ENV } from '@gauzy/ui-config'; diff --git a/packages/ui-core/shared/src/lib/report/charts/line-chart/line-chart.component.ts b/packages/ui-core/shared/src/lib/report/charts/line-chart/line-chart.component.ts index 0563d07af2c..30fad653658 100644 --- a/packages/ui-core/shared/src/lib/report/charts/line-chart/line-chart.component.ts +++ b/packages/ui-core/shared/src/lib/report/charts/line-chart/line-chart.component.ts @@ -15,7 +15,7 @@ import { TranslateService } from '@ngx-translate/core'; import { ActiveElement, Chart, ChartConfiguration, ChartDataset, ChartEvent, ChartType, TooltipItem } from 'chart.js'; import { BaseChartDirective } from 'ng2-charts'; import annotationPlugin, { AnnotationPluginOptions } from 'chartjs-plugin-annotation'; -import { DEFAULT_STANDARD_WORK_HOURS_PER_DAY } from '@gauzy/contracts'; +import { DEFAULT_STANDARD_WORK_HOURS_PER_DAY } from '@gauzy/constants'; import { TranslationBaseComponent } from '@gauzy/ui-core/i18n'; import { ChartUtil } from './chart-utils'; diff --git a/packages/ui-core/shared/src/lib/timesheet/gauzy-filters/timezone-filter/timezone-filter.component.ts b/packages/ui-core/shared/src/lib/timesheet/gauzy-filters/timezone-filter/timezone-filter.component.ts index f4e54392122..afdbc0325f7 100644 --- a/packages/ui-core/shared/src/lib/timesheet/gauzy-filters/timezone-filter/timezone-filter.component.ts +++ b/packages/ui-core/shared/src/lib/timesheet/gauzy-filters/timezone-filter/timezone-filter.component.ts @@ -6,14 +6,8 @@ import { tap } from 'rxjs/operators'; import { NbPopoverDirective } from '@nebular/theme'; import { TranslateService } from '@ngx-translate/core'; import * as moment from 'moment-timezone'; -import { - DEFAULT_TIME_FORMATS, - IOrganization, - IUser, - PermissionsEnum, - TimeFormatEnum, - TimeZoneEnum -} from '@gauzy/contracts'; +import { DEFAULT_TIME_FORMATS } from '@gauzy/constants'; +import { IOrganization, IUser, PermissionsEnum, TimeFormatEnum, TimeZoneEnum } from '@gauzy/contracts'; import { distinctUntilChange } from '@gauzy/ui-core/common'; import { NavigationService, Store } from '@gauzy/ui-core/core'; import { TranslationBaseComponent } from '@gauzy/ui-core/i18n'; diff --git a/packages/ui-core/shared/src/lib/user/edit-profile-form/edit-profile-form.component.ts b/packages/ui-core/shared/src/lib/user/edit-profile-form/edit-profile-form.component.ts index 51d1b5c0034..48f0bfc50a9 100644 --- a/packages/ui-core/shared/src/lib/user/edit-profile-form/edit-profile-form.component.ts +++ b/packages/ui-core/shared/src/lib/user/edit-profile-form/edit-profile-form.component.ts @@ -1,8 +1,9 @@ import { Component, OnInit, OnDestroy, Input, Output, EventEmitter } from '@angular/core'; import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; -import { IUser, ITag, IRole, IUserUpdateInput, RolesEnum, IImageAsset, DEFAULT_TIME_FORMATS } from '@gauzy/contracts'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { Subject, filter, debounceTime, tap, firstValueFrom } from 'rxjs'; +import { DEFAULT_TIME_FORMATS } from '@gauzy/constants'; +import { IUser, ITag, IRole, IUserUpdateInput, RolesEnum, IImageAsset } from '@gauzy/contracts'; import { AuthService, EmailValidator, @@ -117,9 +118,7 @@ export class EditProfileFormComponent implements OnInit, OnDestroy { async excludeRoles(): Promise { try { // Check if the user has the SUPER_ADMIN role - const hasSuperAdminRole = await firstValueFrom( - this._authService.hasRole([RolesEnum.SUPER_ADMIN]) - ); + const hasSuperAdminRole = await firstValueFrom(this._authService.hasRole([RolesEnum.SUPER_ADMIN])); // Add SUPER_ADMIN to the excludes list if the user lacks the role if (!hasSuperAdminRole) { From f02fd16b77067bfeee8cc5e3284f950926e2eb3b Mon Sep 17 00:00:00 2001 From: "Rahul R." Date: Thu, 23 Jan 2025 16:19:34 +0530 Subject: [PATCH 3/3] fix(constants): docker build for @gauzy/constants --- .deploy/api/Dockerfile | 2 ++ .deploy/webapp/Dockerfile | 1 + apps/desktop/src/package.json | 4 ++-- apps/server-api/src/package.json | 6 +++--- apps/server/src/package.json | 6 +++--- package.json | 21 ++++++++++++--------- packages/constants/tsconfig.json | 10 +++++----- packages/constants/tsconfig.lib.json | 8 +++++++- tsconfig.json | 2 +- 9 files changed, 36 insertions(+), 24 deletions(-) diff --git a/.deploy/api/Dockerfile b/.deploy/api/Dockerfile index 4ad391039c5..13afa6f9c8b 100644 --- a/.deploy/api/Dockerfile +++ b/.deploy/api/Dockerfile @@ -136,6 +136,7 @@ COPY --chown=node:node apps/api/package.json ./apps/api/ COPY --chown=node:node packages/common/package.json ./packages/common/ COPY --chown=node:node packages/utils/package.json ./packages/utils/ COPY --chown=node:node packages/config/package.json ./packages/config/ +COPY --chown=node:node packages/constants/package.json ./packages/constants/ COPY --chown=node:node packages/contracts/package.json ./packages/contracts/ COPY --chown=node:node packages/auth/package.json ./packages/auth/ COPY --chown=node:node packages/core/package.json ./packages/core/ @@ -191,6 +192,7 @@ COPY --chown=node:node apps/api/package.json ./apps/api/ COPY --chown=node:node packages/common/package.json ./packages/common/ COPY --chown=node:node packages/utils/package.json ./packages/utils/ COPY --chown=node:node packages/config/package.json ./packages/config/ +COPY --chown=node:node packages/constants/package.json ./packages/constants/ COPY --chown=node:node packages/contracts/package.json ./packages/contracts/ COPY --chown=node:node packages/auth/package.json ./packages/auth/ COPY --chown=node:node packages/core/package.json ./packages/core/ diff --git a/.deploy/webapp/Dockerfile b/.deploy/webapp/Dockerfile index 04f13fd8249..4bd949c2bd9 100644 --- a/.deploy/webapp/Dockerfile +++ b/.deploy/webapp/Dockerfile @@ -91,6 +91,7 @@ COPY --chown=node:node apps/gauzy/package.json ./apps/gauzy/ COPY --chown=node:node packages/common/package.json ./packages/common/ COPY --chown=node:node packages/utils/package.json ./packages/utils/ COPY --chown=node:node packages/config/package.json ./packages/config/ +COPY --chown=node:node packages/constants/package.json ./packages/constants/ COPY --chown=node:node packages/contracts/package.json ./packages/contracts/ COPY --chown=node:node packages/auth/package.json ./packages/auth/ COPY --chown=node:node packages/core/package.json ./packages/core/ diff --git a/apps/desktop/src/package.json b/apps/desktop/src/package.json index ac6dcb7cb90..e02959137e6 100644 --- a/apps/desktop/src/package.json +++ b/apps/desktop/src/package.json @@ -23,7 +23,6 @@ "packages": [ "../../../dist/packages/auth", "../../../dist/packages/common", - "../../../dist/packages/utils", "../../../dist/packages/config", "../../../dist/packages/contracts", "../../../dist/packages/core", @@ -45,7 +44,8 @@ "../../../dist/packages/plugins/product-reviews", "../../../dist/packages/plugins/sentry-tracing", "../../../dist/packages/plugins/videos", - "../../../dist/packages/ui-config" + "../../../dist/packages/ui-config", + "../../../dist/packages/utils" ] }, "build": { diff --git a/apps/server-api/src/package.json b/apps/server-api/src/package.json index d3b555ca566..b3e58fcfb6f 100755 --- a/apps/server-api/src/package.json +++ b/apps/server-api/src/package.json @@ -24,7 +24,6 @@ "packages": [ "../../../dist/packages/auth", "../../../dist/packages/common", - "../../../dist/packages/utils", "../../../dist/packages/config", "../../../dist/packages/contracts", "../../../dist/packages/core", @@ -34,7 +33,8 @@ "../../../dist/packages/plugin", "../../../dist/packages/plugins/integration-ai", "../../../dist/packages/plugins/job-proposal", - "../../../dist/packages/ui-config" + "../../../dist/packages/ui-config", + "../../../dist/packages/utils" ] }, "build": { @@ -135,7 +135,6 @@ "@electron/remote": "^2.0.8", "@fastify/swagger": "^9.4.0", "@gauzy/auth": "file:../../../dist/packages/auth", - "@gauzy/utils": "file:../../../dist/packages/utils", "@gauzy/config": "file:../../../dist/packages/config", "@gauzy/contracts": "file:../../../dist/packages/contracts", "@gauzy/core": "file:../../../dist/packages/core", @@ -158,6 +157,7 @@ "@gauzy/plugin-sentry": "file:../../../dist/packages/plugins/sentry-tracing", "@gauzy/plugin-videos": "file:../../../dist/packages/plugins/videos", "@gauzy/ui-config": "file:../../../dist/packages/ui-config", + "@gauzy/utils": "file:../../../dist/packages/utils", "@sentry/electron": "^4.18.0", "@sentry/node": "^7.101.1", "@sentry/profiling-node": "^7.101.1", diff --git a/apps/server/src/package.json b/apps/server/src/package.json index 8e409024aae..3fccb5c249f 100755 --- a/apps/server/src/package.json +++ b/apps/server/src/package.json @@ -24,7 +24,6 @@ "packages": [ "../../../dist/packages/auth", "../../../dist/packages/common", - "../../../dist/packages/utils", "../../../dist/packages/config", "../../../dist/packages/contracts", "../../../dist/packages/core", @@ -34,7 +33,8 @@ "../../../dist/packages/plugin", "../../../dist/packages/plugins/integration-ai", "../../../dist/packages/plugins/job-proposal", - "../../../dist/packages/ui-config" + "../../../dist/packages/ui-config", + "../../../dist/packages/utils" ] }, "build": { @@ -134,7 +134,6 @@ "@datorama/akita": "^8.0.1", "@electron/remote": "^2.0.8", "@gauzy/auth": "file:../../../dist/packages/auth", - "@gauzy/utils": "file:../../../dist/packages/utils", "@gauzy/config": "file:../../../dist/packages/config", "@gauzy/contracts": "file:../../../dist/packages/contracts", "@gauzy/core": "file:../../../dist/packages/core", @@ -157,6 +156,7 @@ "@gauzy/plugin-sentry": "file:../../../dist/packages/plugins/sentry-tracing", "@gauzy/plugin-videos": "file:../../../dist/packages/plugins/videos", "@gauzy/ui-config": "file:../../../dist/packages/ui-config", + "@gauzy/utils": "file:../../../dist/packages/utils", "@sentry/electron": "^4.18.0", "@sentry/node": "^7.101.1", "@sentry/profiling-node": "^7.101.1", diff --git a/package.json b/package.json index 0aba09e3757..7bd18ead956 100644 --- a/package.json +++ b/package.json @@ -143,6 +143,9 @@ "build:package:utils": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn nx build utils", "build:package:utils:prod": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=12288 yarn nx build utils", "build:package:utils:docker": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=60000 yarn nx build utils", + "build:package:constants": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn nx build constants", + "build:package:constants:prod": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=12288 yarn nx build constants", + "build:package:constants:docker": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=60000 yarn nx build constants", "build:package:contracts": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn nx build contracts", "build:package:contracts:prod": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=12288 yarn nx build contracts", "build:package:contracts:docker": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=60000 yarn nx build contracts", @@ -251,15 +254,15 @@ "build:package:plugin:integration-wakatime": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn nx build plugin-integration-wakatime", "build:package:plugin:integration-wakatime:prod": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=12288 yarn nx build plugin-integration-wakatime", "build:package:plugin:integration-wakatime:docker": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=60000 yarn nx build plugin-integration-wakatime", - "build:package:all": "yarn run build:package:contracts && yarn run build:package:common && yarn run build:package:utils && yarn run build:package:config && yarn run build:package:plugin && yarn run build:package:auth && yarn run build:package:plugins:pre && yarn run build:package:core && yarn run build:package:plugins:post && yarn run build:package:desktop-lib && yarn run build:package:plugin:integration-wakatime && yarn run build:package:desktop-ui-lib", - "build:package:all:prod": "yarn run build:package:contracts:prod && yarn run build:package:common:prod && yarn run build:package:utils:prod && yarn run build:package:config:prod && yarn run build:package:plugin:prod && yarn run build:package:auth:prod && yarn run build:package:plugins:pre:prod && yarn run build:package:core:prod && yarn run build:package:plugins:post:prod && yarn run build:package:desktop-lib:prod && yarn run build:package:plugin:integration-wakatime:prod && yarn run build:package:desktop-ui-lib:prod", - "build:package:all:docker": "yarn run build:package:contracts:docker && yarn run build:package:common:docker && yarn run build:package:utils:docker &&yarn run build:package:config:docker && yarn run build:package:plugin:docker && yarn run build:package:auth:docker && yarn run build:package:plugins:pre:docker && yarn run build:package:core:docker && yarn run build:package:plugins:post:docker && yarn run build:package:desktop-lib:docker && yarn run build:package:plugin:integration-wakatime:docker && yarn run build:package:desktop-ui-lib:docker", - "build:package:api": "yarn run build:package:contracts && yarn run build:package:common && yarn run build:package:utils && yarn run build:package:config && yarn run build:package:plugin && yarn run build:package:auth && yarn run build:package:core && yarn run build:package:plugins:post && yarn run build:package:plugin:integration-wakatime", - "build:package:api:prod": "yarn run build:package:contracts:prod && yarn run build:package:common:prod && yarn run build:package:utils:prod && yarn run build:package:config:prod && yarn run build:package:plugin:prod && yarn run build:package:auth:prod && yarn run build:package:core:prod && yarn run build:package:plugins:post:prod", - "build:package:api:docker": "yarn run build:package:contracts:docker && yarn run build:package:common:docker && yarn run build:package:utils:docker && yarn run build:package:config:docker && yarn run build:package:plugin:docker && yarn run build:package:auth:docker && yarn run build:package:core:docker && yarn run build:package:plugins:post:docker", - "build:package:gauzy": "yarn run build:package:contracts && yarn run build:package:common && yarn run build:package:utils && yarn run build:package:config && yarn run build:package:plugin && yarn run build:package:auth && yarn run build:package:plugins:pre && yarn run build:package:core && yarn run build:package:plugins:post", - "build:package:gauzy:prod": "yarn run build:package:contracts:prod && yarn run build:package:common:prod && yarn run build:package:utils:prod && yarn run build:package:config:prod && yarn run build:package:plugin:prod && yarn run build:package:auth:prod && yarn run build:package:plugins:pre:prod && yarn run build:package:core:prod && yarn run build:package:plugins:post:prod", - "build:package:gauzy:docker": "yarn run build:package:contracts:docker && yarn run build:package:common:docker && yarn run build:package:utils:docker && yarn run build:package:config:docker && yarn run build:package:plugin:docker && yarn run build:package:auth:docker && yarn run build:package:plugins:pre:docker && yarn run build:package:core:docker && yarn run build:package:plugins:post:docker", + "build:package:all": "yarn run build:package:constants && yarn run build:package:contracts && yarn run build:package:common && yarn run build:package:utils && yarn run build:package:config && yarn run build:package:plugin && yarn run build:package:auth && yarn run build:package:plugins:pre && yarn run build:package:core && yarn run build:package:plugins:post && yarn run build:package:desktop-lib && yarn run build:package:plugin:integration-wakatime && yarn run build:package:desktop-ui-lib", + "build:package:all:prod": "yarn run build:package:constants:prod && yarn run build:package:contracts:prod && yarn run build:package:common:prod && yarn run build:package:utils:prod && yarn run build:package:config:prod && yarn run build:package:plugin:prod && yarn run build:package:auth:prod && yarn run build:package:plugins:pre:prod && yarn run build:package:core:prod && yarn run build:package:plugins:post:prod && yarn run build:package:desktop-lib:prod && yarn run build:package:plugin:integration-wakatime:prod && yarn run build:package:desktop-ui-lib:prod", + "build:package:all:docker": "yarn run build:package:constants:docker && yarn run build:package:contracts:docker && yarn run build:package:common:docker && yarn run build:package:utils:docker &&yarn run build:package:config:docker && yarn run build:package:plugin:docker && yarn run build:package:auth:docker && yarn run build:package:plugins:pre:docker && yarn run build:package:core:docker && yarn run build:package:plugins:post:docker && yarn run build:package:desktop-lib:docker && yarn run build:package:plugin:integration-wakatime:docker && yarn run build:package:desktop-ui-lib:docker", + "build:package:api": "yarn run build:package:constants && yarn run build:package:contracts && yarn run build:package:common && yarn run build:package:utils && yarn run build:package:config && yarn run build:package:plugin && yarn run build:package:auth && yarn run build:package:core && yarn run build:package:plugins:post && yarn run build:package:plugin:integration-wakatime", + "build:package:api:prod": "yarn run build:package:constants:prod && yarn run build:package:contracts:prod && yarn run build:package:common:prod && yarn run build:package:utils:prod && yarn run build:package:config:prod && yarn run build:package:plugin:prod && yarn run build:package:auth:prod && yarn run build:package:core:prod && yarn run build:package:plugins:post:prod", + "build:package:api:docker": "yarn run build:package:constants:docker && yarn run build:package:contracts:docker && yarn run build:package:common:docker && yarn run build:package:utils:docker && yarn run build:package:config:docker && yarn run build:package:plugin:docker && yarn run build:package:auth:docker && yarn run build:package:core:docker && yarn run build:package:plugins:post:docker", + "build:package:gauzy": "yarn run build:package:constants && yarn run build:package:contracts && yarn run build:package:common && yarn run build:package:utils && yarn run build:package:config && yarn run build:package:plugin && yarn run build:package:auth && yarn run build:package:plugins:pre && yarn run build:package:core && yarn run build:package:plugins:post", + "build:package:gauzy:prod": "yarn run build:package:constants:prod && yarn run build:package:contracts:prod && yarn run build:package:common:prod && yarn run build:package:utils:prod && yarn run build:package:config:prod && yarn run build:package:plugin:prod && yarn run build:package:auth:prod && yarn run build:package:plugins:pre:prod && yarn run build:package:core:prod && yarn run build:package:plugins:post:prod", + "build:package:gauzy:docker": "yarn run build:package:constants:docker && yarn run build:package:contracts:docker && yarn run build:package:common:docker && yarn run build:package:utils:docker && yarn run build:package:config:docker && yarn run build:package:plugin:docker && yarn run build:package:auth:docker && yarn run build:package:plugins:pre:docker && yarn run build:package:core:docker && yarn run build:package:plugins:post:docker", "copy-files-desktop": "copyfiles -f packages/core/src/**/*.gql dist/apps/desktop/data/", "prepare:desktop-timer": "yarn run postinstall.electron && tsc -p apps/desktop-timer/tsconfig.electron.json", "build:desktop-timer": "cross-env NODE_ENV=production yarn copy-files-i18n-desktop-timer && yarn run postinstall.electron && yarn run config:prod && yarn run config:desktop-timer:prod && yarn build:package:all:prod && yarn run pack:desktop-timer && yarn run generate:icons:desktop-timer --environment=prod && yarn ng:prod build desktop-timer --base-href=./ && yarn run prepare:desktop-timer && yarn ng:prod build desktop-api --configuration=production --output-path=dist/apps/desktop-timer/desktop-api && yarn run copy-assets-gauzy-timer", diff --git a/packages/constants/tsconfig.json b/packages/constants/tsconfig.json index f762511ee1d..421318cc65b 100644 --- a/packages/constants/tsconfig.json +++ b/packages/constants/tsconfig.json @@ -2,11 +2,11 @@ "extends": "../../tsconfig.json", "compilerOptions": { "forceConsistentCasingInFileNames": true, - "strict": true, - "noImplicitOverride": true, - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true, - "noPropertyAccessFromIndexSignature": true + "strict": false, + "noImplicitOverride": false, + "noImplicitReturns": false, + "noFallthroughCasesInSwitch": false, + "noPropertyAccessFromIndexSignature": false }, "files": [], "include": [], diff --git a/packages/constants/tsconfig.lib.json b/packages/constants/tsconfig.lib.json index 94b20c39e81..8f1bc78a2de 100644 --- a/packages/constants/tsconfig.lib.json +++ b/packages/constants/tsconfig.lib.json @@ -3,7 +3,13 @@ "compilerOptions": { "outDir": "../../dist/out-tsc", "declaration": true, - "types": ["node"] + "types": ["node"], + "target": "es2021", + "strictNullChecks": false, + "noImplicitAny": false, + "strictBindCallApply": false, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": false }, "include": ["src/**/*.ts"], "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"] diff --git a/tsconfig.json b/tsconfig.json index 1e9cbbf1d3e..0e4ccbea37f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,8 +9,8 @@ "@gauzy/auth": ["./packages/auth/src/index.ts"], "@gauzy/common": ["./packages/common/src/index.ts"], "@gauzy/config": ["./packages/config/src/index.ts"], - "@gauzy/contracts": ["./packages/contracts/src/index.ts"], "@gauzy/constants": ["./packages/constants/src/index.ts"], + "@gauzy/contracts": ["./packages/contracts/src/index.ts"], "@gauzy/core": ["./packages/core/src/index.ts"], "@gauzy/desktop-core": ["./packages/desktop-core/src/index.ts"], "@gauzy/desktop-timer": ["./packages/desktop-timer/src/index.ts"],