Skip to content

Commit

Permalink
[Feat] MikroOrm Query Builder (#7674)
Browse files Browse the repository at this point in the history
* fix: updated custom smtp subscriber for mikro-orm and typeorm

* fix: updated candidate subscriber for mikro-orm and typeorm

* fix: updated user subscriber for mikro-orm and typeorm

* fix: updated email reset subscriber

* fix: updated email template subscriber

* fix: updated image asset subscriber

* fix: updated payment and feature subscribers

* fix: updated subscribers for mikro orm

* fix: updated subscribers for mikro orm

* fix: many to many relation

* fix: updated subscribers for mikro orm

* fix: where query build

* fix: after remove event subscribers for multi orm

* fix: after remove event subscribers for multi orm

* fix: update timeslot delete with screenshots parallel

* fix: updated events with entity manager

* fix: count total members of projects after updated entity

* fix: updated screenshot event subscriber

* fix: updated event subscribers

* fix: jitsu events subscriber used base entity event subscriber

* fix: updated subscribers defintion

* fix: updated time slot subscriber

* fix: updated employee subscriber

* fix: added console.log for organization team query

* replace @Index() decorator from typeorm with the new custom decorator @ColumnIndex()

* fix: rename column indexing & unnecessary separate import

* fix: column indexing for class decorator

* fix: added missing JoinColumn decorator

* fix: unnecessary additional import

* fix: role create crud service API

* fix: mapping typeorm find operator to mikro orm

* fix: tenant create API (disabled relations auto loading during create)

* refactor: tenant custom repository injection

* fix: organization create API (disabled relations auto loading during create)

* fix(deepscan): removed unnecessary import

* fix: my task for employee (custom query builder)

---------

Co-authored-by: RAHUL RATHORE <41804588+rahul-rocket@users.noreply.github.com>
Co-authored-by: Ruslan K <evereq@gmail.com>
Co-authored-by: CoderNadir <coder.nadir@gmail.com>
  • Loading branch information
4 people authored Mar 16, 2024
1 parent ca46703 commit 45c9465
Show file tree
Hide file tree
Showing 225 changed files with 2,884 additions and 2,067 deletions.
11 changes: 6 additions & 5 deletions packages/config/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ const dbConnectionTimeout = process.env.DB_CONNECTION_TIMEOUT ? parseInt(process

const idleTimeoutMillis = process.env.DB_IDLE_TIMEOUT ? parseInt(process.env.DB_IDLE_TIMEOUT) : 10000; // 10 seconds

const dbSlowQueryLoggingTimeout = process.env.DB_SLOW_QUERY_LOGGING_TIMEOUT
? parseInt(process.env.DB_SLOW_QUERY_LOGGING_TIMEOUT)
: 10000; // 10 seconds default
const dbSlowQueryLoggingTimeout = process.env.DB_SLOW_QUERY_LOGGING_TIMEOUT ? parseInt(process.env.DB_SLOW_QUERY_LOGGING_TIMEOUT) : 10000; // 10 seconds default

const dbSslMode = process.env.DB_SSL_MODE === 'true';

Expand Down Expand Up @@ -103,6 +101,7 @@ switch (dbType) {
min: 0,
max: dbPoolSize
},
persistOnCreate: true,
namingStrategy: EntityCaseNamingStrategy,
debug: getLoggingMikroOptions(process.env.DB_LOGGING) // by default set to false only
};
Expand Down Expand Up @@ -197,6 +196,7 @@ switch (dbType) {
// connection timeout - number of milliseconds to wait before timing out when connecting a new client
acquireTimeoutMillis: dbConnectionTimeout
},
persistOnCreate: true,
namingStrategy: EntityCaseNamingStrategy,
debug: getLoggingMikroOptions(process.env.DB_LOGGING) // by default set to false only
};
Expand Down Expand Up @@ -280,6 +280,7 @@ switch (dbType) {
const mikroOrmSqliteConfig: MikroOrmSqliteOptions = {
driver: SqliteDriver,
dbName: dbPath,
persistOnCreate: true,
namingStrategy: EntityCaseNamingStrategy,
debug: getLoggingMikroOptions(process.env.DB_LOGGING) // by default set to false only
};
Expand Down Expand Up @@ -310,14 +311,14 @@ switch (dbType) {
break;

case DatabaseTypeEnum.betterSqlite3:
const betterSqlitePath =
process.env.DB_PATH || path.join(process.cwd(), ...['apps', 'api', 'data'], 'gauzy.sqlite3');
const betterSqlitePath = process.env.DB_PATH || path.join(process.cwd(), ...['apps', 'api', 'data'], 'gauzy.sqlite3');
console.log('Better Sqlite DB Path: ' + betterSqlitePath);

// MikroORM DB Config (Better-SQLite3)
const mikroOrmBetterSqliteConfig: MikroOrmBetterSqliteOptions = {
driver: BetterSqliteDriver,
dbName: betterSqlitePath,
persistOnCreate: true,
namingStrategy: EntityCaseNamingStrategy,
debug: getLoggingMikroOptions(process.env.DB_LOGGING) // by default set to false only
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { ApiProperty } from '@nestjs/swagger';
import { Index } from 'typeorm';
import { AccountingTemplateTypeEnum, IAccountingTemplate } from '@gauzy/contracts';
import { isMySQL } from '@gauzy/config';
import { TenantOrganizationBaseEntity } from '../core/entities/internal';
import { MultiORMColumn, MultiORMEntity } from './../core/decorators/entity';
import { ColumnIndex, MultiORMColumn, MultiORMEntity } from './../core/decorators/entity';
import { MikroOrmAccountingTemplateRepository } from './repository/mikro-orm-accounting-template.repository';

@MultiORMEntity('accounting_template', { mikroOrmRepository: () => MikroOrmAccountingTemplateRepository })
export class AccountingTemplate extends TenantOrganizationBaseEntity
implements IAccountingTemplate {

@ApiProperty({ type: () => String })
@Index()
@ColumnIndex()
@MultiORMColumn()
name?: string;

@ApiProperty({ type: () => String })
@Index()
@ColumnIndex()
@MultiORMColumn()
languageCode?: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { ApiProperty } from '@nestjs/swagger';
import { RelationId, Index } from 'typeorm';
import { RelationId } from 'typeorm';
import { IAppointmentEmployee, IEmployee, IEmployeeAppointment } from '@gauzy/contracts';
import { IsString, IsNotEmpty } from 'class-validator';
import {
Employee,
EmployeeAppointment,
TenantOrganizationBaseEntity
} from '../core/entities/internal';
import { MultiORMColumn, MultiORMEntity } from './../core/decorators/entity';
import { ColumnIndex, MultiORMColumn, MultiORMEntity, MultiORMManyToOne } from './../core/decorators/entity';
import { MikroOrmAppointmentEmployeeRepository } from './repository/mikro-orm-appointment-employee.repository';
import { MultiORMManyToOne } from './../core/decorators/entity/relations';

@MultiORMEntity('appointment_employee', { mikroOrmRepository: () => MikroOrmAppointmentEmployeeRepository })
export class AppointmentEmployee extends TenantOrganizationBaseEntity implements IAppointmentEmployee {
Expand All @@ -34,7 +33,7 @@ export class AppointmentEmployee extends TenantOrganizationBaseEntity implements
@RelationId((it: AppointmentEmployee) => it.employee)
@IsString()
@IsNotEmpty()
@Index()
@ColumnIndex()
@MultiORMColumn({ relationId: true })
public employeeId?: string;

Expand All @@ -50,7 +49,7 @@ export class AppointmentEmployee extends TenantOrganizationBaseEntity implements
@ApiProperty({ type: () => String })
@RelationId((it: AppointmentEmployee) => it.employeeAppointment)
@IsString()
@Index()
@ColumnIndex()
@MultiORMColumn({ nullable: true, relationId: true })
public employeeAppointmentId?: string;
}
5 changes: 2 additions & 3 deletions packages/core/src/approval-policy/approval-policy.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
* E.g. for example, "Business Trip", "Borrow Items", ...
* Approval Policy table has the many to one relationship to the Organization table and Tenant by organizationId and tenantId
*/
import { Index } from 'typeorm';
import { IApprovalPolicy } from '@gauzy/contracts';
import { ApiProperty } from '@nestjs/swagger';
import { TenantOrganizationBaseEntity } from '../core/entities/internal';
import { MultiORMColumn, MultiORMEntity } from './../core/decorators/entity';
import { ColumnIndex, MultiORMColumn, MultiORMEntity } from './../core/decorators/entity';
import { MikroOrmApprovalPolicyRepository } from './repository/mikro-orm-approval-policy.repository';

@MultiORMEntity('approval_policy', { mikroOrmRepository: () => MikroOrmApprovalPolicyRepository })
export class ApprovalPolicy extends TenantOrganizationBaseEntity
implements IApprovalPolicy {

@ApiProperty({ type: () => String })
@Index()
@ColumnIndex()
@MultiORMColumn()
name: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RelationId, JoinColumn, Index } from 'typeorm';
import { RelationId, JoinColumn } from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import {
IsNotEmpty,
Expand All @@ -16,9 +16,8 @@ import {
Employee,
TenantOrganizationBaseEntity
} from '../core/entities/internal';
import { MultiORMColumn, MultiORMEntity } from './../core/decorators/entity';
import { ColumnIndex, MultiORMColumn, MultiORMEntity, MultiORMManyToOne } from './../core/decorators/entity';
import { MikroOrmAvailabilitySlotRepository } from './repository/mikro-orm-availability-slot.repository';
import { MultiORMManyToOne } from './../core/decorators/entity/relations';

@MultiORMEntity('availability_slot', { mikroOrmRepository: () => MikroOrmAvailabilitySlotRepository })
export class AvailabilitySlot extends TenantOrganizationBaseEntity implements IAvailabilitySlot {
Expand Down Expand Up @@ -59,7 +58,7 @@ export class AvailabilitySlot extends TenantOrganizationBaseEntity implements IA
@RelationId((it: AvailabilitySlot) => it.employee)
@IsString()
@IsOptional()
@Index()
@ColumnIndex()
@MultiORMColumn({ nullable: true, relationId: true })
readonly employeeId?: string;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Index, RelationId } from 'typeorm';
import { RelationId } from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import {
ICandidateCriterionsRating,
Expand All @@ -12,9 +12,8 @@ import {
CandidateTechnologies,
TenantOrganizationBaseEntity
} from '../core/entities/internal';
import { MultiORMColumn, MultiORMEntity } from './../core/decorators/entity';
import { ColumnIndex, MultiORMColumn, MultiORMEntity, MultiORMManyToOne } from './../core/decorators/entity';
import { MikroOrmCandidateCriterionsRatingRepository } from './repository/mikro-orm-candidate-criterions-rating.repository';
import { MultiORMManyToOne } from '../core/decorators/entity/relations';

@MultiORMEntity('candidate_criterion_rating', { mikroOrmRepository: () => MikroOrmCandidateCriterionsRatingRepository })
export class CandidateCriterionsRating extends TenantOrganizationBaseEntity
Expand All @@ -41,7 +40,7 @@ export class CandidateCriterionsRating extends TenantOrganizationBaseEntity

@ApiProperty({ type: () => String })
@RelationId((it: CandidateCriterionsRating) => it.technology)
@Index()
@ColumnIndex()
@MultiORMColumn({ nullable: true, relationId: true })
technologyId?: string;

Expand All @@ -56,7 +55,7 @@ export class CandidateCriterionsRating extends TenantOrganizationBaseEntity

@ApiProperty({ type: () => String })
@RelationId((it: CandidateCriterionsRating) => it.personalQuality)
@Index()
@ColumnIndex()
@MultiORMColumn({ nullable: true, relationId: true })
personalQualityId?: string;

Expand All @@ -71,7 +70,7 @@ export class CandidateCriterionsRating extends TenantOrganizationBaseEntity

@ApiProperty({ type: () => String })
@RelationId((it: CandidateCriterionsRating) => it.feedback)
@Index()
@ColumnIndex()
@MultiORMColumn({ nullable: true, relationId: true })
feedbackId?: string;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Index, RelationId } from 'typeorm';
import { RelationId } from 'typeorm';
import { ICandidateDocument, ICandidate } from '@gauzy/contracts';
import { IsString } from 'class-validator';
import {
Candidate,
TenantOrganizationBaseEntity
} from '../core/entities/internal';
import { MultiORMColumn, MultiORMEntity } from './../core/decorators/entity';
import { ColumnIndex, MultiORMColumn, MultiORMEntity, MultiORMManyToOne } from './../core/decorators/entity';
import { MikroOrmCandidateDocumentRepository } from './repository/mikro-orm-candidate-document.repository';
import { MultiORMManyToOne } from '../core/decorators/entity/relations';

@MultiORMEntity('candidate_document', { mikroOrmRepository: () => MikroOrmCandidateDocumentRepository })
export class CandidateDocument extends TenantOrganizationBaseEntity implements ICandidateDocument {
Expand All @@ -34,7 +33,7 @@ export class CandidateDocument extends TenantOrganizationBaseEntity implements I
@ApiProperty({ type: () => String })
@RelationId((it: CandidateDocument) => it.candidate)
@IsString()
@Index()
@ColumnIndex()
@MultiORMColumn({ nullable: true, relationId: true })
candidateId?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import {
Candidate,
TenantOrganizationBaseEntity
} from '../core/entities/internal';
import { MultiORMColumn, MultiORMEntity } from './../core/decorators/entity';
import { MultiORMColumn, MultiORMEntity, MultiORMManyToOne } from './../core/decorators/entity';
import { MikroOrmCandidateEducationRepository } from './repository/mikro-orm-candidate-education.repository';
import { MultiORMManyToOne } from '../core/decorators/entity/relations';

@MultiORMEntity('candidate_education', { mikroOrmRepository: () => MikroOrmCandidateEducationRepository })
export class CandidateEducation extends TenantOrganizationBaseEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import {
Candidate,
TenantOrganizationBaseEntity
} from '../core/entities/internal';
import { MultiORMColumn, MultiORMEntity } from './../core/decorators/entity';
import { MultiORMColumn, MultiORMEntity, MultiORMManyToOne } from './../core/decorators/entity';
import { MikroOrmCandidateExperienceRepository } from './repository/mikro-orm-candidate-experience.repository';
import { MultiORMManyToOne } from '../core/decorators/entity/relations';

@MultiORMEntity('candidate_experience', { mikroOrmRepository: () => MikroOrmCandidateExperienceRepository })
export class CandidateExperience extends TenantOrganizationBaseEntity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
JoinColumn,
RelationId,
Index
RelationId
} from 'typeorm';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
Expand All @@ -20,9 +19,8 @@ import {
CandidateInterviewers,
TenantOrganizationBaseEntity
} from '../core/entities/internal';
import { MultiORMColumn, MultiORMEntity } from './../core/decorators/entity';
import { ColumnIndex, MultiORMColumn, MultiORMEntity, MultiORMManyToOne, MultiORMOneToMany, MultiORMOneToOne } from './../core/decorators/entity';
import { MikroOrmCandidateFeedbackRepository } from './repository/mikro-orm-candidate-feedback.repository';
import { MultiORMManyToOne, MultiORMOneToMany, MultiORMOneToOne } from '../core/decorators/entity/relations';

@MultiORMEntity('candidate_feedback', { mikroOrmRepository: () => MikroOrmCandidateFeedbackRepository })
export class CandidateFeedback extends TenantOrganizationBaseEntity
Expand Down Expand Up @@ -65,7 +63,7 @@ export class CandidateFeedback extends TenantOrganizationBaseEntity

@ApiProperty({ type: () => String })
@RelationId((it: CandidateFeedback) => it.candidate)
@Index()
@ColumnIndex()
@MultiORMColumn({ nullable: true, relationId: true })
candidateId?: ICandidate['id'];

Expand All @@ -80,7 +78,7 @@ export class CandidateFeedback extends TenantOrganizationBaseEntity

@ApiProperty({ type: () => String })
@RelationId((it: CandidateFeedback) => it.interview)
@Index()
@ColumnIndex()
@MultiORMColumn({ nullable: true, relationId: true })
interviewId?: ICandidateInterview['id'];
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JoinColumn, RelationId, Index } from 'typeorm';
import { JoinColumn, RelationId } from 'typeorm';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
ICandidateInterview,
Expand All @@ -17,9 +17,8 @@ import {
TenantOrganizationBaseEntity
} from '../core/entities/internal';
import { ColumnNumericTransformerPipe } from './../shared/pipes';
import { MultiORMColumn, MultiORMEntity } from './../core/decorators/entity';
import { ColumnIndex, MultiORMColumn, MultiORMEntity, MultiORMManyToOne, MultiORMOneToMany } from './../core/decorators/entity';
import { MikroOrmCandidateInterviewRepository } from './repository/mikro-orm-candidate-interview.repository';
import { MultiORMManyToOne, MultiORMOneToMany } from '../core/decorators/entity/relations';

@MultiORMEntity('candidate_interview', { mikroOrmRepository: () => MikroOrmCandidateInterviewRepository })
export class CandidateInterview extends TenantOrganizationBaseEntity
Expand Down Expand Up @@ -104,7 +103,7 @@ export class CandidateInterview extends TenantOrganizationBaseEntity

@ApiProperty({ type: () => String })
@RelationId((it: CandidateInterview) => it.candidate)
@Index()
@ColumnIndex()
@MultiORMColumn({ nullable: true, relationId: true })
candidateId?: string;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RelationId, Index } from 'typeorm';
import { RelationId } from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { ICandidateInterviewers, ICandidateInterview, IEmployee } from '@gauzy/contracts';
import {
Expand All @@ -7,9 +7,8 @@ import {
TenantOrganizationBaseEntity
} from '../core/entities/internal';
import { IsString } from 'class-validator';
import { MultiORMColumn, MultiORMEntity } from './../core/decorators/entity';
import { ColumnIndex, MultiORMColumn, MultiORMEntity, MultiORMManyToOne } from './../core/decorators/entity';
import { MikroOrmCandidateInterviewersRepository } from './repository/mikro-orm-candidate-interviewers.repository';
import { MultiORMManyToOne } from '../core/decorators/entity/relations';

@MultiORMEntity('candidate_interviewer', { mikroOrmRepository: () => MikroOrmCandidateInterviewersRepository })
export class CandidateInterviewers extends TenantOrganizationBaseEntity implements ICandidateInterviewers {
Expand All @@ -27,7 +26,7 @@ export class CandidateInterviewers extends TenantOrganizationBaseEntity implemen
@ApiProperty({ type: () => String })
@RelationId((it: CandidateInterviewers) => it.interview)
@IsString()
@Index()
@ColumnIndex()
@MultiORMColumn({ relationId: true })
interviewId: string;

Expand All @@ -40,7 +39,7 @@ export class CandidateInterviewers extends TenantOrganizationBaseEntity implemen
@ApiProperty({ type: () => String })
@RelationId((it: CandidateInterviewers) => it.employee)
@IsString()
@Index()
@ColumnIndex()
@MultiORMColumn({ nullable: true, relationId: true })
employeeId: string;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Index, JoinColumn, RelationId } from 'typeorm';
import { JoinColumn, RelationId } from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import {
ICandidatePersonalQualities,
Expand All @@ -12,9 +12,8 @@ import {
} from '../core/entities/internal';
import { IsOptional, IsString } from 'class-validator';
import { ColumnNumericTransformerPipe } from './../shared/pipes';
import { MultiORMColumn, MultiORMEntity } from './../core/decorators/entity';
import { ColumnIndex, MultiORMColumn, MultiORMEntity, MultiORMManyToOne, MultiORMOneToMany } from './../core/decorators/entity';
import { MikroOrmCandidatePersonalQualitiesRepository } from './repository/mikro-orm-candidate-personal-qualities.repository';
import { MultiORMManyToOne, MultiORMOneToMany } from '../core/decorators/entity/relations';

@MultiORMEntity('candidate_personal_quality', { mikroOrmRepository: () => MikroOrmCandidatePersonalQualitiesRepository })
export class CandidatePersonalQualities extends TenantOrganizationBaseEntity implements ICandidatePersonalQualities {
Expand Down Expand Up @@ -47,7 +46,7 @@ export class CandidatePersonalQualities extends TenantOrganizationBaseEntity imp
@RelationId((it: CandidatePersonalQualities) => it.interview)
@IsString()
@IsOptional()
@Index()
@ColumnIndex()
@MultiORMColumn({ nullable: true, relationId: true })
interviewId?: string;

Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/candidate-skill/candidate-skill.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import {
Candidate,
TenantOrganizationBaseEntity
} from '../core/entities/internal';
import { MultiORMColumn, MultiORMEntity } from './../core/decorators/entity';
import { MultiORMColumn, MultiORMEntity, MultiORMManyToOne } from './../core/decorators/entity';
import { MikroOrmCandidateSkillRepository } from './repository/mikro-orm-candidate-skill.repository';
import { MultiORMManyToOne } from '../core/decorators/entity/relations';

@MultiORMEntity('candidate_skill', { mikroOrmRepository: () => MikroOrmCandidateSkillRepository })
export class CandidateSkill extends TenantOrganizationBaseEntity implements ICandidateSkill {
Expand Down
Loading

0 comments on commit 45c9465

Please sign in to comment.