Skip to content

Commit

Permalink
feat: make sure more entities are now per tenant / organization
Browse files Browse the repository at this point in the history
  • Loading branch information
evereq committed Sep 16, 2020
1 parent e2377cf commit dfbe6ec
Show file tree
Hide file tree
Showing 49 changed files with 122 additions and 297 deletions.
Expand Up @@ -3,10 +3,10 @@ import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';
import { ICandidateCriterionsRating } from '@gauzy/models';
import { CandidateFeedback } from '../candidate-feedbacks/candidate-feedbacks.entity';
import { Base } from '../core/entities/base';
import { TenantOrganizationBase } from '../core/entities/tenant-organization-base';

@Entity('candidate_criterion_rating')
export class CandidateCriterionsRating extends Base
export class CandidateCriterionsRating extends TenantOrganizationBase
implements ICandidateCriterionsRating {
@ApiProperty({ type: String })
@Column()
Expand Down
Expand Up @@ -2,10 +2,10 @@ import { Entity, Column, ManyToOne } from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { ICandidateInterviewers, ICandidateInterview } from '@gauzy/models';
import { CandidateInterview } from '../candidate-interview/candidate-interview.entity';
import { Base } from '../core/entities/base';
import { TenantOrganizationBase } from '../core/entities/tenant-organization-base';

@Entity('candidate_interviewer')
export class CandidateInterviewers extends Base
export class CandidateInterviewers extends TenantOrganizationBase
implements ICandidateInterviewers {
@ApiProperty({ type: String })
@Column()
Expand Down
Expand Up @@ -5,10 +5,10 @@ import {
ICandidateInterview
} from '@gauzy/models';
import { CandidateInterview } from '../candidate-interview/candidate-interview.entity';
import { Base } from '../core/entities/base';
import { TenantOrganizationBase } from '../core/entities/tenant-organization-base';

@Entity('candidate_personal_quality')
export class CandidatePersonalQualities extends Base
export class CandidatePersonalQualities extends TenantOrganizationBase
implements ICandidatePersonalQualities {
@ApiProperty({ type: String })
@Column()
Expand Down
Expand Up @@ -2,10 +2,10 @@ import { Column, Entity, ManyToOne } from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { ICandidateTechnologies, ICandidateInterview } from '@gauzy/models';
import { CandidateInterview } from '../candidate-interview/candidate-interview.entity';
import { Base } from '../core/entities/base';
import { TenantOrganizationBase } from '../core/entities/tenant-organization-base';

@Entity('candidate_technology')
export class CandidateTechnologies extends Base
export class CandidateTechnologies extends TenantOrganizationBase
implements ICandidateTechnologies {
@ApiProperty({ type: String })
@Column()
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/app/core/entities/tenant-base.ts
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { Column, JoinColumn, ManyToOne, RelationId } from 'typeorm';
import { Column, Index, JoinColumn, ManyToOne, RelationId } from 'typeorm';
import { Tenant } from '../../tenant/tenant.entity';
import { Base } from './base';
import { IsString, IsOptional } from 'class-validator';
Expand All @@ -17,6 +17,7 @@ export abstract class TenantBase extends Base
@RelationId((t: TenantBase) => t.tenant)
@IsString()
@IsOptional()
@Index()
@Column({ nullable: true })
tenantId?: string;
}
4 changes: 3 additions & 1 deletion apps/api/src/app/core/entities/tenant-organization-base.ts
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { Column, JoinColumn, ManyToOne, RelationId } from 'typeorm';
import { Column, Index, JoinColumn, ManyToOne, RelationId } from 'typeorm';
import { Organization } from '../../organization/organization.entity';
import { IsOptional, IsString } from 'class-validator';
import { TenantBase } from './tenant-base';
Expand All @@ -23,6 +23,7 @@ export abstract class TenantOrganizationBase extends Base
@RelationId((it: TenantOrganizationBase) => it.organization)
@IsString()
@IsOptional()
@Index()
@Column({ nullable: true })
organizationId?: string;

Expand All @@ -36,6 +37,7 @@ export abstract class TenantOrganizationBase extends Base
@RelationId((t: TenantBase) => t.tenant)
@IsString()
@IsOptional()
@Index()
@Column({ nullable: true })
tenantId?: string;
}
Expand Up @@ -13,10 +13,10 @@ import {
} from 'class-validator';
import { Column, Entity, Index, ManyToOne } from 'typeorm';
import { Employee } from '../employee/employee.entity';
import { Base } from '../core/entities/base';
import { TenantOrganizationBase } from '../core/entities/tenant-organization-base';

@Entity('employee_recurring_expense')
export class EmployeeRecurringExpense extends Base
export class EmployeeRecurringExpense extends TenantOrganizationBase
implements IEmployeeRecurringExpense {
@ApiProperty({ type: String })
@IsString()
Expand Down
5 changes: 3 additions & 2 deletions apps/api/src/app/employee-setting/employee-setting.entity.ts
Expand Up @@ -10,10 +10,11 @@ import {
} from 'class-validator';
import { IEmployeeSetting, CurrenciesEnum } from '@gauzy/models';
import { Employee } from '../employee/employee.entity';
import { Base } from '../core/entities/base';
import { TenantOrganizationBase } from '../core/entities/tenant-organization-base';

@Entity('employee_setting')
export class EmployeeSetting extends Base implements IEmployeeSetting {
export class EmployeeSetting extends TenantOrganizationBase
implements IEmployeeSetting {
@ApiProperty({ type: String })
@IsString()
@IsNotEmpty()
Expand Down
9 changes: 8 additions & 1 deletion apps/api/src/app/employee/employee.entity.ts
Expand Up @@ -12,7 +12,8 @@ import {
IOrganizationDepartment,
IOrganizationEmploymentType,
IInvoiceItem,
IRequestApprovalEmployee
IRequestApprovalEmployee,
IPayment
} from '@gauzy/models';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
Expand Down Expand Up @@ -45,6 +46,7 @@ import { Skill } from '../skills/skill.entity';
import { Contact } from '../contact/contact.entity';
import { TimeLog } from '../timesheet/time-log.entity';
import { TenantOrganizationBase } from '../core/entities/tenant-organization-base';
import { Payment } from '../payment/payment.entity';

@Entity('employee')
export class Employee extends TenantOrganizationBase implements IEmployee {
Expand Down Expand Up @@ -205,6 +207,11 @@ export class Employee extends TenantOrganizationBase implements IEmployee {
@JoinColumn()
invoiceItems?: IInvoiceItem[];

@ApiPropertyOptional({ type: Payment, isArray: true })
@OneToMany((type) => Payment, (payments) => payments.recordedBy)
@JoinColumn()
payments?: IPayment[];

@OneToMany(
(type) => RequestApprovalEmployee,
(requestApprovals) => requestApprovals.employee
Expand Down
5 changes: 3 additions & 2 deletions apps/api/src/app/estimate-email/estimate-email.entity.ts
Expand Up @@ -2,10 +2,11 @@ import { IEstimateEmail } from '@gauzy/models';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsDate, IsEmail, IsString } from 'class-validator';
import { Column, Entity } from 'typeorm';
import { Base } from '../core/entities/base';
import { TenantOrganizationBase } from '../core/entities/tenant-organization-base';

@Entity('estimate_email')
export class EstimateEmail extends Base implements IEstimateEmail {
export class EstimateEmail extends TenantOrganizationBase
implements IEstimateEmail {
@ApiPropertyOptional({ type: String })
@IsString()
@Column()
Expand Down
@@ -1,10 +1,11 @@
import { Entity, Column } from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { IHelpCenterArticle } from '@gauzy/models';
import { Base } from '../core/entities/base';
import { TenantOrganizationBase } from '../core/entities/tenant-organization-base';

@Entity('knowledge_base_article')
export class HelpCenterArticle extends Base implements IHelpCenterArticle {
export class HelpCenterArticle extends TenantOrganizationBase
implements IHelpCenterArticle {
@ApiProperty({ type: String })
@Column()
name: string;
Expand Down
@@ -1,10 +1,11 @@
import { Entity, Column } from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { IHelpCenterAuthor } from '@gauzy/models';
import { Base } from '../core/entities/base';
import { TenantOrganizationBase } from '../core/entities/tenant-organization-base';

@Entity('knowledge_base_author')
export class HelpCenterAuthor extends Base implements IHelpCenterAuthor {
export class HelpCenterAuthor extends TenantOrganizationBase
implements IHelpCenterAuthor {
@ApiProperty({ type: String })
@Column()
employeeId: string;
Expand Down
@@ -1,11 +1,11 @@
import { ApiProperty } from '@nestjs/swagger';
import { Column, Entity, JoinColumn, RelationId, ManyToOne } from 'typeorm';
import { Base } from '../core/entities/base';
import { IIntegrationEntitySetting } from '@gauzy/models';
import { IntegrationEntitySetting } from '../integration-entity-setting/integration-entity-setting.entity';
import { TenantBase } from '../core/entities/tenant-base';

@Entity('integration_entity_setting_tied_entity')
export class IntegrationEntitySettingTiedEntity extends Base
export class IntegrationEntitySettingTiedEntity extends TenantBase
implements IIntegrationEntitySetting {
@ApiProperty({ type: IntegrationEntitySetting })
@ManyToOne(
Expand Down
Expand Up @@ -7,13 +7,13 @@ import {
ManyToOne,
OneToMany
} from 'typeorm';
import { Base } from '../core/entities/base';
import { IIntegrationEntitySetting } from '@gauzy/models';
import { IntegrationTenant } from '../integration-tenant/integration-tenant.entity';
import { IntegrationEntitySettingTiedEntity } from '../integration-entity-setting-tied-entity/integration-entity-setting-tied-entity.entity';
import { TenantBase } from '../core/entities/tenant-base';

@Entity('integration_entity_setting')
export class IntegrationEntitySetting extends Base
export class IntegrationEntitySetting extends TenantBase
implements IIntegrationEntitySetting {
@ApiPropertyOptional({ type: IntegrationTenant })
@ManyToOne(
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/app/integration-map/integration-map.entity.ts
@@ -1,11 +1,11 @@
import { ApiProperty } from '@nestjs/swagger';
import { Column, Entity, JoinColumn, RelationId, ManyToOne } from 'typeorm';
import { Base } from '../core/entities/base';
import { IIntegrationMap } from '@gauzy/models';
import { IntegrationTenant } from '../integration-tenant/integration-tenant.entity';
import { TenantBase } from '../core/entities/tenant-base';

@Entity('integration_map')
export class IntegrationMap extends Base implements IIntegrationMap {
export class IntegrationMap extends TenantBase implements IIntegrationMap {
@ApiProperty({ type: IntegrationTenant })
@ManyToOne((type) => IntegrationTenant, {
nullable: false
Expand Down
@@ -1,11 +1,12 @@
import { ApiProperty } from '@nestjs/swagger';
import { Column, Entity, JoinColumn, RelationId, ManyToOne } from 'typeorm';
import { Base } from '../core/entities/base';
import { IIntegrationSetting } from '@gauzy/models';
import { IntegrationTenant } from '../integration-tenant/integration-tenant.entity';
import { TenantBase } from '../core/entities/tenant-base';

@Entity('integration_setting')
export class IntegrationSetting extends Base implements IIntegrationSetting {
export class IntegrationSetting extends TenantBase
implements IIntegrationSetting {
@ApiProperty({ type: IntegrationTenant })
@ManyToOne((type) => IntegrationTenant, {
nullable: false
Expand Down
26 changes: 4 additions & 22 deletions apps/api/src/app/integration-tenant/integration-tenant.entity.ts
@@ -1,30 +1,12 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
Column,
Entity,
JoinColumn,
RelationId,
ManyToOne,
OneToMany
} from 'typeorm';
import { Tenant } from '../tenant/tenant.entity';
import { Base } from '../core/entities/base';
import { Column, Entity, JoinColumn, OneToMany } from 'typeorm';
import { IIntegrationTenant } from '@gauzy/models';
import { IntegrationEntitySetting } from '../integration-entity-setting/integration-entity-setting.entity';
import { TenantBase } from '../core/entities/tenant-base';

@Entity('integration_tenant')
export class IntegrationTenant extends Base implements IIntegrationTenant {
@ApiProperty({ type: Tenant })
@ManyToOne((type) => Tenant, {
nullable: false
})
@JoinColumn()
tenant: Tenant;

@ApiProperty({ type: String, readOnly: true })
@RelationId((integration: IntegrationTenant) => integration.tenant)
readonly tenantId: string;

export class IntegrationTenant extends TenantBase
implements IIntegrationTenant {
@ApiPropertyOptional({ type: IntegrationEntitySetting, isArray: true })
@OneToMany(
(type) => IntegrationEntitySetting,
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/app/integration/integration-type.entity.ts
@@ -1,10 +1,10 @@
import { ApiProperty } from '@nestjs/swagger';
import { Column, Entity } from 'typeorm';
import { Base } from '../core/entities/base';
import { IIntegrationType } from '@gauzy/models';
import { TenantBase } from '../core/entities/tenant-base';

@Entity('integration_type')
export class IntegrationType extends Base implements IIntegrationType {
export class IntegrationType extends TenantBase implements IIntegrationType {
@ApiProperty({ type: String })
@Column({ nullable: false })
name: string;
Expand Down
@@ -1,14 +1,13 @@
import { IInvoiceEstimateHistory } from '@gauzy/models';
import { Base } from '../core/entities/base';
import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';
import { Entity, Column, JoinColumn, ManyToOne } from 'typeorm';
import { User } from '../user/user.entity';
import { Invoice } from '../invoice/invoice.entity';
import { Organization } from '../organization/organization.entity';
import { TenantOrganizationBase } from '../core/entities/tenant-organization-base';

@Entity('invoice_estimate_history')
export class InvoiceEstimateHistory extends Base
export class InvoiceEstimateHistory extends TenantOrganizationBase
implements IInvoiceEstimateHistory {
@ApiProperty({ type: String })
@IsString()
Expand All @@ -34,20 +33,4 @@ export class InvoiceEstimateHistory extends Base
})
@JoinColumn()
invoice: Invoice;

@ApiProperty({ type: Organization })
@ManyToOne(
(type) => Organization,
(organization) => organization.invoiceEstimateHistories,
{
onDelete: 'SET NULL'
}
)
@JoinColumn()
organization: Organization;

@ApiProperty({ type: String })
@IsString()
@Column()
organizationId: string;
}
5 changes: 3 additions & 2 deletions apps/api/src/app/invoice-item/invoice-item.entity.ts
@@ -1,4 +1,3 @@
import { Base } from '../core/entities/base';
import { Entity, Column, JoinColumn, ManyToOne } from 'typeorm';
import { IInvoiceItem } from '@gauzy/models';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
Expand All @@ -8,9 +7,11 @@ import { Task } from '../tasks/task.entity';
import { Employee } from '../employee/employee.entity';
import { OrganizationProject } from '../organization-projects/organization-projects.entity';
import { Product } from '../product/product.entity';
import { TenantOrganizationBase } from '../core/entities/tenant-organization-base';

@Entity('invoice_item')
export class InvoiceItem extends Base implements IInvoiceItem {
export class InvoiceItem extends TenantOrganizationBase
implements IInvoiceItem {
@ApiPropertyOptional({ type: String })
@IsString()
@IsOptional()
Expand Down
@@ -1,19 +1,15 @@
import { Column, Entity } from 'typeorm';
import { Base } from '../core/entities/base';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IOrganizationDocument } from '@gauzy/models';
import { TenantOrganizationBase } from '../core/entities/tenant-organization-base';

@Entity('organization_document')
export class OrganizationDocuments extends Base
export class OrganizationDocuments extends TenantOrganizationBase
implements IOrganizationDocument {
@ApiProperty({ type: String })
@Column()
name: string;

@ApiProperty({ type: String })
@Column()
organizationId: string;

@ApiPropertyOptional({ type: String })
@Column()
documentUrl: string;
Expand Down

0 comments on commit dfbe6ec

Please sign in to comment.