mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-23 10:47:54 +00:00
Merge branch 'dev' into real-time-devices
This commit is contained in:
@@ -7,6 +7,7 @@ export default registerAs(
|
||||
SMTP_PORT: parseInt(process.env.SMTP_PORT),
|
||||
SMTP_SECURE: process.env.SMTP_SECURE === 'true',
|
||||
SMTP_USER: process.env.SMTP_USER,
|
||||
SMTP_SENDER: process.env.SMTP_SENDER,
|
||||
SMTP_PASSWORD: process.env.SMTP_PASSWORD,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -79,7 +79,6 @@ export const allCountries = [
|
||||
'Iran',
|
||||
'Iraq',
|
||||
'Ireland',
|
||||
'Israel',
|
||||
'Italy',
|
||||
'Jamaica',
|
||||
'Japan',
|
||||
|
||||
@@ -4,18 +4,18 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { SnakeNamingStrategy } from './strategies';
|
||||
import { UserEntity } from '../modules/user/entities/user.entity';
|
||||
import { UserSessionEntity } from '../modules/session/entities/session.entity';
|
||||
import { UserOtpEntity } from '../modules/user-otp/entities';
|
||||
import { UserOtpEntity } from '../modules/user/entities';
|
||||
import { ProductEntity } from '../modules/product/entities';
|
||||
import { DeviceEntity } from '../modules/device/entities';
|
||||
import { PermissionTypeEntity } from '../modules/permission/entities';
|
||||
import { SpaceEntity } from '../modules/space/entities';
|
||||
import { SpaceTypeEntity } from '../modules/space-type/entities';
|
||||
import { UserSpaceEntity } from '../modules/user-space/entities';
|
||||
import { DeviceUserPermissionEntity } from '../modules/device-user-permission/entities';
|
||||
import { UserRoleEntity } from '../modules/user-role/entities';
|
||||
import { SpaceTypeEntity } from '../modules/space/entities';
|
||||
import { UserSpaceEntity } from '../modules/user/entities';
|
||||
import { DeviceUserPermissionEntity } from '../modules/device/entities';
|
||||
import { UserRoleEntity } from '../modules/user/entities';
|
||||
import { RoleTypeEntity } from '../modules/role-type/entities';
|
||||
import { UserNotificationEntity } from '../modules/user-notification/entities';
|
||||
import { DeviceNotificationEntity } from '../modules/device-notification/entities';
|
||||
import { UserNotificationEntity } from '../modules/user/entities';
|
||||
import { DeviceNotificationEntity } from '../modules/device/entities';
|
||||
import { RegionEntity } from '../modules/region/entities';
|
||||
import { TimeZoneEntity } from '../modules/timezone/entities';
|
||||
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
import { SnakeNamingStrategy } from './snack-naming.strategy';
|
||||
import { snakeCase } from 'typeorm/util/StringUtils';
|
||||
|
||||
describe('SnakeNamingStrategy', () => {
|
||||
let strategy: SnakeNamingStrategy;
|
||||
|
||||
beforeEach(() => {
|
||||
strategy = new SnakeNamingStrategy();
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(strategy).toBeDefined();
|
||||
});
|
||||
|
||||
describe('tableName', () => {
|
||||
it('should use customName if provided', () => {
|
||||
const className = 'User';
|
||||
const customName = 'users_table';
|
||||
expect(strategy.tableName(className, customName)).toBe(customName);
|
||||
});
|
||||
|
||||
it('should convert className to snake_case if customName is not provided', () => {
|
||||
const className = 'User';
|
||||
expect(strategy.tableName(className, '')).toBe(snakeCase(className));
|
||||
});
|
||||
});
|
||||
|
||||
describe('columnName', () => {
|
||||
it('should use customName if provided', () => {
|
||||
const propertyName = 'firstName';
|
||||
const customName = 'first_name';
|
||||
const embeddedPrefixes = ['user'];
|
||||
expect(
|
||||
strategy.columnName(propertyName, customName, embeddedPrefixes),
|
||||
).toBe(snakeCase(embeddedPrefixes.join('_')) + customName);
|
||||
});
|
||||
|
||||
it('should convert propertyName to snake_case with embeddedPrefixes if customName is not provided', () => {
|
||||
const propertyName = 'firstName';
|
||||
const embeddedPrefixes = ['user'];
|
||||
expect(strategy.columnName(propertyName, '', embeddedPrefixes)).toBe(
|
||||
snakeCase(embeddedPrefixes.join('_')) + snakeCase(propertyName),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('relationName', () => {
|
||||
it('should convert propertyName to snake_case', () => {
|
||||
const propertyName = 'profilePicture';
|
||||
expect(strategy.relationName(propertyName)).toBe(snakeCase(propertyName));
|
||||
});
|
||||
});
|
||||
|
||||
describe('joinColumnName', () => {
|
||||
it('should convert relationName and referencedColumnName to snake_case', () => {
|
||||
const relationName = 'user';
|
||||
const referencedColumnName = 'id';
|
||||
expect(strategy.joinColumnName(relationName, referencedColumnName)).toBe(
|
||||
snakeCase(`${relationName}_${referencedColumnName}`),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('joinTableName', () => {
|
||||
it('should convert table names and property name to snake_case', () => {
|
||||
const firstTableName = 'users';
|
||||
const secondTableName = 'roles';
|
||||
const firstPropertyName = 'userRoles';
|
||||
expect(
|
||||
strategy.joinTableName(
|
||||
firstTableName,
|
||||
secondTableName,
|
||||
firstPropertyName,
|
||||
),
|
||||
).toBe(
|
||||
snakeCase(
|
||||
`${firstTableName}_${firstPropertyName.replaceAll(/\./gi, '_')}_${secondTableName}`,
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('joinTableColumnName', () => {
|
||||
it('should use columnName if provided', () => {
|
||||
const tableName = 'user_roles';
|
||||
const propertyName = 'user';
|
||||
const columnName = 'role';
|
||||
expect(
|
||||
strategy.joinTableColumnName(tableName, propertyName, columnName),
|
||||
).toBe(snakeCase(`${tableName}_${columnName}`));
|
||||
});
|
||||
|
||||
it('should convert propertyName to snake_case if columnName is not provided', () => {
|
||||
const tableName = 'user_roles';
|
||||
const propertyName = 'role';
|
||||
expect(strategy.joinTableColumnName(tableName, propertyName)).toBe(
|
||||
snakeCase(`${tableName}_${propertyName}`),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('classTableInheritanceParentColumnName', () => {
|
||||
it('should convert parentTableName and parentTableIdPropertyName to snake_case', () => {
|
||||
const parentTableName = 'users';
|
||||
const parentTableIdPropertyName = 'id';
|
||||
expect(
|
||||
strategy.classTableInheritanceParentColumnName(
|
||||
parentTableName,
|
||||
parentTableIdPropertyName,
|
||||
),
|
||||
).toBe(snakeCase(`${parentTableName}_${parentTableIdPropertyName}`));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,86 @@
|
||||
import { convertKeysToCamelCase } from './camelCaseConverter';
|
||||
|
||||
describe('convertKeysToCamelCase', () => {
|
||||
it('should return the same value if not an object or array', () => {
|
||||
expect(convertKeysToCamelCase(null)).toBeNull();
|
||||
expect(convertKeysToCamelCase(undefined)).toBeUndefined();
|
||||
expect(convertKeysToCamelCase(123)).toBe(123);
|
||||
expect(convertKeysToCamelCase('string')).toBe('string');
|
||||
expect(convertKeysToCamelCase(true)).toBe(true);
|
||||
expect(convertKeysToCamelCase(false)).toBe(false);
|
||||
});
|
||||
|
||||
it('should convert object keys from snake_case to camelCase', () => {
|
||||
const obj = {
|
||||
first_name: 'John',
|
||||
last_name: 'Doe',
|
||||
address_details: {
|
||||
street_name: 'Main St',
|
||||
postal_code: '12345',
|
||||
},
|
||||
};
|
||||
|
||||
const expected = {
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
addressDetails: {
|
||||
streetName: 'Main St',
|
||||
postalCode: '12345',
|
||||
},
|
||||
};
|
||||
|
||||
expect(convertKeysToCamelCase(obj)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should convert array of objects with snake_case keys to camelCase', () => {
|
||||
const arr = [
|
||||
{ first_name: 'Jane', last_name: 'Doe' },
|
||||
{ first_name: 'John', last_name: 'Smith' },
|
||||
];
|
||||
|
||||
const expected = [
|
||||
{ firstName: 'Jane', lastName: 'Doe' },
|
||||
{ firstName: 'John', lastName: 'Smith' },
|
||||
];
|
||||
|
||||
expect(convertKeysToCamelCase(arr)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should handle nested arrays and objects', () => {
|
||||
const nestedObj = {
|
||||
user_info: {
|
||||
user_name: 'Alice',
|
||||
contact_details: [
|
||||
{ email_address: '[email protected]' },
|
||||
{ phone_number: '123-456-7890' },
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const expected = {
|
||||
userInfo: {
|
||||
userName: 'Alice',
|
||||
contactDetails: [
|
||||
{ emailAddress: '[email protected]' },
|
||||
{ phoneNumber: '123-456-7890' },
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
expect(convertKeysToCamelCase(nestedObj)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should handle objects with no snake_case keys', () => {
|
||||
const obj = {
|
||||
firstName: 'Alice',
|
||||
lastName: 'Johnson',
|
||||
};
|
||||
|
||||
const expected = {
|
||||
firstName: 'Alice',
|
||||
lastName: 'Johnson',
|
||||
};
|
||||
|
||||
expect(convertKeysToCamelCase(obj)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
@@ -7,8 +7,8 @@ import { TuyaWebSocketService } from './services/tuya.web.socket.service';
|
||||
|
||||
import { OneSignalService } from './services/onesignal.service';
|
||||
import { DeviceMessagesService } from './services/device.messages.service';
|
||||
import { DeviceNotificationRepositoryModule } from '../modules/device-notification/device.notification.module';
|
||||
import { DeviceNotificationRepository } from '../modules/device-notification/repositories';
|
||||
import { DeviceRepositoryModule } from '../modules/device/device.repository.module';
|
||||
import { DeviceNotificationRepository } from '../modules/device/repositories';
|
||||
import { DeviceStatusFirebaseModule } from '../firebase/devices-status/devices-status.module';
|
||||
|
||||
@Global()
|
||||
@@ -26,7 +26,7 @@ import { DeviceStatusFirebaseModule } from '../firebase/devices-status/devices-s
|
||||
controllers: [],
|
||||
imports: [
|
||||
SpaceRepositoryModule,
|
||||
DeviceNotificationRepositoryModule,
|
||||
DeviceRepositoryModule,
|
||||
DeviceStatusFirebaseModule,
|
||||
],
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { DeviceNotificationRepository } from '@app/common/modules/device-notification/repositories';
|
||||
import { DeviceNotificationRepository } from '@app/common/modules/device/repositories';
|
||||
import { OneSignalService } from './onesignal.service';
|
||||
|
||||
@Injectable()
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
import { HelperHashService } from './helper.hash.service';
|
||||
import { enc, SHA256 } from 'crypto-js';
|
||||
describe('HelperHashService', () => {
|
||||
let service: HelperHashService;
|
||||
const secretKey = '12345678901234567890123456789012';
|
||||
const iv = '1234567890123456';
|
||||
const password = 'password123';
|
||||
let salt: string;
|
||||
let hashedPassword: string;
|
||||
|
||||
beforeEach(() => {
|
||||
service = new HelperHashService();
|
||||
salt = service.randomSalt(10);
|
||||
hashedPassword = service.bcrypt(password, salt);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
|
||||
describe('randomSalt', () => {
|
||||
it('should generate a salt of the specified length', () => {
|
||||
expect(service.randomSalt(10)).toHaveLength(29);
|
||||
});
|
||||
});
|
||||
|
||||
describe('bcrypt', () => {
|
||||
it('should hash the password with the given salt', () => {
|
||||
expect(service.bcrypt(password, salt)).toBe(hashedPassword);
|
||||
});
|
||||
});
|
||||
|
||||
describe('bcryptCompare', () => {
|
||||
it('should return true for correct password comparison', () => {
|
||||
expect(service.bcryptCompare(password, hashedPassword)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for incorrect password comparison', () => {
|
||||
expect(service.bcryptCompare('wrongpassword', hashedPassword)).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sha256', () => {
|
||||
it('should hash a string using SHA256', () => {
|
||||
const hash = SHA256(password).toString(enc.Hex);
|
||||
expect(service.sha256(password)).toBe(hash);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sha256Compare', () => {
|
||||
it('should return true for identical SHA256 hashes', () => {
|
||||
const hash = SHA256(password).toString(enc.Hex);
|
||||
expect(service.sha256Compare(hash, hash)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for different SHA256 hashes', () => {
|
||||
const hash1 = SHA256(password).toString(enc.Hex);
|
||||
const hash2 = SHA256('anotherpassword').toString(enc.Hex);
|
||||
expect(service.sha256Compare(hash1, hash2)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('encryptPassword', () => {
|
||||
it('should encrypt a password with the given secret key', () => {
|
||||
const encrypted = service.encryptPassword(password, secretKey);
|
||||
const decrypted = service.decryptPassword(encrypted, secretKey);
|
||||
expect(decrypted).toBe('trx8g6gi');
|
||||
});
|
||||
});
|
||||
|
||||
describe('decryptPassword', () => {
|
||||
it('should decrypt an encrypted password with the given secret key', () => {
|
||||
const encrypted = service.encryptPassword(password, secretKey);
|
||||
const decrypted = service.decryptPassword(encrypted, secretKey);
|
||||
expect(decrypted).toBe('trx8g6gi');
|
||||
});
|
||||
});
|
||||
|
||||
describe('aes256Encrypt', () => {
|
||||
it('should encrypt data with AES-256 and return the ciphertext', () => {
|
||||
const data = { key: 'value' };
|
||||
const encrypted = service.aes256Encrypt(data, secretKey, iv);
|
||||
expect(encrypted).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('aes256Decrypt', () => {
|
||||
it('should decrypt data with AES-256 and return the plaintext', async () => {
|
||||
const data = { key: 'value' };
|
||||
const encrypted = service.aes256Encrypt(data, secretKey, iv);
|
||||
const decrypted = service.aes256Decrypt(encrypted, secretKey, iv);
|
||||
expect(decrypted).toBeDefined();
|
||||
expect(() => JSON.parse(decrypted)).not.toThrow();
|
||||
expect(JSON.parse(decrypted)).toEqual(data);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,54 @@
|
||||
import { convertKeysToSnakeCase } from './snakeCaseConverter';
|
||||
|
||||
describe('convertKeysToSnakeCase', () => {
|
||||
it('should convert single level object keys to snake case', () => {
|
||||
const input = { camelCase: 'value', anotherKey: 'anotherValue' };
|
||||
const expected = { camel_case: 'value', another_key: 'anotherValue' };
|
||||
expect(convertKeysToSnakeCase(input)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should convert nested object keys to snake case', () => {
|
||||
const input = {
|
||||
camelCaseKey: 'value',
|
||||
nestedObject: {
|
||||
nestedCamelCase: 'nestedValue',
|
||||
arrayOfObjects: [
|
||||
{ arrayCamelCase: 'arrayValue' },
|
||||
{ anotherCamelCase: 'anotherValue' },
|
||||
],
|
||||
},
|
||||
};
|
||||
const expected = {
|
||||
camel_case_key: 'value',
|
||||
nested_object: {
|
||||
nested_camel_case: 'nestedValue',
|
||||
array_of_objects: [
|
||||
{ array_camel_case: 'arrayValue' },
|
||||
{ another_camel_case: 'anotherValue' },
|
||||
],
|
||||
},
|
||||
};
|
||||
expect(convertKeysToSnakeCase(input)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should handle arrays of objects', () => {
|
||||
const input = [{ camelCaseItem: 'value' }, { anotherItem: 'anotherValue' }];
|
||||
const expected = [
|
||||
{ camel_case_item: 'value' },
|
||||
{ another_item: 'anotherValue' },
|
||||
];
|
||||
expect(convertKeysToSnakeCase(input)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should handle empty objects and arrays', () => {
|
||||
expect(convertKeysToSnakeCase({})).toEqual({});
|
||||
expect(convertKeysToSnakeCase([])).toEqual([]);
|
||||
});
|
||||
|
||||
it('should handle primitive values without modification', () => {
|
||||
expect(convertKeysToSnakeCase('string')).toEqual('string');
|
||||
expect(convertKeysToSnakeCase(123)).toEqual(123);
|
||||
expect(convertKeysToSnakeCase(null)).toEqual(null);
|
||||
expect(convertKeysToSnakeCase(undefined)).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
@@ -1,10 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { DeviceNotificationEntity } from './entities';
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [TypeOrmModule.forFeature([DeviceNotificationEntity])],
|
||||
})
|
||||
export class DeviceNotificationRepositoryModule {}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class DeviceNotificationDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public userUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public deviceUuid: string;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './device.notification.dto';
|
||||
@@ -1,33 +0,0 @@
|
||||
import { Column, Entity, ManyToOne, Unique } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { DeviceNotificationDto } from '../dtos';
|
||||
import { DeviceEntity } from '../../device/entities';
|
||||
import { UserEntity } from '../../user/entities';
|
||||
|
||||
@Entity({ name: 'device-notification' })
|
||||
@Unique(['userUuid', 'deviceUuid'])
|
||||
export class DeviceNotificationEntity extends AbstractEntity<DeviceNotificationDto> {
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
public userUuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
deviceUuid: string;
|
||||
|
||||
@ManyToOne(() => DeviceEntity, (device) => device.permission, {
|
||||
nullable: false,
|
||||
})
|
||||
device: DeviceEntity;
|
||||
|
||||
@ManyToOne(() => UserEntity, (user) => user.userPermission, {
|
||||
nullable: false,
|
||||
})
|
||||
user: UserEntity;
|
||||
constructor(partial: Partial<DeviceNotificationEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './device.notification.entity';
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { DeviceNotificationEntity } from '../entities';
|
||||
|
||||
@Injectable()
|
||||
export class DeviceNotificationRepository extends Repository<DeviceNotificationEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(DeviceNotificationEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './device.notification.repository';
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { DeviceUserPermissionEntity } from './entities';
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [TypeOrmModule.forFeature([DeviceUserPermissionEntity])],
|
||||
})
|
||||
export class DeviceUserPermissionRepositoryModule {}
|
||||
@@ -1,19 +0,0 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class DeviceUserPermissionDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public userUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public deviceUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public permissionTypeUuid: string;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './device.user.permission.dto';
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
import { Column, Entity, ManyToOne, Unique } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { DeviceUserPermissionDto } from '../dtos';
|
||||
import { PermissionTypeEntity } from '../../permission/entities';
|
||||
import { DeviceEntity } from '../../device/entities';
|
||||
import { UserEntity } from '../../user/entities';
|
||||
|
||||
@Entity({ name: 'device-user-permission' })
|
||||
@Unique(['userUuid', 'deviceUuid'])
|
||||
export class DeviceUserPermissionEntity extends AbstractEntity<DeviceUserPermissionDto> {
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
public userUuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
deviceUuid: string;
|
||||
|
||||
@ManyToOne(() => DeviceEntity, (device) => device.permission, {
|
||||
nullable: false,
|
||||
})
|
||||
device: DeviceEntity;
|
||||
|
||||
@ManyToOne(
|
||||
() => PermissionTypeEntity,
|
||||
(permissionType) => permissionType.permission,
|
||||
{
|
||||
nullable: false,
|
||||
},
|
||||
)
|
||||
permissionType: PermissionTypeEntity;
|
||||
|
||||
@ManyToOne(() => UserEntity, (user) => user.userPermission, {
|
||||
nullable: false,
|
||||
})
|
||||
user: UserEntity;
|
||||
constructor(partial: Partial<DeviceUserPermissionEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './device.user.permission.entity';
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { DeviceUserPermissionEntity } from '../entities';
|
||||
|
||||
@Injectable()
|
||||
export class DeviceUserPermissionRepository extends Repository<DeviceUserPermissionEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(DeviceUserPermissionEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './device.user.permission.repository';
|
||||
@@ -1,11 +1,21 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { DeviceEntity } from './entities';
|
||||
import {
|
||||
DeviceEntity,
|
||||
DeviceNotificationEntity,
|
||||
DeviceUserPermissionEntity,
|
||||
} from './entities';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [TypeOrmModule.forFeature([DeviceEntity])],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([
|
||||
DeviceEntity,
|
||||
DeviceNotificationEntity,
|
||||
DeviceUserPermissionEntity,
|
||||
]),
|
||||
],
|
||||
})
|
||||
export class DeviceRepositoryModule {}
|
||||
|
||||
@@ -21,3 +21,35 @@ export class DeviceDto {
|
||||
@IsNotEmpty()
|
||||
productUuid: string;
|
||||
}
|
||||
|
||||
export class DeviceUserPermissionDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public userUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public deviceUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public permissionTypeUuid: string;
|
||||
}
|
||||
|
||||
export class DeviceNotificationDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public userUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public deviceUuid: string;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Column, Entity, ManyToOne, OneToMany, Unique, Index } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { DeviceDto } from '../dtos/device.dto';
|
||||
import { DeviceDto, DeviceUserPermissionDto } from '../dtos/device.dto';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
import { ProductEntity } from '../../product/entities';
|
||||
import { DeviceUserPermissionEntity } from '../../device-user-permission/entities';
|
||||
import { DeviceNotificationEntity } from '../../device-notification/entities';
|
||||
import { UserEntity } from '../../user/entities';
|
||||
import { DeviceNotificationDto } from '../dtos';
|
||||
import { PermissionTypeEntity } from '../../permission/entities';
|
||||
|
||||
@Entity({ name: 'device' })
|
||||
@Unique(['deviceTuyaUuid'])
|
||||
@@ -60,3 +60,68 @@ export class DeviceEntity extends AbstractEntity<DeviceDto> {
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@Entity({ name: 'device-notification' })
|
||||
@Unique(['userUuid', 'deviceUuid'])
|
||||
export class DeviceNotificationEntity extends AbstractEntity<DeviceNotificationDto> {
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
public userUuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
deviceUuid: string;
|
||||
|
||||
@ManyToOne(() => DeviceEntity, (device) => device.permission, {
|
||||
nullable: false,
|
||||
})
|
||||
device: DeviceEntity;
|
||||
|
||||
@ManyToOne(() => UserEntity, (user) => user.userPermission, {
|
||||
nullable: false,
|
||||
})
|
||||
user: UserEntity;
|
||||
constructor(partial: Partial<DeviceNotificationEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@Entity({ name: 'device-user-permission' })
|
||||
@Unique(['userUuid', 'deviceUuid'])
|
||||
export class DeviceUserPermissionEntity extends AbstractEntity<DeviceUserPermissionDto> {
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
public userUuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
deviceUuid: string;
|
||||
|
||||
@ManyToOne(() => DeviceEntity, (device) => device.permission, {
|
||||
nullable: false,
|
||||
})
|
||||
device: DeviceEntity;
|
||||
|
||||
@ManyToOne(
|
||||
() => PermissionTypeEntity,
|
||||
(permissionType) => permissionType.permission,
|
||||
{
|
||||
nullable: false,
|
||||
},
|
||||
)
|
||||
permissionType: PermissionTypeEntity;
|
||||
|
||||
@ManyToOne(() => UserEntity, (user) => user.userPermission, {
|
||||
nullable: false,
|
||||
})
|
||||
user: UserEntity;
|
||||
constructor(partial: Partial<DeviceUserPermissionEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { DeviceEntity } from '../entities';
|
||||
import {
|
||||
DeviceEntity,
|
||||
DeviceNotificationEntity,
|
||||
DeviceUserPermissionEntity,
|
||||
} from '../entities';
|
||||
|
||||
@Injectable()
|
||||
export class DeviceRepository extends Repository<DeviceEntity> {
|
||||
@@ -8,3 +12,15 @@ export class DeviceRepository extends Repository<DeviceEntity> {
|
||||
super(DeviceEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
@Injectable()
|
||||
export class DeviceNotificationRepository extends Repository<DeviceNotificationEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(DeviceNotificationEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
@Injectable()
|
||||
export class DeviceUserPermissionRepository extends Repository<DeviceUserPermissionEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(DeviceUserPermissionEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Column, Entity, OneToMany } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { PermissionType } from '@app/common/constants/permission-type.enum';
|
||||
import { PermissionTypeDto } from '../dtos/permission.dto';
|
||||
import { DeviceUserPermissionEntity } from '../../device-user-permission/entities';
|
||||
import { DeviceUserPermissionEntity } from '../../device/entities';
|
||||
|
||||
@Entity({ name: 'permission-type' })
|
||||
export class PermissionTypeEntity extends AbstractEntity<PermissionTypeDto> {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Column, Entity, OneToMany, Unique } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { RoleTypeDto } from '../dtos/role.type.dto';
|
||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||
import { UserRoleEntity } from '../../user-role/entities';
|
||||
import { UserRoleEntity } from '../../user/entities';
|
||||
|
||||
@Entity({ name: 'role-type' })
|
||||
@Unique(['type'])
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export * from './space.type.dto';
|
||||
@@ -1,11 +0,0 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class SpaceTypeDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public type: string;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './space.type.entity';
|
||||
@@ -1,26 +0,0 @@
|
||||
import { Column, Entity, OneToMany } from 'typeorm';
|
||||
import { SpaceTypeDto } from '../dtos';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
|
||||
@Entity({ name: 'space-type' })
|
||||
export class SpaceTypeEntity extends AbstractEntity<SpaceTypeDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()', // Use gen_random_uuid() for default value
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
type: string;
|
||||
|
||||
@OneToMany(() => SpaceEntity, (space) => space.spaceType)
|
||||
spaces: SpaceEntity[];
|
||||
constructor(partial: Partial<SpaceTypeEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './space.type.repository';
|
||||
@@ -1,10 +0,0 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { SpaceTypeEntity } from '../entities/space.type.entity';
|
||||
|
||||
@Injectable()
|
||||
export class SpaceTypeRepository extends Repository<SpaceTypeEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(SpaceTypeEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { SpaceTypeEntity } from './entities/space.type.entity';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [TypeOrmModule.forFeature([SpaceTypeEntity])],
|
||||
})
|
||||
export class SpaceTypeRepositoryModule {}
|
||||
@@ -21,3 +21,13 @@ export class SpaceDto {
|
||||
@IsNotEmpty()
|
||||
public invitationCode: string;
|
||||
}
|
||||
|
||||
export class SpaceTypeDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public type: string;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,37 @@
|
||||
import { Column, Entity, ManyToOne, OneToMany, Unique } from 'typeorm';
|
||||
import { SpaceDto } from '../dtos';
|
||||
import { SpaceDto, SpaceTypeDto } from '../dtos';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { SpaceTypeEntity } from '../../space-type/entities';
|
||||
import { UserSpaceEntity } from '../../user-space/entities';
|
||||
import { UserSpaceEntity } from '../../user/entities';
|
||||
import { DeviceEntity } from '../../device/entities';
|
||||
|
||||
@Entity({ name: 'space-type' })
|
||||
export class SpaceTypeEntity extends AbstractEntity<SpaceTypeDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
type: string;
|
||||
|
||||
@OneToMany(() => SpaceEntity, (space) => space.spaceType)
|
||||
spaces: SpaceEntity[];
|
||||
constructor(partial: Partial<SpaceTypeEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@Entity({ name: 'space' })
|
||||
@Unique(['invitationCode'])
|
||||
export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()', // Use gen_random_uuid() for default value
|
||||
default: () => 'gen_random_uuid()',
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { SpaceEntity } from '../entities/space.entity';
|
||||
import { SpaceEntity, SpaceTypeEntity } from '../entities';
|
||||
|
||||
@Injectable()
|
||||
export class SpaceRepository extends Repository<SpaceEntity> {
|
||||
@@ -8,3 +8,10 @@ export class SpaceRepository extends Repository<SpaceEntity> {
|
||||
super(SpaceEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class SpaceTypeRepository extends Repository<SpaceTypeEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(SpaceTypeEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { SpaceEntity } from './entities/space.entity';
|
||||
import { SpaceEntity, SpaceTypeEntity } from './entities';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [TypeOrmModule.forFeature([SpaceEntity])],
|
||||
imports: [TypeOrmModule.forFeature([SpaceEntity, SpaceTypeEntity])],
|
||||
})
|
||||
export class SpaceRepositoryModule {}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export * from './user.notification.dto';
|
||||
@@ -1,19 +0,0 @@
|
||||
import { IsBoolean, IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class UserNotificationDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public userUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public subscriptionUuid: string;
|
||||
|
||||
@IsBoolean()
|
||||
@IsNotEmpty()
|
||||
public active: boolean;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './user.notification.entity';
|
||||
@@ -1,27 +0,0 @@
|
||||
import { Column, Entity, ManyToOne, Unique } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { UserNotificationDto } from '../dtos';
|
||||
import { UserEntity } from '../../user/entities';
|
||||
|
||||
@Entity({ name: 'user-notification' })
|
||||
@Unique(['user', 'subscriptionUuid'])
|
||||
export class UserNotificationEntity extends AbstractEntity<UserNotificationDto> {
|
||||
@ManyToOne(() => UserEntity, (user) => user.roles, {
|
||||
nullable: false,
|
||||
})
|
||||
user: UserEntity;
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
subscriptionUuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
default: true,
|
||||
})
|
||||
active: boolean;
|
||||
constructor(partial: Partial<UserNotificationEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './user.notification.repository';
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { UserNotificationEntity } from '../entities';
|
||||
|
||||
@Injectable()
|
||||
export class UserNotificationRepository extends Repository<UserNotificationEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(UserNotificationEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { UserNotificationEntity } from './entities';
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [TypeOrmModule.forFeature([UserNotificationEntity])],
|
||||
})
|
||||
export class UserNotificationRepositoryModule {}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './user-otp.dto';
|
||||
@@ -1,19 +0,0 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class UserOtpDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public email: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public otpCode: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public expiryTime: string;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './user-otp.entity';
|
||||
@@ -1,34 +0,0 @@
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { UserOtpDto } from '../dtos';
|
||||
import { OtpType } from '../../../../src/constants/otp-type.enum';
|
||||
|
||||
@Entity({ name: 'user-otp' })
|
||||
export class UserOtpEntity extends AbstractEntity<UserOtpDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@Column({ nullable: false })
|
||||
email: string;
|
||||
|
||||
@Column({ nullable: false })
|
||||
otpCode: string;
|
||||
|
||||
@Column({ nullable: false })
|
||||
expiryTime: Date;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: Object.values(OtpType),
|
||||
})
|
||||
type: OtpType;
|
||||
|
||||
constructor(partial: Partial<UserOtpEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { UserOtpEntity } from '../entities';
|
||||
|
||||
@Injectable()
|
||||
export class UserOtpRepository extends Repository<UserOtpEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(UserOtpEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { UserOtpEntity } from './entities';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [TypeOrmModule.forFeature([UserOtpEntity])],
|
||||
})
|
||||
export class UserOtpRepositoryModule {}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './user.role.dto';
|
||||
@@ -1,15 +0,0 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class UserRoleDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public userUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public roleTypeUuid: string;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './user.role.entity';
|
||||
@@ -1,24 +0,0 @@
|
||||
import { Entity, ManyToOne, Unique } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { UserRoleDto } from '../dtos';
|
||||
import { UserEntity } from '../../user/entities';
|
||||
import { RoleTypeEntity } from '../../role-type/entities';
|
||||
|
||||
@Entity({ name: 'user-role' })
|
||||
@Unique(['user', 'roleType'])
|
||||
export class UserRoleEntity extends AbstractEntity<UserRoleDto> {
|
||||
@ManyToOne(() => UserEntity, (user) => user.roles, {
|
||||
nullable: false,
|
||||
})
|
||||
user: UserEntity;
|
||||
|
||||
@ManyToOne(() => RoleTypeEntity, (roleType) => roleType.roles, {
|
||||
nullable: false,
|
||||
})
|
||||
roleType: RoleTypeEntity;
|
||||
|
||||
constructor(partial: Partial<UserRoleEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './user.role.repository';
|
||||
@@ -1,10 +0,0 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { UserRoleEntity } from '../entities';
|
||||
|
||||
@Injectable()
|
||||
export class UserRoleRepository extends Repository<UserRoleEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(UserRoleEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { UserRoleEntity } from './entities';
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [TypeOrmModule.forFeature([UserRoleEntity])],
|
||||
})
|
||||
export class UserRoleRepositoryModule {}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './user.space.dto';
|
||||
@@ -1,15 +0,0 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class UserSpaceDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public spaceUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public userUuid: string;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './user.space.entity';
|
||||
@@ -1,29 +0,0 @@
|
||||
import { Column, Entity, ManyToOne, Unique } from 'typeorm';
|
||||
import { UserSpaceDto } from '../dtos';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
import { UserEntity } from '../../user/entities';
|
||||
|
||||
@Entity({ name: 'user-space' })
|
||||
@Unique(['user', 'space'])
|
||||
export class UserSpaceEntity extends AbstractEntity<UserSpaceDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()', // Use gen_random_uuid() for default value
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@ManyToOne(() => UserEntity, (user) => user.userSpaces, { nullable: false })
|
||||
user: UserEntity;
|
||||
|
||||
@ManyToOne(() => SpaceEntity, (space) => space.userSpaces, {
|
||||
nullable: false,
|
||||
})
|
||||
space: SpaceEntity;
|
||||
|
||||
constructor(partial: Partial<UserSpaceEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './user.space.repository';
|
||||
@@ -1,10 +0,0 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { UserSpaceEntity } from '../entities/user.space.entity';
|
||||
|
||||
@Injectable()
|
||||
export class UserSpaceRepository extends Repository<UserSpaceEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(UserSpaceEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { UserSpaceEntity } from './entities/user.space.entity';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [TypeOrmModule.forFeature([UserSpaceEntity])],
|
||||
})
|
||||
export class UserSpaceRepositoryModule {}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
import { IsBoolean, IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class UserDto {
|
||||
@IsString()
|
||||
@@ -21,3 +21,67 @@ export class UserDto {
|
||||
@IsNotEmpty()
|
||||
public lastName: string;
|
||||
}
|
||||
|
||||
export class UserNotificationDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public userUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public subscriptionUuid: string;
|
||||
|
||||
@IsBoolean()
|
||||
@IsNotEmpty()
|
||||
public active: boolean;
|
||||
}
|
||||
|
||||
export class UserOtpDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public email: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public otpCode: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public expiryTime: string;
|
||||
}
|
||||
|
||||
export class UserRoleDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public userUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public roleTypeUuid: string;
|
||||
}
|
||||
|
||||
export class UserSpaceDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public spaceUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public userUuid: string;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
import { DeviceUserPermissionEntity } from '../../device-user-permission/entities/device.user.permission.entity';
|
||||
import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
|
||||
import { UserDto } from '../dtos';
|
||||
import { Column, Entity, ManyToOne, OneToMany, Unique } from 'typeorm';
|
||||
import {
|
||||
UserDto,
|
||||
UserNotificationDto,
|
||||
UserOtpDto,
|
||||
UserRoleDto,
|
||||
UserSpaceDto,
|
||||
} from '../dtos';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { UserSpaceEntity } from '../../user-space/entities';
|
||||
import { UserRoleEntity } from '../../user-role/entities';
|
||||
import { DeviceNotificationEntity } from '../../device-notification/entities';
|
||||
import { UserNotificationEntity } from '../../user-notification/entities';
|
||||
import { DeviceEntity } from '../../device/entities';
|
||||
import {
|
||||
DeviceEntity,
|
||||
DeviceNotificationEntity,
|
||||
DeviceUserPermissionEntity,
|
||||
} from '../../device/entities';
|
||||
import { defaultProfilePicture } from '@app/common/constants/default.profile.picture';
|
||||
import { RegionEntity } from '../../region/entities';
|
||||
import { TimeZoneEntity } from '../../timezone/entities';
|
||||
import { OtpType } from '../../../../src/constants/otp-type.enum';
|
||||
import { RoleTypeEntity } from '../../role-type/entities';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
|
||||
@Entity({ name: 'user' })
|
||||
export class UserEntity extends AbstractEntity<UserDto> {
|
||||
@@ -99,3 +107,99 @@ export class UserEntity extends AbstractEntity<UserDto> {
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@Entity({ name: 'user-notification' })
|
||||
@Unique(['user', 'subscriptionUuid'])
|
||||
export class UserNotificationEntity extends AbstractEntity<UserNotificationDto> {
|
||||
@ManyToOne(() => UserEntity, (user) => user.roles, {
|
||||
nullable: false,
|
||||
})
|
||||
user: UserEntity;
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
subscriptionUuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
default: true,
|
||||
})
|
||||
active: boolean;
|
||||
constructor(partial: Partial<UserNotificationEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@Entity({ name: 'user-otp' })
|
||||
export class UserOtpEntity extends AbstractEntity<UserOtpDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@Column({ nullable: false })
|
||||
email: string;
|
||||
|
||||
@Column({ nullable: false })
|
||||
otpCode: string;
|
||||
|
||||
@Column({ nullable: false })
|
||||
expiryTime: Date;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: Object.values(OtpType),
|
||||
})
|
||||
type: OtpType;
|
||||
|
||||
constructor(partial: Partial<UserOtpEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@Entity({ name: 'user-role' })
|
||||
@Unique(['user', 'roleType'])
|
||||
export class UserRoleEntity extends AbstractEntity<UserRoleDto> {
|
||||
@ManyToOne(() => UserEntity, (user) => user.roles, {
|
||||
nullable: false,
|
||||
})
|
||||
user: UserEntity;
|
||||
|
||||
@ManyToOne(() => RoleTypeEntity, (roleType) => roleType.roles, {
|
||||
nullable: false,
|
||||
})
|
||||
roleType: RoleTypeEntity;
|
||||
|
||||
constructor(partial: Partial<UserRoleEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@Entity({ name: 'user-space' })
|
||||
@Unique(['user', 'space'])
|
||||
export class UserSpaceEntity extends AbstractEntity<UserSpaceDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()', // Use gen_random_uuid() for default value
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@ManyToOne(() => UserEntity, (user) => user.userSpaces, { nullable: false })
|
||||
user: UserEntity;
|
||||
|
||||
@ManyToOne(() => SpaceEntity, (space) => space.userSpaces, {
|
||||
nullable: false,
|
||||
})
|
||||
space: SpaceEntity;
|
||||
|
||||
constructor(partial: Partial<UserSpaceEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { UserEntity } from '../entities/user.entity';
|
||||
import {
|
||||
UserEntity,
|
||||
UserNotificationEntity,
|
||||
UserOtpEntity,
|
||||
UserRoleEntity,
|
||||
UserSpaceEntity,
|
||||
} from '../entities/';
|
||||
|
||||
@Injectable()
|
||||
export class UserRepository extends Repository<UserEntity> {
|
||||
@@ -8,3 +14,31 @@ export class UserRepository extends Repository<UserEntity> {
|
||||
super(UserEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class UserNotificationRepository extends Repository<UserNotificationEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(UserNotificationEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class UserOtpRepository extends Repository<UserOtpEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(UserOtpEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class UserRoleRepository extends Repository<UserRoleEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(UserRoleEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class UserSpaceRepository extends Repository<UserSpaceEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(UserSpaceEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,25 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { UserEntity } from './entities/user.entity';
|
||||
import {
|
||||
UserEntity,
|
||||
UserNotificationEntity,
|
||||
UserOtpEntity,
|
||||
UserRoleEntity,
|
||||
UserSpaceEntity,
|
||||
} from './entities';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [TypeOrmModule.forFeature([UserEntity])],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([
|
||||
UserEntity,
|
||||
UserNotificationEntity,
|
||||
UserOtpEntity,
|
||||
UserRoleEntity,
|
||||
UserSpaceEntity,
|
||||
]),
|
||||
],
|
||||
})
|
||||
export class UserRepositoryModule {}
|
||||
|
||||
@@ -7,13 +7,12 @@ import { ConfigModule } from '@nestjs/config';
|
||||
import { RoleTypeRepositoryModule } from '../modules/role-type/role.type.repository.module';
|
||||
import { RoleTypeRepository } from '../modules/role-type/repositories';
|
||||
import { RoleTypeSeeder } from './services/role.type.seeder';
|
||||
import { SpaceTypeRepository } from '../modules/space-type/repositories';
|
||||
import { SpaceTypeRepository } from '../modules/space/repositories';
|
||||
import { SpaceTypeSeeder } from './services/space.type.seeder';
|
||||
import { SpaceTypeRepositoryModule } from '../modules/space-type/space.type.repository.module';
|
||||
import { SpaceRepositoryModule } from '../modules/space/space.repository.module';
|
||||
import { SuperAdminSeeder } from './services/supper.admin.seeder';
|
||||
import { UserRepository } from '../modules/user/repositories';
|
||||
import { UserRoleRepository } from '../modules/user-role/repositories';
|
||||
import { UserRoleRepositoryModule } from '../modules/user-role/user.role.repository.module';
|
||||
import { UserRoleRepository } from '../modules/user/repositories';
|
||||
import { UserRepositoryModule } from '../modules/user/user.repository.module';
|
||||
import { RegionSeeder } from './services/regions.seeder';
|
||||
import { RegionRepository } from '../modules/region/repositories';
|
||||
@@ -44,8 +43,7 @@ import { TimeZoneRepository } from '../modules/timezone/repositories';
|
||||
PermissionTypeRepositoryModule,
|
||||
RoleTypeRepositoryModule,
|
||||
UserRepositoryModule,
|
||||
UserRoleRepositoryModule,
|
||||
SpaceTypeRepositoryModule,
|
||||
SpaceRepositoryModule,
|
||||
],
|
||||
})
|
||||
export class SeederModule {}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { SpaceType } from '../../constants/space-type.enum';
|
||||
import { SpaceTypeRepository } from '../../modules/space-type/repositories';
|
||||
import { SpaceTypeRepository } from '../../modules/space/repositories';
|
||||
|
||||
@Injectable()
|
||||
export class SpaceTypeSeeder {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||
import { UserRoleRepository } from '@app/common/modules/user-role/repositories';
|
||||
import { UserRoleRepository } from '@app/common/modules/user/repositories';
|
||||
import { RoleTypeRepository } from '@app/common/modules/role-type/repositories';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { HelperHashService } from '../../helper/services';
|
||||
|
||||
@@ -10,6 +10,7 @@ export class EmailService {
|
||||
this.smtpConfig = {
|
||||
host: this.configService.get<string>('email-config.SMTP_HOST'),
|
||||
port: this.configService.get<number>('email-config.SMTP_PORT'),
|
||||
sender: this.configService.get<string>('email-config.SMTP_SENDER'),
|
||||
secure: this.configService.get<boolean>('email-config.SMTP_SECURE'), // true for 465, false for other ports
|
||||
auth: {
|
||||
user: this.configService.get<string>('email-config.SMTP_USER'),
|
||||
@@ -26,7 +27,7 @@ export class EmailService {
|
||||
const transporter = nodemailer.createTransport(this.smtpConfig);
|
||||
|
||||
const mailOptions = {
|
||||
from: this.smtpConfig.auth.user,
|
||||
from: this.smtpConfig.sender,
|
||||
to: email,
|
||||
subject,
|
||||
text: message,
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
import {
|
||||
Constructor,
|
||||
Plain,
|
||||
Optional,
|
||||
Nullable,
|
||||
Path,
|
||||
PathValue,
|
||||
KeyOfType,
|
||||
} from './types';
|
||||
|
||||
interface TestInterface {
|
||||
user: {
|
||||
profile: {
|
||||
name: string;
|
||||
age: number;
|
||||
};
|
||||
settings: {
|
||||
theme: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
interface SampleEntity {
|
||||
id: number;
|
||||
name: string;
|
||||
tags: string[];
|
||||
}
|
||||
|
||||
class TestClass {
|
||||
constructor(
|
||||
public name: string,
|
||||
public age: number,
|
||||
) {}
|
||||
}
|
||||
|
||||
describe('TypeScript Utility Types', () => {
|
||||
it('should validate Constructor type', () => {
|
||||
type ValidConstructorTest = Constructor<TestClass, [string, number]>;
|
||||
const instance: ValidConstructorTest = TestClass;
|
||||
expect(instance).toBeDefined();
|
||||
});
|
||||
|
||||
it('should validate Plain type', () => {
|
||||
type PlainNumberTest = Plain<number>;
|
||||
type PlainStringTest = Plain<string>;
|
||||
type PlainObjectTest = Plain<{ name: string; age: number }>;
|
||||
const num: PlainNumberTest = 42;
|
||||
const str: PlainStringTest = 'hello';
|
||||
const obj: PlainObjectTest = { name: 'John', age: 30 };
|
||||
|
||||
expect(num).toBe(42);
|
||||
expect(str).toBe('hello');
|
||||
expect(obj).toEqual({ name: 'John', age: 30 });
|
||||
});
|
||||
|
||||
it('should validate Optional type', () => {
|
||||
type OptionalNumberTest = Optional<number>;
|
||||
type OptionalObjectTest = Optional<{ name: string }>;
|
||||
|
||||
const num: OptionalNumberTest = undefined;
|
||||
const obj: OptionalObjectTest = { name: 'Jane' };
|
||||
const objUndefined: OptionalObjectTest = undefined;
|
||||
|
||||
expect(num).toBeUndefined();
|
||||
expect(obj).toEqual({ name: 'Jane' });
|
||||
expect(objUndefined).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should validate Nullable type', () => {
|
||||
type NullableNumberTest = Nullable<number>;
|
||||
type NullableObjectTest = Nullable<{ name: string }>;
|
||||
|
||||
const num: NullableNumberTest = null;
|
||||
const obj: NullableObjectTest = { name: 'Jack' };
|
||||
const objNull: NullableObjectTest = null;
|
||||
|
||||
expect(num).toBeNull();
|
||||
expect(obj).toEqual({ name: 'Jack' });
|
||||
expect(objNull).toBeNull();
|
||||
});
|
||||
|
||||
it('should validate Path type', () => {
|
||||
type PathTest = Path<TestInterface>;
|
||||
const path1: PathTest = 'user.profile.name';
|
||||
const path2: PathTest = 'user.settings.theme';
|
||||
|
||||
expect(path1).toBe('user.profile.name');
|
||||
expect(path2).toBe('user.settings.theme');
|
||||
});
|
||||
|
||||
it('should validate PathValue type', () => {
|
||||
type NameTypeTest = PathValue<TestInterface, 'user.profile.name'>;
|
||||
type AgeTypeTest = PathValue<TestInterface, 'user.profile.age'>;
|
||||
type ThemeTypeTest = PathValue<TestInterface, 'user.settings.theme'>;
|
||||
|
||||
const name: NameTypeTest = 'Alice';
|
||||
const age: AgeTypeTest = 25;
|
||||
const theme: ThemeTypeTest = 'dark';
|
||||
|
||||
expect(name).toBe('Alice');
|
||||
expect(age).toBe(25);
|
||||
expect(theme).toBe('dark');
|
||||
});
|
||||
|
||||
it('should validate KeyOfType type', () => {
|
||||
type StringKeysTest = KeyOfType<SampleEntity, string>;
|
||||
type NumberKeysTest = KeyOfType<SampleEntity, number>;
|
||||
type ArrayKeysTest = KeyOfType<SampleEntity, string[]>;
|
||||
|
||||
const stringKey: StringKeysTest = 'name';
|
||||
const numberKey: NumberKeysTest = 'id';
|
||||
const arrayKey: ArrayKeysTest = 'tags';
|
||||
|
||||
expect(stringKey).toBe('name');
|
||||
expect(numberKey).toBe('id');
|
||||
expect(arrayKey).toBe('tags');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user