-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rename "Subscription" to "EntitySubscription"
- Loading branch information
1 parent
590cf1c
commit 34cd9f4
Showing
47 changed files
with
372 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { IBasePerEntityType, OmitFields } from './base-entity.model'; | ||
import { IEmployeeEntityInput } from './employee.model'; | ||
|
||
export interface IEntitySubscription extends IBasePerEntityType, IEmployeeEntityInput { | ||
type: EntitySubscriptionTypeEnum; | ||
} | ||
|
||
export enum EntitySubscriptionTypeEnum { | ||
MANUAL = 'manual', | ||
MENTION = 'mention', | ||
ASSIGNMENT = 'assignment', | ||
COMMENT = 'comment', | ||
CREATED_ENTITY = 'created-entity' | ||
} | ||
|
||
export interface IEntitySubscriptionCreateInput extends OmitFields<IEntitySubscription> {} | ||
|
||
export interface IEntitySubscriptionFindInput extends Partial<IEntitySubscription> {} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...n/commands/subscription.create.command.ts → ...nds/entity-subscription.create.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
.../core/src/lib/entity-subscription/commands/handlers/entity-subscription.create.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { IEntitySubscription } from '@gauzy/contracts'; | ||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; | ||
import { EntitySubscriptionCreateCommand } from '../entity-subscription.create.command'; | ||
import { EntitySubscriptionService } from '../../entity-subscription.service'; | ||
|
||
@CommandHandler(EntitySubscriptionCreateCommand) | ||
export class EntitySubscriptionCreateHandler implements ICommandHandler<EntitySubscriptionCreateCommand> { | ||
constructor(private readonly subscriptionService: EntitySubscriptionService) {} | ||
|
||
public async execute(command: EntitySubscriptionCreateCommand): Promise<IEntitySubscription> { | ||
const { input } = command; | ||
|
||
return await this.subscriptionService.create(input); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/core/src/lib/entity-subscription/commands/handlers/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { EntitySubscriptionCreateHandler } from './entity-subscription.create.handler'; | ||
|
||
export const CommandHandlers = [EntitySubscriptionCreateHandler]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './entity-subscription.create.command'; |
22 changes: 22 additions & 0 deletions
22
packages/core/src/lib/entity-subscription/dto/create-entity-subscription.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
BaseEntityEnum, | ||
EntitySubscriptionTypeEnum, | ||
IEmployee, | ||
IEntitySubscriptionCreateInput | ||
} from '@gauzy/contracts'; | ||
import { TenantOrganizationBaseDTO } from '../../core'; | ||
|
||
/** | ||
* Create entity subscription data validation request DTO. | ||
*/ | ||
export class CreateEntitySubscriptionDTO extends TenantOrganizationBaseDTO implements IEntitySubscriptionCreateInput { | ||
type: EntitySubscriptionTypeEnum; | ||
entityId: string; | ||
entity: BaseEntityEnum; | ||
isActive?: boolean; | ||
isArchived?: boolean; | ||
archivedAt?: Date; | ||
deletedAt?: Date; | ||
employeeId?: string; | ||
employee?: IEmployee; | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/core/src/lib/entity-subscription/dto/entity-subscription-find-input.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { PartialType } from '@nestjs/swagger'; | ||
import { IEntitySubscriptionFindInput } from '@gauzy/contracts'; | ||
import { EntitySubscription } from '../entity-subscription.entity'; | ||
|
||
export class EntitySubscriptionFindInputDTO | ||
extends PartialType(EntitySubscription) | ||
implements IEntitySubscriptionFindInput {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './create-entity-subscription.dto'; | ||
export * from './entity-subscription-find-input.dto'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/core/src/lib/entity-subscription/entity-subscription.entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import { EntityRepositoryType } from '@mikro-orm/core'; | ||
import { JoinColumn, RelationId } from 'typeorm'; | ||
import { IsEnum, IsNotEmpty, IsOptional, IsUUID } from 'class-validator'; | ||
import { ActorTypeEnum, ID, IEmployee, IEntitySubscription, EntitySubscriptionTypeEnum } from '@gauzy/contracts'; | ||
import { BasePerEntityType, Employee } from '../core/entities/internal'; | ||
import { ColumnIndex, MultiORMColumn, MultiORMEntity, MultiORMManyToOne } from '../core/decorators/entity'; | ||
import { ActorTypeTransformer } from '../shared/pipes'; | ||
import { MikroOrmEntitySubscriptionRepository } from './repository/mikro-orm-entity-subscription.repository'; | ||
|
||
@MultiORMEntity('entity_subscription', { mikroOrmRepository: () => MikroOrmEntitySubscriptionRepository }) | ||
export class EntitySubscription extends BasePerEntityType implements IEntitySubscription { | ||
[EntityRepositoryType]?: MikroOrmEntitySubscriptionRepository; | ||
|
||
// Indicate the actor type | ||
@ApiPropertyOptional({ enum: ActorTypeEnum }) | ||
@IsOptional() | ||
@IsEnum(ActorTypeEnum) | ||
@ColumnIndex() | ||
@MultiORMColumn({ type: 'int', nullable: true, transformer: new ActorTypeTransformer() }) | ||
actorType?: ActorTypeEnum; // Will be stored as 0 or 1 in DB | ||
|
||
/** | ||
* The type of subscription. | ||
*/ | ||
@ApiProperty({ type: () => String, enum: EntitySubscriptionTypeEnum }) | ||
@IsNotEmpty() | ||
@IsEnum(EntitySubscriptionTypeEnum) | ||
@ColumnIndex() | ||
@MultiORMColumn() | ||
type: EntitySubscriptionTypeEnum; | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| @ManyToOne | ||
|-------------------------------------------------------------------------- | ||
*/ | ||
/** | ||
* The employee who subscribed to the entity. | ||
*/ | ||
@MultiORMManyToOne(() => Employee, { | ||
onDelete: 'CASCADE' // Database cascade action on delete. | ||
}) | ||
@JoinColumn() | ||
employee?: IEmployee; | ||
|
||
/** | ||
* The employee id who subscribed to the entity. | ||
*/ | ||
@ApiProperty({ type: () => String }) | ||
@IsNotEmpty() | ||
@IsUUID() | ||
@RelationId((it: EntitySubscription) => it.employee) | ||
@ColumnIndex() | ||
@MultiORMColumn({ relationId: true }) | ||
employeeId?: ID; | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/core/src/lib/entity-subscription/entity-subscription.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { CqrsModule } from '@nestjs/cqrs'; | ||
import { Global, Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { MikroOrmModule } from '@mikro-orm/nestjs'; | ||
import { RolePermissionModule } from '../role-permission/role-permission.module'; | ||
import { CommandHandlers } from './commands/handlers'; | ||
import { EventHandlers } from './events/handlers'; | ||
import { EntitySubscriptionService } from './entity-subscription.service'; | ||
import { EntitySubscriptionController } from './entity-subscription.controller'; | ||
import { EntitySubscription } from './entity-subscription.entity'; | ||
import { TypeOrmEntitySubscriptionRepository } from './repository/type-orm-entity-subscription.repository'; | ||
|
||
@Global() | ||
@Module({ | ||
imports: [ | ||
TypeOrmModule.forFeature([EntitySubscription]), | ||
MikroOrmModule.forFeature([EntitySubscription]), | ||
RolePermissionModule, | ||
CqrsModule | ||
], | ||
controllers: [EntitySubscriptionController], | ||
providers: [EntitySubscriptionService, TypeOrmEntitySubscriptionRepository, ...CommandHandlers, ...EventHandlers], | ||
exports: [EntitySubscriptionService, TypeOrmEntitySubscriptionRepository] | ||
}) | ||
export class EntitySubscriptionModule {} |
Oops, something went wrong.