mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 10:24:53 +00:00
Merge branch 'dev' into real-time-devices
This commit is contained in:
75
.env.example
Normal file
75
.env.example
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
ACCESS_KEY=
|
||||||
|
|
||||||
|
AZURE_POSTGRESQL_DATABASE=
|
||||||
|
|
||||||
|
AZURE_POSTGRESQL_HOST=
|
||||||
|
|
||||||
|
AZURE_POSTGRESQL_PASSWORD=
|
||||||
|
|
||||||
|
AZURE_POSTGRESQL_PORT=
|
||||||
|
|
||||||
|
AZURE_POSTGRESQL_SSL=
|
||||||
|
|
||||||
|
AZURE_POSTGRESQL_SYNC=
|
||||||
|
|
||||||
|
AZURE_POSTGRESQL_USER=
|
||||||
|
|
||||||
|
AZURE_REDIS_CONNECTIONSTRING=
|
||||||
|
|
||||||
|
BASE_URL=
|
||||||
|
|
||||||
|
DB_SYNC=
|
||||||
|
|
||||||
|
DOCKER_REGISTRY_SERVER_PASSWORD=
|
||||||
|
|
||||||
|
DOCKER_REGISTRY_SERVER_URL=
|
||||||
|
|
||||||
|
DOCKER_REGISTRY_SERVER_USERNAME=
|
||||||
|
|
||||||
|
DOPPLER_CONFIG=
|
||||||
|
|
||||||
|
DOPPLER_ENVIRONMENT=
|
||||||
|
|
||||||
|
DOPPLER_PROJECT=
|
||||||
|
|
||||||
|
JWT_EXPIRE_TIME=
|
||||||
|
|
||||||
|
JWT_EXPIRE_TIME_REFRESH=
|
||||||
|
|
||||||
|
JWT_SECRET=
|
||||||
|
|
||||||
|
JWT_SECRET_REFRESH=
|
||||||
|
|
||||||
|
SECRET_KEY=
|
||||||
|
|
||||||
|
SMTP_HOST=
|
||||||
|
|
||||||
|
SMTP_PASSWORD=
|
||||||
|
|
||||||
|
SMTP_PORT=
|
||||||
|
|
||||||
|
SMTP_SECURE=
|
||||||
|
|
||||||
|
SMTP_USER=
|
||||||
|
|
||||||
|
WEBSITES_ENABLE_APP_SERVICE_STORAGE=
|
||||||
|
|
||||||
|
PORT=
|
||||||
|
|
||||||
|
SUPER_ADMIN_EMAIL=
|
||||||
|
|
||||||
|
SUPER_ADMIN_PASSWORD=
|
||||||
|
|
||||||
|
TUYA_ACCESS_ID=
|
||||||
|
|
||||||
|
TUYA_ACCESS_KEY=
|
||||||
|
|
||||||
|
ONESIGNAL_APP_ID=
|
||||||
|
|
||||||
|
ONESIGNAL_API_KEY=
|
||||||
|
|
||||||
|
TRUN_ON_TUYA_SOCKET=
|
||||||
|
|
||||||
|
TUYA_EU_URL=
|
||||||
|
|
||||||
|
MONGODB_URI=
|
||||||
61
.github/workflows/dev_syncrow(dev).yml
vendored
61
.github/workflows/dev_syncrow(dev).yml
vendored
@ -1,61 +0,0 @@
|
|||||||
name: Backend deployment to Azure App Service
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- dev
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
env:
|
|
||||||
AZURE_WEB_APP_NAME: 'syncrow'
|
|
||||||
AZURE_WEB_APP_SLOT_NAME: 'dev'
|
|
||||||
ACR_REGISTRY: 'syncrow.azurecr.io'
|
|
||||||
IMAGE_NAME: 'backend'
|
|
||||||
IMAGE_TAG: '${{ github.sha }}' # Use commit SHA for unique tagging
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build_and_deploy:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Node.js
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: '20'
|
|
||||||
|
|
||||||
- name: Clear npm cache and install dependencies
|
|
||||||
run: |
|
|
||||||
npm cache clean --force
|
|
||||||
npm install
|
|
||||||
|
|
||||||
- name: Build project
|
|
||||||
run: npm run build
|
|
||||||
|
|
||||||
- name: Log in to Azure
|
|
||||||
uses: azure/login@v1
|
|
||||||
with:
|
|
||||||
creds: ${{ secrets.AZURE_CREDENTIALS }}
|
|
||||||
|
|
||||||
- name: Log in to Azure Container Registry
|
|
||||||
run: az acr login --name ${{ env.ACR_REGISTRY }}
|
|
||||||
|
|
||||||
- name: List build output
|
|
||||||
run: ls -R dist/
|
|
||||||
|
|
||||||
- name: Build and push Docker image
|
|
||||||
run: |
|
|
||||||
docker build . -t ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
|
|
||||||
docker push ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
|
|
||||||
|
|
||||||
- name: Set Web App with Docker container
|
|
||||||
run: |
|
|
||||||
az webapp config container set \
|
|
||||||
--name ${{ env.AZURE_WEB_APP_NAME }} \
|
|
||||||
--resource-group backend \
|
|
||||||
--docker-custom-image-name ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} \
|
|
||||||
--docker-registry-server-url https://${{ env.ACR_REGISTRY }}
|
|
||||||
|
|
||||||
- name: Restart Web App
|
|
||||||
run: az webapp restart --name ${{ env.AZURE_WEB_APP_NAME }} --resource-group backend
|
|
||||||
51
.github/workflows/dev_syncrow(test).yml
vendored
Normal file
51
.github/workflows/dev_syncrow(test).yml
vendored
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
|
||||||
|
# More GitHub Actions for Azure: https://github.com/Azure/actions
|
||||||
|
|
||||||
|
name: Build and deploy container app to Azure Web App - syncrow(test)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- dev
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: 'ubuntu-latest'
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
|
- name: Log in to registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: https://syncrow.azurecr.io/
|
||||||
|
username: ${{ secrets.AzureAppService_ContainerUsername_e7578d2a094946609a4506f293c7c645 }}
|
||||||
|
password: ${{ secrets.AzureAppService_ContainerPassword_3cfcef3755ed46eda766dfc7059dcf5e }}
|
||||||
|
|
||||||
|
- name: Build and push container image to registry
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
push: true
|
||||||
|
tags: syncrow.azurecr.io/${{ secrets.AzureAppService_ContainerUsername_e7578d2a094946609a4506f293c7c645 }}/backend:${{ github.sha }}
|
||||||
|
file: ./Dockerfile
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
|
environment:
|
||||||
|
name: 'test'
|
||||||
|
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Deploy to Azure Web App
|
||||||
|
id: deploy-to-webapp
|
||||||
|
uses: azure/webapps-deploy@v2
|
||||||
|
with:
|
||||||
|
app-name: 'syncrow'
|
||||||
|
slot-name: 'test'
|
||||||
|
publish-profile: ${{ secrets.AzureAppService_PublishProfile_cfa029d9d3a84172a06cfe47c05c18ca }}
|
||||||
|
images: 'syncrow.azurecr.io/${{ secrets.AzureAppService_ContainerUsername_e7578d2a094946609a4506f293c7c645 }}/backend:${{ github.sha }}'
|
||||||
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"trailingComma": "all"
|
"trailingComma": "all",
|
||||||
|
"endOfLine": "auto"
|
||||||
}
|
}
|
||||||
@ -1,24 +1,15 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
moduleFileExtensions: [
|
moduleFileExtensions: ['js', 'json', 'ts'],
|
||||||
"js",
|
rootDir: '.',
|
||||||
"json",
|
testRegex: '.*\\.spec\\.ts$',
|
||||||
"ts"
|
|
||||||
],
|
|
||||||
rootDir: ".",
|
|
||||||
testRegex: ".*\\.spec\\.ts$",
|
|
||||||
transform: {
|
transform: {
|
||||||
"^.+\\.(t|j)s$": "ts-jest"
|
'^.+\\.(t|j)s$': 'ts-jest',
|
||||||
},
|
},
|
||||||
collectCoverageFrom: [
|
collectCoverageFrom: ['**/*.(t|j)s'],
|
||||||
"**/*.(t|j)s"
|
coverageDirectory: './coverage',
|
||||||
],
|
testEnvironment: 'node',
|
||||||
coverageDirectory: "./coverage",
|
roots: ['<rootDir>/src/', '<rootDir>/libs/'],
|
||||||
testEnvironment: "node",
|
|
||||||
roots: [
|
|
||||||
"<rootDir>/src/",
|
|
||||||
"<rootDir>/libs/"
|
|
||||||
],
|
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
"^@app/common(|/.*)$": "<rootDir>/libs/common/src/$1"
|
'^@app/common(|/.*)$': '<rootDir>/libs/common/src/$1',
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -7,6 +7,7 @@ export default registerAs(
|
|||||||
SMTP_PORT: parseInt(process.env.SMTP_PORT),
|
SMTP_PORT: parseInt(process.env.SMTP_PORT),
|
||||||
SMTP_SECURE: process.env.SMTP_SECURE === 'true',
|
SMTP_SECURE: process.env.SMTP_SECURE === 'true',
|
||||||
SMTP_USER: process.env.SMTP_USER,
|
SMTP_USER: process.env.SMTP_USER,
|
||||||
|
SMTP_SENDER: process.env.SMTP_SENDER,
|
||||||
SMTP_PASSWORD: process.env.SMTP_PASSWORD,
|
SMTP_PASSWORD: process.env.SMTP_PASSWORD,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -79,7 +79,6 @@ export const allCountries = [
|
|||||||
'Iran',
|
'Iran',
|
||||||
'Iraq',
|
'Iraq',
|
||||||
'Ireland',
|
'Ireland',
|
||||||
'Israel',
|
|
||||||
'Italy',
|
'Italy',
|
||||||
'Jamaica',
|
'Jamaica',
|
||||||
'Japan',
|
'Japan',
|
||||||
|
|||||||
@ -4,18 +4,18 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
|||||||
import { SnakeNamingStrategy } from './strategies';
|
import { SnakeNamingStrategy } from './strategies';
|
||||||
import { UserEntity } from '../modules/user/entities/user.entity';
|
import { UserEntity } from '../modules/user/entities/user.entity';
|
||||||
import { UserSessionEntity } from '../modules/session/entities/session.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 { ProductEntity } from '../modules/product/entities';
|
||||||
import { DeviceEntity } from '../modules/device/entities';
|
import { DeviceEntity } from '../modules/device/entities';
|
||||||
import { PermissionTypeEntity } from '../modules/permission/entities';
|
import { PermissionTypeEntity } from '../modules/permission/entities';
|
||||||
import { SpaceEntity } from '../modules/space/entities';
|
import { SpaceEntity } from '../modules/space/entities';
|
||||||
import { SpaceTypeEntity } from '../modules/space-type/entities';
|
import { SpaceTypeEntity } from '../modules/space/entities';
|
||||||
import { UserSpaceEntity } from '../modules/user-space/entities';
|
import { UserSpaceEntity } from '../modules/user/entities';
|
||||||
import { DeviceUserPermissionEntity } from '../modules/device-user-permission/entities';
|
import { DeviceUserPermissionEntity } from '../modules/device/entities';
|
||||||
import { UserRoleEntity } from '../modules/user-role/entities';
|
import { UserRoleEntity } from '../modules/user/entities';
|
||||||
import { RoleTypeEntity } from '../modules/role-type/entities';
|
import { RoleTypeEntity } from '../modules/role-type/entities';
|
||||||
import { UserNotificationEntity } from '../modules/user-notification/entities';
|
import { UserNotificationEntity } from '../modules/user/entities';
|
||||||
import { DeviceNotificationEntity } from '../modules/device-notification/entities';
|
import { DeviceNotificationEntity } from '../modules/device/entities';
|
||||||
import { RegionEntity } from '../modules/region/entities';
|
import { RegionEntity } from '../modules/region/entities';
|
||||||
import { TimeZoneEntity } from '../modules/timezone/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}`));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
86
libs/common/src/helper/camelCaseConverter.spec.ts
Normal file
86
libs/common/src/helper/camelCaseConverter.spec.ts
Normal file
@ -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: 'alice@example.com' },
|
||||||
|
{ phone_number: '123-456-7890' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const expected = {
|
||||||
|
userInfo: {
|
||||||
|
userName: 'Alice',
|
||||||
|
contactDetails: [
|
||||||
|
{ emailAddress: 'alice@example.com' },
|
||||||
|
{ 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 { OneSignalService } from './services/onesignal.service';
|
||||||
import { DeviceMessagesService } from './services/device.messages.service';
|
import { DeviceMessagesService } from './services/device.messages.service';
|
||||||
import { DeviceNotificationRepositoryModule } from '../modules/device-notification/device.notification.module';
|
import { DeviceRepositoryModule } from '../modules/device/device.repository.module';
|
||||||
import { DeviceNotificationRepository } from '../modules/device-notification/repositories';
|
import { DeviceNotificationRepository } from '../modules/device/repositories';
|
||||||
import { DeviceStatusFirebaseModule } from '../firebase/devices-status/devices-status.module';
|
import { DeviceStatusFirebaseModule } from '../firebase/devices-status/devices-status.module';
|
||||||
|
|
||||||
@Global()
|
@Global()
|
||||||
@ -26,7 +26,7 @@ import { DeviceStatusFirebaseModule } from '../firebase/devices-status/devices-s
|
|||||||
controllers: [],
|
controllers: [],
|
||||||
imports: [
|
imports: [
|
||||||
SpaceRepositoryModule,
|
SpaceRepositoryModule,
|
||||||
DeviceNotificationRepositoryModule,
|
DeviceRepositoryModule,
|
||||||
DeviceStatusFirebaseModule,
|
DeviceStatusFirebaseModule,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
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';
|
import { OneSignalService } from './onesignal.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|||||||
99
libs/common/src/helper/services/helper.hash.service.spec.ts
Normal file
99
libs/common/src/helper/services/helper.hash.service.spec.ts
Normal file
@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
54
libs/common/src/helper/snakeCaseConverter.spec.ts
Normal file
54
libs/common/src/helper/snakeCaseConverter.spec.ts
Normal file
@ -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';
|
|
||||||
@ -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';
|
|
||||||
@ -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';
|
|
||||||
@ -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';
|
|
||||||
@ -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 { Module } from '@nestjs/common';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { DeviceEntity } from './entities';
|
import {
|
||||||
|
DeviceEntity,
|
||||||
|
DeviceNotificationEntity,
|
||||||
|
DeviceUserPermissionEntity,
|
||||||
|
} from './entities';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [],
|
providers: [],
|
||||||
exports: [],
|
exports: [],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
imports: [TypeOrmModule.forFeature([DeviceEntity])],
|
imports: [
|
||||||
|
TypeOrmModule.forFeature([
|
||||||
|
DeviceEntity,
|
||||||
|
DeviceNotificationEntity,
|
||||||
|
DeviceUserPermissionEntity,
|
||||||
|
]),
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class DeviceRepositoryModule {}
|
export class DeviceRepositoryModule {}
|
||||||
|
|||||||
@ -21,3 +21,35 @@ export class DeviceDto {
|
|||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
productUuid: string;
|
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 { Column, Entity, ManyToOne, OneToMany, Unique, Index } from 'typeorm';
|
||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
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 { SpaceEntity } from '../../space/entities';
|
||||||
import { ProductEntity } from '../../product/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 { UserEntity } from '../../user/entities';
|
||||||
|
import { DeviceNotificationDto } from '../dtos';
|
||||||
|
import { PermissionTypeEntity } from '../../permission/entities';
|
||||||
|
|
||||||
@Entity({ name: 'device' })
|
@Entity({ name: 'device' })
|
||||||
@Unique(['deviceTuyaUuid'])
|
@Unique(['deviceTuyaUuid'])
|
||||||
@ -60,3 +60,68 @@ export class DeviceEntity extends AbstractEntity<DeviceDto> {
|
|||||||
Object.assign(this, partial);
|
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 { DataSource, Repository } from 'typeorm';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { DeviceEntity } from '../entities';
|
import {
|
||||||
|
DeviceEntity,
|
||||||
|
DeviceNotificationEntity,
|
||||||
|
DeviceUserPermissionEntity,
|
||||||
|
} from '../entities';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DeviceRepository extends Repository<DeviceEntity> {
|
export class DeviceRepository extends Repository<DeviceEntity> {
|
||||||
@ -8,3 +12,15 @@ export class DeviceRepository extends Repository<DeviceEntity> {
|
|||||||
super(DeviceEntity, dataSource.createEntityManager());
|
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 { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
import { PermissionType } from '@app/common/constants/permission-type.enum';
|
import { PermissionType } from '@app/common/constants/permission-type.enum';
|
||||||
import { PermissionTypeDto } from '../dtos/permission.dto';
|
import { PermissionTypeDto } from '../dtos/permission.dto';
|
||||||
import { DeviceUserPermissionEntity } from '../../device-user-permission/entities';
|
import { DeviceUserPermissionEntity } from '../../device/entities';
|
||||||
|
|
||||||
@Entity({ name: 'permission-type' })
|
@Entity({ name: 'permission-type' })
|
||||||
export class PermissionTypeEntity extends AbstractEntity<PermissionTypeDto> {
|
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 { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
import { RoleTypeDto } from '../dtos/role.type.dto';
|
import { RoleTypeDto } from '../dtos/role.type.dto';
|
||||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||||
import { UserRoleEntity } from '../../user-role/entities';
|
import { UserRoleEntity } from '../../user/entities';
|
||||||
|
|
||||||
@Entity({ name: 'role-type' })
|
@Entity({ name: 'role-type' })
|
||||||
@Unique(['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()
|
@IsNotEmpty()
|
||||||
public invitationCode: string;
|
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 { Column, Entity, ManyToOne, OneToMany, Unique } from 'typeorm';
|
||||||
import { SpaceDto } from '../dtos';
|
import { SpaceDto, SpaceTypeDto } from '../dtos';
|
||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
import { SpaceTypeEntity } from '../../space-type/entities';
|
import { UserSpaceEntity } from '../../user/entities';
|
||||||
import { UserSpaceEntity } from '../../user-space/entities';
|
|
||||||
import { DeviceEntity } from '../../device/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' })
|
@Entity({ name: 'space' })
|
||||||
@Unique(['invitationCode'])
|
@Unique(['invitationCode'])
|
||||||
export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
||||||
@Column({
|
@Column({
|
||||||
type: 'uuid',
|
type: 'uuid',
|
||||||
default: () => 'gen_random_uuid()', // Use gen_random_uuid() for default value
|
default: () => 'gen_random_uuid()',
|
||||||
nullable: false,
|
nullable: false,
|
||||||
})
|
})
|
||||||
public uuid: string;
|
public uuid: string;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { DataSource, Repository } from 'typeorm';
|
import { DataSource, Repository } from 'typeorm';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { SpaceEntity } from '../entities/space.entity';
|
import { SpaceEntity, SpaceTypeEntity } from '../entities';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SpaceRepository extends Repository<SpaceEntity> {
|
export class SpaceRepository extends Repository<SpaceEntity> {
|
||||||
@ -8,3 +8,10 @@ export class SpaceRepository extends Repository<SpaceEntity> {
|
|||||||
super(SpaceEntity, dataSource.createEntityManager());
|
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 { Module } from '@nestjs/common';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { SpaceEntity } from './entities/space.entity';
|
import { SpaceEntity, SpaceTypeEntity } from './entities';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [],
|
providers: [],
|
||||||
exports: [],
|
exports: [],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
imports: [TypeOrmModule.forFeature([SpaceEntity])],
|
imports: [TypeOrmModule.forFeature([SpaceEntity, SpaceTypeEntity])],
|
||||||
})
|
})
|
||||||
export class SpaceRepositoryModule {}
|
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';
|
|
||||||
@ -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 {
|
export class UserDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ -21,3 +21,67 @@ export class UserDto {
|
|||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
public lastName: string;
|
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, Unique } from 'typeorm';
|
||||||
import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
|
import {
|
||||||
import { UserDto } from '../dtos';
|
UserDto,
|
||||||
|
UserNotificationDto,
|
||||||
|
UserOtpDto,
|
||||||
|
UserRoleDto,
|
||||||
|
UserSpaceDto,
|
||||||
|
} from '../dtos';
|
||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
import { UserSpaceEntity } from '../../user-space/entities';
|
import {
|
||||||
import { UserRoleEntity } from '../../user-role/entities';
|
DeviceEntity,
|
||||||
import { DeviceNotificationEntity } from '../../device-notification/entities';
|
DeviceNotificationEntity,
|
||||||
import { UserNotificationEntity } from '../../user-notification/entities';
|
DeviceUserPermissionEntity,
|
||||||
import { DeviceEntity } from '../../device/entities';
|
} from '../../device/entities';
|
||||||
import { defaultProfilePicture } from '@app/common/constants/default.profile.picture';
|
import { defaultProfilePicture } from '@app/common/constants/default.profile.picture';
|
||||||
import { RegionEntity } from '../../region/entities';
|
import { RegionEntity } from '../../region/entities';
|
||||||
import { TimeZoneEntity } from '../../timezone/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' })
|
@Entity({ name: 'user' })
|
||||||
export class UserEntity extends AbstractEntity<UserDto> {
|
export class UserEntity extends AbstractEntity<UserDto> {
|
||||||
@ -99,3 +107,99 @@ export class UserEntity extends AbstractEntity<UserDto> {
|
|||||||
Object.assign(this, partial);
|
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 { DataSource, Repository } from 'typeorm';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { UserEntity } from '../entities/user.entity';
|
import {
|
||||||
|
UserEntity,
|
||||||
|
UserNotificationEntity,
|
||||||
|
UserOtpEntity,
|
||||||
|
UserRoleEntity,
|
||||||
|
UserSpaceEntity,
|
||||||
|
} from '../entities/';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserRepository extends Repository<UserEntity> {
|
export class UserRepository extends Repository<UserEntity> {
|
||||||
@ -8,3 +14,31 @@ export class UserRepository extends Repository<UserEntity> {
|
|||||||
super(UserEntity, dataSource.createEntityManager());
|
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 { Module } from '@nestjs/common';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { UserEntity } from './entities/user.entity';
|
import {
|
||||||
|
UserEntity,
|
||||||
|
UserNotificationEntity,
|
||||||
|
UserOtpEntity,
|
||||||
|
UserRoleEntity,
|
||||||
|
UserSpaceEntity,
|
||||||
|
} from './entities';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [],
|
providers: [],
|
||||||
exports: [],
|
exports: [],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
imports: [TypeOrmModule.forFeature([UserEntity])],
|
imports: [
|
||||||
|
TypeOrmModule.forFeature([
|
||||||
|
UserEntity,
|
||||||
|
UserNotificationEntity,
|
||||||
|
UserOtpEntity,
|
||||||
|
UserRoleEntity,
|
||||||
|
UserSpaceEntity,
|
||||||
|
]),
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class UserRepositoryModule {}
|
export class UserRepositoryModule {}
|
||||||
|
|||||||
@ -7,13 +7,12 @@ import { ConfigModule } from '@nestjs/config';
|
|||||||
import { RoleTypeRepositoryModule } from '../modules/role-type/role.type.repository.module';
|
import { RoleTypeRepositoryModule } from '../modules/role-type/role.type.repository.module';
|
||||||
import { RoleTypeRepository } from '../modules/role-type/repositories';
|
import { RoleTypeRepository } from '../modules/role-type/repositories';
|
||||||
import { RoleTypeSeeder } from './services/role.type.seeder';
|
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 { 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 { SuperAdminSeeder } from './services/supper.admin.seeder';
|
||||||
import { UserRepository } from '../modules/user/repositories';
|
import { UserRepository } from '../modules/user/repositories';
|
||||||
import { UserRoleRepository } from '../modules/user-role/repositories';
|
import { UserRoleRepository } from '../modules/user/repositories';
|
||||||
import { UserRoleRepositoryModule } from '../modules/user-role/user.role.repository.module';
|
|
||||||
import { UserRepositoryModule } from '../modules/user/user.repository.module';
|
import { UserRepositoryModule } from '../modules/user/user.repository.module';
|
||||||
import { RegionSeeder } from './services/regions.seeder';
|
import { RegionSeeder } from './services/regions.seeder';
|
||||||
import { RegionRepository } from '../modules/region/repositories';
|
import { RegionRepository } from '../modules/region/repositories';
|
||||||
@ -44,8 +43,7 @@ import { TimeZoneRepository } from '../modules/timezone/repositories';
|
|||||||
PermissionTypeRepositoryModule,
|
PermissionTypeRepositoryModule,
|
||||||
RoleTypeRepositoryModule,
|
RoleTypeRepositoryModule,
|
||||||
UserRepositoryModule,
|
UserRepositoryModule,
|
||||||
UserRoleRepositoryModule,
|
SpaceRepositoryModule,
|
||||||
SpaceTypeRepositoryModule,
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class SeederModule {}
|
export class SeederModule {}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { SpaceType } from '../../constants/space-type.enum';
|
import { SpaceType } from '../../constants/space-type.enum';
|
||||||
import { SpaceTypeRepository } from '../../modules/space-type/repositories';
|
import { SpaceTypeRepository } from '../../modules/space/repositories';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SpaceTypeSeeder {
|
export class SpaceTypeSeeder {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
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 { RoleTypeRepository } from '@app/common/modules/role-type/repositories';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { HelperHashService } from '../../helper/services';
|
import { HelperHashService } from '../../helper/services';
|
||||||
|
|||||||
@ -10,6 +10,7 @@ export class EmailService {
|
|||||||
this.smtpConfig = {
|
this.smtpConfig = {
|
||||||
host: this.configService.get<string>('email-config.SMTP_HOST'),
|
host: this.configService.get<string>('email-config.SMTP_HOST'),
|
||||||
port: this.configService.get<number>('email-config.SMTP_PORT'),
|
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
|
secure: this.configService.get<boolean>('email-config.SMTP_SECURE'), // true for 465, false for other ports
|
||||||
auth: {
|
auth: {
|
||||||
user: this.configService.get<string>('email-config.SMTP_USER'),
|
user: this.configService.get<string>('email-config.SMTP_USER'),
|
||||||
@ -26,7 +27,7 @@ export class EmailService {
|
|||||||
const transporter = nodemailer.createTransport(this.smtpConfig);
|
const transporter = nodemailer.createTransport(this.smtpConfig);
|
||||||
|
|
||||||
const mailOptions = {
|
const mailOptions = {
|
||||||
from: this.smtpConfig.auth.user,
|
from: this.smtpConfig.sender,
|
||||||
to: email,
|
to: email,
|
||||||
subject,
|
subject,
|
||||||
text: message,
|
text: message,
|
||||||
|
|||||||
118
libs/common/src/util/types.spec.ts
Normal file
118
libs/common/src/util/types.spec.ts
Normal file
@ -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');
|
||||||
|
});
|
||||||
|
});
|
||||||
14
package-lock.json
generated
14
package-lock.json
generated
@ -43,6 +43,8 @@
|
|||||||
"@nestjs/cli": "^10.3.2",
|
"@nestjs/cli": "^10.3.2",
|
||||||
"@nestjs/schematics": "^10.0.0",
|
"@nestjs/schematics": "^10.0.0",
|
||||||
"@nestjs/testing": "^10.0.0",
|
"@nestjs/testing": "^10.0.0",
|
||||||
|
"@types/bcryptjs": "^2.4.6",
|
||||||
|
"@types/crypto-js": "^4.2.2",
|
||||||
"@types/express": "^4.17.17",
|
"@types/express": "^4.17.17",
|
||||||
"@types/jest": "^29.5.2",
|
"@types/jest": "^29.5.2",
|
||||||
"@types/node": "^20.3.1",
|
"@types/node": "^20.3.1",
|
||||||
@ -2892,6 +2894,12 @@
|
|||||||
"@babel/types": "^7.20.7"
|
"@babel/types": "^7.20.7"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/bcryptjs": {
|
||||||
|
"version": "2.4.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/bcryptjs/-/bcryptjs-2.4.6.tgz",
|
||||||
|
"integrity": "sha512-9xlo6R2qDs5uixm0bcIqCeMCE6HiQsIyel9KQySStiyqNl2tnj2mP3DX1Nf56MD6KMenNNlBBsy3LJ7gUEQPXQ==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"node_modules/@types/body-parser": {
|
"node_modules/@types/body-parser": {
|
||||||
"version": "1.19.5",
|
"version": "1.19.5",
|
||||||
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.5.tgz",
|
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.5.tgz",
|
||||||
@ -2917,6 +2925,12 @@
|
|||||||
"integrity": "sha512-he+DHOWReW0nghN24E1WUqM0efK4kI9oTqDm6XmK8ZPe2djZ90BSNdGnIyCLzCPw7/pogPlGbzI2wHGGmi4O/Q==",
|
"integrity": "sha512-he+DHOWReW0nghN24E1WUqM0efK4kI9oTqDm6XmK8ZPe2djZ90BSNdGnIyCLzCPw7/pogPlGbzI2wHGGmi4O/Q==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/crypto-js": {
|
||||||
|
"version": "4.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.2.2.tgz",
|
||||||
|
"integrity": "sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"node_modules/@types/eslint": {
|
"node_modules/@types/eslint": {
|
||||||
"version": "8.56.4",
|
"version": "8.56.4",
|
||||||
"resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.56.4.tgz",
|
"resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.56.4.tgz",
|
||||||
|
|||||||
12
package.json
12
package.json
@ -6,12 +6,12 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npx nest build",
|
"build": "npm run test && npx nest build",
|
||||||
"format": "prettier --write \"apps/**/*.ts\" \"libs/**/*.ts\"",
|
"format": "prettier --write \"apps/**/*.ts\" \"libs/**/*.ts\"",
|
||||||
"start": "node dist/main",
|
"start": "npm run test && node dist/main",
|
||||||
"start:dev": "npx nest start --watch",
|
"start:dev": "npm run test && npx nest start --watch",
|
||||||
"start:debug": "npx nest start --debug --watch",
|
"start:debug": "npm run test && npx nest start --debug --watch",
|
||||||
"start:prod": "node dist/main",
|
"start:prod": "npm run test && node dist/main",
|
||||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||||
"test": "jest --config jest.config.js",
|
"test": "jest --config jest.config.js",
|
||||||
"test:watch": "jest --watch --config jest.config.js",
|
"test:watch": "jest --watch --config jest.config.js",
|
||||||
@ -54,6 +54,8 @@
|
|||||||
"@nestjs/cli": "^10.3.2",
|
"@nestjs/cli": "^10.3.2",
|
||||||
"@nestjs/schematics": "^10.0.0",
|
"@nestjs/schematics": "^10.0.0",
|
||||||
"@nestjs/testing": "^10.0.0",
|
"@nestjs/testing": "^10.0.0",
|
||||||
|
"@types/bcryptjs": "^2.4.6",
|
||||||
|
"@types/crypto-js": "^4.2.2",
|
||||||
"@types/express": "^4.17.17",
|
"@types/express": "^4.17.17",
|
||||||
"@types/jest": "^29.5.2",
|
"@types/jest": "^29.5.2",
|
||||||
"@types/node": "^20.3.1",
|
"@types/node": "^20.3.1",
|
||||||
|
|||||||
@ -57,4 +57,4 @@ import { TimeZoneModule } from './timezone/timezone.module';
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AuthModule {}
|
export class AppModule {}
|
||||||
|
|||||||
@ -2,14 +2,16 @@ import { Module } from '@nestjs/common';
|
|||||||
import { AuthenticationController } from './controllers/authentication.controller';
|
import { AuthenticationController } from './controllers/authentication.controller';
|
||||||
import { AuthenticationService } from './services/authentication.service';
|
import { AuthenticationService } from './services/authentication.service';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { UserRepositoryModule } from '../../libs/common/src/modules/user/user.repository.module';
|
import { UserRepositoryModule } from '@app/common/modules/user/user.repository.module';
|
||||||
import { CommonModule } from '../../libs/common/src';
|
import { CommonModule } from '../../libs/common/src';
|
||||||
import { UserAuthController } from './controllers';
|
import { UserAuthController } from './controllers';
|
||||||
import { UserAuthService } from './services';
|
import { UserAuthService } from './services';
|
||||||
import { UserRepository } from '../../libs/common/src/modules/user/repositories';
|
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||||
import { UserSessionRepository } from '../../libs/common/src/modules/session/repositories/session.repository';
|
import { UserSessionRepository } from '@app/common/modules/session/repositories/session.repository';
|
||||||
import { UserOtpRepository } from '../../libs/common/src/modules/user-otp/repositories/user-otp.repository';
|
import {
|
||||||
import { UserRoleRepository } from '@app/common/modules/user-role/repositories';
|
UserRoleRepository,
|
||||||
|
UserOtpRepository,
|
||||||
|
} from '@app/common/modules/user/repositories';
|
||||||
import { RoleTypeRepository } from '@app/common/modules/role-type/repositories';
|
import { RoleTypeRepository } from '@app/common/modules/role-type/repositories';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import { ApiTags } from '@nestjs/swagger';
|
|||||||
@ApiTags('Tuya Auth')
|
@ApiTags('Tuya Auth')
|
||||||
export class AuthenticationController {
|
export class AuthenticationController {
|
||||||
constructor(private readonly authenticationService: AuthenticationService) {}
|
constructor(private readonly authenticationService: AuthenticationService) {}
|
||||||
@Post('auth1')
|
@Post('auth2')
|
||||||
async Authentication() {
|
async Authentication() {
|
||||||
return await this.authenticationService.main();
|
return await this.authenticationService.main();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RoleTypeRepository } from './../../../libs/common/src/modules/role-type/repositories/role.type.repository';
|
import { RoleTypeRepository } from './../../../libs/common/src/modules/role-type/repositories/role.type.repository';
|
||||||
import { UserRoleRepository } from './../../../libs/common/src/modules/user-role/repositories/user.role.repository';
|
import { UserRoleRepository } from './../../../libs/common/src/modules/user/repositories/user.repository';
|
||||||
import { UserRepository } from '../../../libs/common/src/modules/user/repositories';
|
import { UserRepository } from '../../../libs/common/src/modules/user/repositories';
|
||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
@ -12,7 +12,7 @@ import { HelperHashService } from '../../../libs/common/src/helper/services';
|
|||||||
import { UserLoginDto } from '../dtos/user-login.dto';
|
import { UserLoginDto } from '../dtos/user-login.dto';
|
||||||
import { AuthService } from '../../../libs/common/src/auth/services/auth.service';
|
import { AuthService } from '../../../libs/common/src/auth/services/auth.service';
|
||||||
import { UserSessionRepository } from '../../../libs/common/src/modules/session/repositories/session.repository';
|
import { UserSessionRepository } from '../../../libs/common/src/modules/session/repositories/session.repository';
|
||||||
import { UserOtpRepository } from '../../../libs/common/src/modules/user-otp/repositories/user-otp.repository';
|
import { UserOtpRepository } from '../../../libs/common/src/modules/user/repositories/user.repository';
|
||||||
import { ForgetPasswordDto, UserOtpDto, VerifyOtpDto } from '../dtos';
|
import { ForgetPasswordDto, UserOtpDto, VerifyOtpDto } from '../dtos';
|
||||||
import { EmailService } from '../../../libs/common/src/util/email.service';
|
import { EmailService } from '../../../libs/common/src/util/email.service';
|
||||||
import { OtpType } from '../../../libs/common/src/constants/otp-type.enum';
|
import { OtpType } from '../../../libs/common/src/constants/otp-type.enum';
|
||||||
|
|||||||
@ -43,3 +43,8 @@ export interface AutomationResponseData {
|
|||||||
conditions: Condition[];
|
conditions: Condition[];
|
||||||
[key: string]: any; // Allow additional properties
|
[key: string]: any; // Allow additional properties
|
||||||
}
|
}
|
||||||
|
export interface AutomationDetailsResult {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import { convertKeysToSnakeCase } from '@app/common/helper/snakeCaseConverter';
|
|||||||
import { DeviceService } from 'src/device/services';
|
import { DeviceService } from 'src/device/services';
|
||||||
import {
|
import {
|
||||||
AddAutomationInterface,
|
AddAutomationInterface,
|
||||||
|
AutomationDetailsResult,
|
||||||
AutomationResponseData,
|
AutomationResponseData,
|
||||||
DeleteAutomationInterface,
|
DeleteAutomationInterface,
|
||||||
GetAutomationByUnitInterface,
|
GetAutomationByUnitInterface,
|
||||||
@ -186,6 +187,38 @@ export class AutomationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async getTapToRunSceneDetailsTuya(
|
||||||
|
sceneId: string,
|
||||||
|
): Promise<AutomationDetailsResult> {
|
||||||
|
try {
|
||||||
|
const path = `/v2.0/cloud/scene/rule/${sceneId}`;
|
||||||
|
const response = await this.tuya.request({
|
||||||
|
method: 'GET',
|
||||||
|
path,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.success) {
|
||||||
|
throw new HttpException(response.msg, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
const camelCaseResponse = convertKeysToCamelCase(response);
|
||||||
|
const { id, name, type } = camelCaseResponse.result;
|
||||||
|
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
type,
|
||||||
|
} as AutomationDetailsResult;
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof BadRequestException) {
|
||||||
|
throw err; // Re-throw BadRequestException
|
||||||
|
} else {
|
||||||
|
throw new HttpException(
|
||||||
|
'Scene not found for Tuya',
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
async getAutomationDetails(automationId: string, withSpaceId = false) {
|
async getAutomationDetails(automationId: string, withSpaceId = false) {
|
||||||
try {
|
try {
|
||||||
const path = `/v2.0/cloud/scene/rule/${automationId}`;
|
const path = `/v2.0/cloud/scene/rule/${automationId}`;
|
||||||
@ -215,6 +248,18 @@ export class AutomationService {
|
|||||||
if (device) {
|
if (device) {
|
||||||
action.entityId = device.uuid;
|
action.entityId = device.uuid;
|
||||||
}
|
}
|
||||||
|
} else if (
|
||||||
|
action.actionExecutor !== 'device_issue' &&
|
||||||
|
action.actionExecutor !== 'delay'
|
||||||
|
) {
|
||||||
|
const sceneDetails = await this.getTapToRunSceneDetailsTuya(
|
||||||
|
action.entityId,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (sceneDetails.id) {
|
||||||
|
action.name = sceneDetails.name;
|
||||||
|
action.type = sceneDetails.type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,21 +4,13 @@ import { BuildingController } from './controllers/building.controller';
|
|||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { SpaceRepositoryModule } from '@app/common/modules/space/space.repository.module';
|
import { SpaceRepositoryModule } from '@app/common/modules/space/space.repository.module';
|
||||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||||
import { SpaceTypeRepositoryModule } from '@app/common/modules/space-type/space.type.repository.module';
|
import { SpaceTypeRepository } from '@app/common/modules/space/repositories';
|
||||||
import { SpaceTypeRepository } from '@app/common/modules/space-type/repositories';
|
import { UserSpaceRepository } from '@app/common/modules/user/repositories';
|
||||||
import { UserSpaceRepositoryModule } from '@app/common/modules/user-space/user.space.repository.module';
|
|
||||||
import { UserSpaceRepository } from '@app/common/modules/user-space/repositories';
|
|
||||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||||
import { UserRepositoryModule } from '@app/common/modules/user/user.repository.module';
|
import { UserRepositoryModule } from '@app/common/modules/user/user.repository.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [ConfigModule, SpaceRepositoryModule, UserRepositoryModule],
|
||||||
ConfigModule,
|
|
||||||
SpaceRepositoryModule,
|
|
||||||
SpaceTypeRepositoryModule,
|
|
||||||
UserSpaceRepositoryModule,
|
|
||||||
UserRepositoryModule,
|
|
||||||
],
|
|
||||||
controllers: [BuildingController],
|
controllers: [BuildingController],
|
||||||
providers: [
|
providers: [
|
||||||
BuildingService,
|
BuildingService,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { GetBuildingChildDto } from '../dtos/get.building.dto';
|
import { GetBuildingChildDto } from '../dtos/get.building.dto';
|
||||||
import { SpaceTypeRepository } from '../../../libs/common/src/modules/space-type/repositories/space.type.repository';
|
import { SpaceTypeRepository } from '../../../libs/common/src/modules/space/repositories/space.repository';
|
||||||
import {
|
import {
|
||||||
Injectable,
|
Injectable,
|
||||||
HttpException,
|
HttpException,
|
||||||
@ -17,7 +17,7 @@ import {
|
|||||||
} from '../interface/building.interface';
|
} from '../interface/building.interface';
|
||||||
import { SpaceEntity } from '@app/common/modules/space/entities';
|
import { SpaceEntity } from '@app/common/modules/space/entities';
|
||||||
import { UpdateBuildingNameDto } from '../dtos/update.building.dto';
|
import { UpdateBuildingNameDto } from '../dtos/update.building.dto';
|
||||||
import { UserSpaceRepository } from '@app/common/modules/user-space/repositories';
|
import { UserSpaceRepository } from '@app/common/modules/user/repositories';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BuildingService {
|
export class BuildingService {
|
||||||
|
|||||||
@ -4,22 +4,14 @@ import { CommunityController } from './controllers/community.controller';
|
|||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { SpaceRepositoryModule } from '@app/common/modules/space/space.repository.module';
|
import { SpaceRepositoryModule } from '@app/common/modules/space/space.repository.module';
|
||||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||||
import { SpaceTypeRepositoryModule } from '@app/common/modules/space-type/space.type.repository.module';
|
import { SpaceTypeRepository } from '@app/common/modules/space/repositories';
|
||||||
import { SpaceTypeRepository } from '@app/common/modules/space-type/repositories';
|
import { UserSpaceRepository } from '@app/common/modules/user/repositories';
|
||||||
import { UserSpaceRepositoryModule } from '@app/common/modules/user-space/user.space.repository.module';
|
|
||||||
import { UserSpaceRepository } from '@app/common/modules/user-space/repositories';
|
|
||||||
import { UserRepositoryModule } from '@app/common/modules/user/user.repository.module';
|
import { UserRepositoryModule } from '@app/common/modules/user/user.repository.module';
|
||||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||||
import { SpacePermissionService } from '@app/common/helper/services';
|
import { SpacePermissionService } from '@app/common/helper/services';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [ConfigModule, SpaceRepositoryModule, UserRepositoryModule],
|
||||||
ConfigModule,
|
|
||||||
SpaceRepositoryModule,
|
|
||||||
SpaceTypeRepositoryModule,
|
|
||||||
UserSpaceRepositoryModule,
|
|
||||||
UserRepositoryModule,
|
|
||||||
],
|
|
||||||
controllers: [CommunityController],
|
controllers: [CommunityController],
|
||||||
providers: [
|
providers: [
|
||||||
CommunityService,
|
CommunityService,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { GetCommunityChildDto } from './../dtos/get.community.dto';
|
import { GetCommunityChildDto } from './../dtos/get.community.dto';
|
||||||
import { SpaceTypeRepository } from './../../../libs/common/src/modules/space-type/repositories/space.type.repository';
|
import { SpaceTypeRepository } from './../../../libs/common/src/modules/space/repositories/space.repository';
|
||||||
import {
|
import {
|
||||||
Injectable,
|
Injectable,
|
||||||
HttpException,
|
HttpException,
|
||||||
@ -16,7 +16,7 @@ import {
|
|||||||
} from '../interface/community.interface';
|
} from '../interface/community.interface';
|
||||||
import { SpaceEntity } from '@app/common/modules/space/entities';
|
import { SpaceEntity } from '@app/common/modules/space/entities';
|
||||||
import { UpdateCommunityNameDto } from '../dtos/update.community.dto';
|
import { UpdateCommunityNameDto } from '../dtos/update.community.dto';
|
||||||
import { UserSpaceRepository } from '@app/common/modules/user-space/repositories';
|
import { UserSpaceRepository } from '@app/common/modules/user/repositories';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CommunityService {
|
export class CommunityService {
|
||||||
|
|||||||
@ -2,11 +2,11 @@ import { Module } from '@nestjs/common';
|
|||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { DeviceMessagesSubscriptionController } from './controllers';
|
import { DeviceMessagesSubscriptionController } from './controllers';
|
||||||
import { DeviceMessagesSubscriptionService } from './services';
|
import { DeviceMessagesSubscriptionService } from './services';
|
||||||
import { DeviceNotificationRepositoryModule } from '@app/common/modules/device-notification/device.notification.module';
|
import { DeviceRepositoryModule } from '@app/common/modules/device/device.repository.module';
|
||||||
import { DeviceNotificationRepository } from '@app/common/modules/device-notification/repositories';
|
import { DeviceNotificationRepository } from '@app/common/modules/device/repositories';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [ConfigModule, DeviceNotificationRepositoryModule],
|
imports: [ConfigModule, DeviceRepositoryModule],
|
||||||
controllers: [DeviceMessagesSubscriptionController],
|
controllers: [DeviceMessagesSubscriptionController],
|
||||||
providers: [DeviceNotificationRepository, DeviceMessagesSubscriptionService],
|
providers: [DeviceNotificationRepository, DeviceMessagesSubscriptionService],
|
||||||
exports: [DeviceMessagesSubscriptionService],
|
exports: [DeviceMessagesSubscriptionService],
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||||
import { DeviceMessagesAddDto } from '../dtos/device-messages.dto';
|
import { DeviceMessagesAddDto } from '../dtos/device-messages.dto';
|
||||||
import { DeviceNotificationRepository } from '@app/common/modules/device-notification/repositories';
|
import { DeviceNotificationRepository } from '@app/common/modules/device/repositories';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DeviceMessagesSubscriptionService {
|
export class DeviceMessagesSubscriptionService {
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import { DeviceRepositoryModule } from '@app/common/modules/device';
|
|||||||
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||||
import { PermissionTypeRepository } from '@app/common/modules/permission/repositories';
|
import { PermissionTypeRepository } from '@app/common/modules/permission/repositories';
|
||||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||||
import { DeviceUserPermissionRepository } from '@app/common/modules/device-user-permission/repositories';
|
import { DeviceUserPermissionRepository } from '@app/common/modules/device/repositories';
|
||||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||||
import { DeviceStatusFirebaseModule } from '@app/common/firebase/devices-status/devices-status.module';
|
import { DeviceStatusFirebaseModule } from '@app/common/firebase/devices-status/devices-status.module';
|
||||||
@Module({
|
@Module({
|
||||||
|
|||||||
@ -4,21 +4,13 @@ import { FloorController } from './controllers/floor.controller';
|
|||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { SpaceRepositoryModule } from '@app/common/modules/space/space.repository.module';
|
import { SpaceRepositoryModule } from '@app/common/modules/space/space.repository.module';
|
||||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||||
import { SpaceTypeRepositoryModule } from '@app/common/modules/space-type/space.type.repository.module';
|
import { SpaceTypeRepository } from '@app/common/modules/space/repositories';
|
||||||
import { SpaceTypeRepository } from '@app/common/modules/space-type/repositories';
|
import { UserSpaceRepository } from '@app/common/modules/user/repositories';
|
||||||
import { UserSpaceRepositoryModule } from '@app/common/modules/user-space/user.space.repository.module';
|
|
||||||
import { UserSpaceRepository } from '@app/common/modules/user-space/repositories';
|
|
||||||
import { UserRepositoryModule } from '@app/common/modules/user/user.repository.module';
|
import { UserRepositoryModule } from '@app/common/modules/user/user.repository.module';
|
||||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [ConfigModule, SpaceRepositoryModule, UserRepositoryModule],
|
||||||
ConfigModule,
|
|
||||||
SpaceRepositoryModule,
|
|
||||||
SpaceTypeRepositoryModule,
|
|
||||||
UserSpaceRepositoryModule,
|
|
||||||
UserRepositoryModule,
|
|
||||||
],
|
|
||||||
controllers: [FloorController],
|
controllers: [FloorController],
|
||||||
providers: [
|
providers: [
|
||||||
FloorService,
|
FloorService,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { GetFloorChildDto } from '../dtos/get.floor.dto';
|
import { GetFloorChildDto } from '../dtos/get.floor.dto';
|
||||||
import { SpaceTypeRepository } from '../../../libs/common/src/modules/space-type/repositories/space.type.repository';
|
import { SpaceTypeRepository } from '../../../libs/common/src/modules/space/repositories/space.repository';
|
||||||
import {
|
import {
|
||||||
Injectable,
|
Injectable,
|
||||||
HttpException,
|
HttpException,
|
||||||
@ -17,7 +17,7 @@ import {
|
|||||||
} from '../interface/floor.interface';
|
} from '../interface/floor.interface';
|
||||||
import { SpaceEntity } from '@app/common/modules/space/entities';
|
import { SpaceEntity } from '@app/common/modules/space/entities';
|
||||||
import { UpdateFloorNameDto } from '../dtos/update.floor.dto';
|
import { UpdateFloorNameDto } from '../dtos/update.floor.dto';
|
||||||
import { UserSpaceRepository } from '@app/common/modules/user-space/repositories';
|
import { UserSpaceRepository } from '@app/common/modules/user/repositories';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class FloorService {
|
export class FloorService {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { NestFactory } from '@nestjs/core';
|
import { NestFactory } from '@nestjs/core';
|
||||||
import { AuthModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
import rateLimit from 'express-rate-limit';
|
import rateLimit from 'express-rate-limit';
|
||||||
import helmet from 'helmet';
|
import helmet from 'helmet';
|
||||||
import { setupSwaggerAuthentication } from '../libs/common/src/util/user-auth.swagger.utils';
|
import { setupSwaggerAuthentication } from '../libs/common/src/util/user-auth.swagger.utils';
|
||||||
@ -8,7 +8,7 @@ import { json, urlencoded } from 'body-parser';
|
|||||||
import { SeederService } from '@app/common/seed/services/seeder.service';
|
import { SeederService } from '@app/common/seed/services/seeder.service';
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AuthModule);
|
const app = await NestFactory.create(AppModule);
|
||||||
|
|
||||||
app.enableCors();
|
app.enableCors();
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user