Skip to content

Commit

Permalink
fix: circular deps with import path
Browse files Browse the repository at this point in the history
  • Loading branch information
GloireMutaliko21 committed Jan 29, 2025
1 parent 58e6775 commit b2542ab
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 78 deletions.
2 changes: 1 addition & 1 deletion packages/contracts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export * from './lib/job-search-category.model';
export * from './lib/job-search-occupation.model';
export * from './lib/language.model';
export * from './lib/mention.model';
export * from './lib/notification.model';
export * from './lib/user-notification.model';
export * from './lib/organization-award.model';
export * from './lib/organization-contact.model';
export * from './lib/organization-department.model';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface IUserNotificationSetting extends IBasePerTenantAndOrganizationE
userId: ID;
user?: IUser;
payment?: boolean;
assignement?: boolean;
assignment?: boolean;
invitation?: boolean;
mention?: boolean;
comment?: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { IBasePerEntityType, IBasePerTenantAndOrganizationEntityModel, ID } from './base-entity.model';
import { IUser } from './user.model';

export interface INotification extends IBasePerTenantAndOrganizationEntityModel, IBasePerEntityType {
export interface IUserNotification extends IBasePerTenantAndOrganizationEntityModel, IBasePerEntityType {
title?: string;
message?: string;
type?: NotificationTypeEnum;
type?: UserNotificationTypeEnum;
sentById?: ID;
sentBy?: IUser;
isRead?: boolean;
readedAt?: Date;
readAt?: Date;
receiverId?: ID;
receiver?: IUser;
}

export enum NotificationTypeEnum {
export enum UserNotificationTypeEnum {
PAYMENT = 'Payment', // Will be stored as 0 in DB
ASSIGNEMENT = 'Assignement', // Will be stored as 1 in DB
ASSIGNMENT = 'Assignment', // Will be stored as 1 in DB
INVITATION = 'Invitation', // Will be stored as 2 in DB
MENTION = 'Mention', // Will be stored as 3 in DB
COMMENT = 'Comment', // Will be stored as 4 in DB
MESSAGE = 'Message' // Will be stored as 5 in DB
}

export interface INotificationCreateInput extends Omit<INotification, 'isRead' | 'readedAt'> {}
export interface IUserNotificationCreateInput extends Omit<IUserNotification, 'isRead' | 'readedAt'> {}

Check warning on line 25 in packages/contracts/src/lib/user-notification.model.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (readed)

export interface INotificationUpdateInput
extends Omit<INotification, 'receiverId' | 'receiver' | 'sentById' | 'sentBy'> {}
extends Omit<IUserNotification, 'receiverId' | 'receiver' | 'sentById' | 'sentBy'> {}
4 changes: 2 additions & 2 deletions packages/core/src/lib/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ import { DashboardModule } from '../dashboard/dashboard.module';
import { DashboardWidgetModule } from '../dashboard/dashboard-widget/dashboard-widget.module';
import { TenantApiKeyModule } from '../tenant-api-key/tenant-api-key.module';
import { TagTypeModule } from '../tag-type/tag-type.module';
import { NotificationModule } from '../notification/notification.module';
import { UserNotificationModule } from '../user-notification/user-notification.module';

const { unleashConfig } = environment;

Expand Down Expand Up @@ -470,7 +470,7 @@ if (environment.THROTTLE_ENABLED) {
MentionModule,
SubscriptionModule,
DashboardModule,
NotificationModule,
UserNotificationModule,
DashboardWidgetModule,
TenantApiKeyModule,
],
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/lib/core/entities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ import {
Language,
Mention,
Merchant,
Notification,
Organization,
OrganizationAward,
OrganizationContact,
Expand Down Expand Up @@ -234,7 +233,6 @@ export const coreEntities = [
Language,
Mention,
Merchant,
Notification,
Organization,
OrganizationAward,
OrganizationContact,
Expand Down Expand Up @@ -310,6 +308,7 @@ export const coreEntities = [
TimeSlot,
TimeSlotMinute,
User,
// UserNotification,
UserOrganization,
Warehouse,
WarehouseProduct,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/core/entities/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export * from '../../keyresult/keyresult.entity';
export * from '../../language/language.entity';
export * from '../../mention/mention.entity';
export * from '../../merchant/merchant.entity';
export * from '../../notification/notification.entity';
export * from '../../user-notification/user-notification.entity';
export * from '../../organization-award/organization-award.entity';
export * from '../../organization-contact/organization-contact.entity';
export * from '../../organization-department/organization-department.entity';
Expand Down
16 changes: 0 additions & 16 deletions packages/core/src/lib/notification/notification.module.ts

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
import { ValueTransformer } from 'typeorm';
import { NotificationTypeEnum } from '@gauzy/contracts';
import { UserNotificationTypeEnum } from '@gauzy/contracts';

/**
* NotificationTypeTransformerPipe handles the conversion between the enum string values
* UserNotificationTypeTransformerPipe handles the conversion between the enum string values
* (used in the application) and the integer values (stored in the database).
*/
export class NotificationTypeTransformerPipe implements ValueTransformer {
export class UserNotificationTypeTransformerPipe implements ValueTransformer {
/**
* Converts the enum string value to its integer representation when writing to the database.
*
* @param value - The `NotificationTypeEnum` value.
* @param value - The `UserNotificationTypeEnum` value.
* @returns The corresponding integer value to be stored in the database.
*/
to(value: NotificationTypeEnum): number {
to(value: UserNotificationTypeEnum): number {
switch (value) {
case NotificationTypeEnum.PAYMENT:
case UserNotificationTypeEnum.PAYMENT:
return 0;
case NotificationTypeEnum.ASSIGNEMENT:
case UserNotificationTypeEnum.ASSIGNMENT:
return 1;
case NotificationTypeEnum.INVITATION:
case UserNotificationTypeEnum.INVITATION:
return 2;
case NotificationTypeEnum.MENTION:
case UserNotificationTypeEnum.MENTION:
return 3;
case NotificationTypeEnum.COMMENT:
case UserNotificationTypeEnum.COMMENT:
return 4;
case NotificationTypeEnum.MESSAGE:
case UserNotificationTypeEnum.MESSAGE:
return 5;
default:
throw new Error(`Unknown notification type: ${value}`);
}
}

/**
* Converts the integer value to its corresponding `NotificationTypeEnum` string when reading from the database.
* Converts the integer value to its corresponding `UserNotificationTypeEnum` string when reading from the database.
*
* @param value - The integer value from the database.
* @returns The corresponding `NotificationTypeEnum`.
* @returns The corresponding `UserNotificationTypeEnum`.
*/
from(value: number): NotificationTypeEnum {
from(value: number): UserNotificationTypeEnum {
switch (value) {
case 0:
return NotificationTypeEnum.PAYMENT;
return UserNotificationTypeEnum.PAYMENT;
case 1:
return NotificationTypeEnum.ASSIGNEMENT;
return UserNotificationTypeEnum.ASSIGNMENT;
case 2:
return NotificationTypeEnum.INVITATION;
return UserNotificationTypeEnum.INVITATION;
case 3:
return NotificationTypeEnum.MENTION;
return UserNotificationTypeEnum.MENTION;
case 4:
return NotificationTypeEnum.COMMENT;
return UserNotificationTypeEnum.COMMENT;
case 5:
return NotificationTypeEnum.MESSAGE;
return UserNotificationTypeEnum.MESSAGE;
default:
throw new Error(`Unknown notification type value: ${value}`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { MikroOrmBaseEntityRepository } from '../../core/repository/mikro-orm-base-entity.repository';
import { UserNotification } from '../user-notification.entity';

export class MikroOrmUserNotificationRepository extends MikroOrmBaseEntityRepository<UserNotification> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { UserNotification } from '../user-notification.entity';

@Injectable()
export class TypeOrmUserNotificationRepository extends Repository<UserNotification> {
constructor(@InjectRepository(UserNotification) readonly repository: Repository<UserNotification>) {
super(repository.target, repository.manager, repository.queryRunner);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { EntityRepositoryType } from '@mikro-orm/core';
import { JoinColumn, RelationId } from 'typeorm';
import { IsBoolean, IsDateString, IsEnum, IsNotEmpty, IsOptional, IsString, IsUUID } from 'class-validator';
import { BaseEntityEnum, ID, INotification, IUser, NotificationTypeEnum } from '@gauzy/contracts';
import { BaseEntityEnum, ID, IUser, IUserNotification, UserNotificationTypeEnum } from '@gauzy/contracts';
import { TenantOrganizationBaseEntity, User } from '../core/entities/internal';
import { ColumnIndex, MultiORMColumn, MultiORMEntity, MultiORMManyToOne } from '../core/decorators/entity';
import { NotificationTypeTransformerPipe } from '../shared';
import { MikroOrmNotificationRepository } from './repository/mikro-orm-notification.repository';
import { UserNotificationTypeTransformerPipe } from '../shared/pipes';
import { MikroOrmUserNotificationRepository } from './repository/mikro-orm-user-notification.repository';

@MultiORMEntity('notification', { mikroOrmRepository: () => MikroOrmNotificationRepository })
export class Notification extends TenantOrganizationBaseEntity implements INotification {
[EntityRepositoryType]: MikroOrmNotificationRepository;
@MultiORMEntity('user_notification', { mikroOrmRepository: () => MikroOrmUserNotificationRepository })
export class UserNotification extends TenantOrganizationBaseEntity implements IUserNotification {
[EntityRepositoryType]?: MikroOrmUserNotificationRepository;

/**
* The type of entity type record from which notification was created
Expand Down Expand Up @@ -51,12 +51,12 @@ export class Notification extends TenantOrganizationBaseEntity implements INotif
@MultiORMColumn()
message: string;

@ApiPropertyOptional({ enum: NotificationTypeEnum })
@ApiPropertyOptional({ enum: UserNotificationTypeEnum })
@IsOptional()
@IsEnum(NotificationTypeEnum)
@IsEnum(UserNotificationTypeEnum)
@ColumnIndex()
@MultiORMColumn({ type: 'int', nullable: true, transformer: new NotificationTypeTransformerPipe() })
type?: NotificationTypeEnum; // Will be stored as 0, 1, 2, 3, etc in DB
@MultiORMColumn({ type: 'int', nullable: true, transformer: new UserNotificationTypeTransformerPipe() })
type?: UserNotificationTypeEnum; // Will be stored as 0, 1, 2, 3, etc in DB

/**
* Indicates if the notification is read
Expand All @@ -76,7 +76,7 @@ export class Notification extends TenantOrganizationBaseEntity implements INotif
@MultiORMColumn({ nullable: true })
readedAt?: Date;

Check warning on line 77 in packages/core/src/lib/user-notification/user-notification.entity.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (readed)

/*
/*
|--------------------------------------------------------------------------
| @ManyToOne
|--------------------------------------------------------------------------
Expand All @@ -100,7 +100,7 @@ export class Notification extends TenantOrganizationBaseEntity implements INotif
@ApiPropertyOptional({ type: () => String })
@IsOptional()
@IsUUID()
@RelationId((it: Notification) => it.sentBy)
@RelationId((it: UserNotification) => it.sentBy)
@ColumnIndex()
@MultiORMColumn({ nullable: true, relationId: true })
sentById?: ID;
Expand All @@ -123,7 +123,7 @@ export class Notification extends TenantOrganizationBaseEntity implements INotif
@ApiPropertyOptional({ type: () => String })
@IsOptional()
@IsUUID()
@RelationId((it: Notification) => it.receiver)
@RelationId((it: UserNotification) => it.receiver)
@ColumnIndex()
@MultiORMColumn({ nullable: true, relationId: true })
receiverId?: ID;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Module } from '@nestjs/common';

@Module({})
export class UserNotificationModule {}

0 comments on commit b2542ab

Please sign in to comment.