mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
resolve conflicts
This commit is contained in:
@ -90,3 +90,6 @@ FIREBASE_DATABASE_URL=
|
||||
|
||||
OTP_LIMITER=
|
||||
|
||||
GOOGLE_CLIENT_ID=
|
||||
|
||||
GOOGLE_CLIENT_SECRET=
|
@ -1,4 +1,8 @@
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import {
|
||||
BadRequestException,
|
||||
Injectable,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import * as argon2 from 'argon2';
|
||||
import { HelperHashService } from '../../helper/services';
|
||||
@ -6,16 +10,20 @@ import { UserRepository } from '../../../../common/src/modules/user/repositories
|
||||
import { UserSessionRepository } from '../../../../common/src/modules/session/repositories/session.repository';
|
||||
import { UserSessionEntity } from '../../../../common/src/modules/session/entities';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { OAuth2Client } from 'google-auth-library';
|
||||
|
||||
@Injectable()
|
||||
export class AuthService {
|
||||
private client: OAuth2Client;
|
||||
constructor(
|
||||
private jwtService: JwtService,
|
||||
private readonly userRepository: UserRepository,
|
||||
private readonly sessionRepository: UserSessionRepository,
|
||||
private readonly helperHashService: HelperHashService,
|
||||
private readonly configService: ConfigService,
|
||||
) {}
|
||||
) {
|
||||
this.client = new OAuth2Client(this.configService.get('GOOGLE_CLIENT_ID'));
|
||||
}
|
||||
|
||||
async validateUser(
|
||||
email: string,
|
||||
@ -80,8 +88,17 @@ export class AuthService {
|
||||
type: user.type,
|
||||
sessionId: user.sessionId,
|
||||
roles: user?.roles,
|
||||
googleCode: user.googleCode,
|
||||
};
|
||||
|
||||
if (payload.googleCode) {
|
||||
const profile = await this.getProfile(payload.googleCode);
|
||||
user = await this.userRepository.findOne({
|
||||
where: { email: profile.email },
|
||||
});
|
||||
if (!user) {
|
||||
return { profile };
|
||||
}
|
||||
}
|
||||
const tokens = await this.getTokens(payload);
|
||||
await this.updateRefreshToken(user.uuid, tokens.refreshToken);
|
||||
return tokens;
|
||||
@ -100,4 +117,19 @@ export class AuthService {
|
||||
hashData(data: string) {
|
||||
return argon2.hash(data);
|
||||
}
|
||||
|
||||
async getProfile(googleCode: string) {
|
||||
try {
|
||||
const ticket = await this.client.verifyIdToken({
|
||||
idToken: googleCode,
|
||||
audience: this.configService.get('GOOGLE_CLIENT_ID'),
|
||||
});
|
||||
const payload = ticket.getPayload();
|
||||
return {
|
||||
...payload,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new UnauthorizedException('Google login failed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,16 @@ import { AuthModule } from './auth/auth.module';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import config from './config';
|
||||
import { EmailService } from './util/email.service';
|
||||
|
||||
import { ErrorMessageService } from 'src/error-message/error-message.service';
|
||||
@Module({
|
||||
providers: [CommonService, EmailService],
|
||||
exports: [CommonService, HelperModule, AuthModule, EmailService],
|
||||
providers: [CommonService, EmailService, ErrorMessageService],
|
||||
exports: [
|
||||
CommonService,
|
||||
HelperModule,
|
||||
AuthModule,
|
||||
EmailService,
|
||||
ErrorMessageService,
|
||||
],
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
load: config,
|
||||
|
@ -13,4 +13,6 @@ export enum ProductType {
|
||||
TWO_2TG = '2GT',
|
||||
ONE_1TG = '1GT',
|
||||
WL = 'WL',
|
||||
GD = 'GD',
|
||||
CUR = 'CUR',
|
||||
}
|
||||
|
@ -85,6 +85,7 @@ export class DeviceStatusFirebaseService {
|
||||
return await this.deviceRepository.findOne({
|
||||
where: {
|
||||
deviceTuyaUuid,
|
||||
isActive: true,
|
||||
},
|
||||
relations: ['productDevice'],
|
||||
});
|
||||
@ -139,6 +140,7 @@ export class DeviceStatusFirebaseService {
|
||||
return await this.deviceRepository.findOne({
|
||||
where: {
|
||||
uuid: deviceUuid,
|
||||
isActive: true,
|
||||
},
|
||||
...(withProductDevice && { relations: ['productDevice'] }),
|
||||
});
|
||||
|
@ -18,8 +18,9 @@ export class DeviceEntity extends AbstractEntity<DeviceDto> {
|
||||
@Column({
|
||||
nullable: true,
|
||||
default: true,
|
||||
type: 'boolean',
|
||||
})
|
||||
isActive: true;
|
||||
isActive: boolean;
|
||||
|
||||
@ManyToOne(() => UserEntity, (user) => user.userSpaces, { nullable: false })
|
||||
user: UserEntity;
|
||||
|
164
package-lock.json
generated
164
package-lock.json
generated
@ -20,13 +20,14 @@
|
||||
"@nestjs/websockets": "^10.3.8",
|
||||
"@tuya/tuya-connector-nodejs": "^2.1.2",
|
||||
"argon2": "^0.40.1",
|
||||
"axios": "^1.6.7",
|
||||
"axios": "^1.7.7",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.1",
|
||||
"crypto-js": "^4.2.0",
|
||||
"express-rate-limit": "^7.1.5",
|
||||
"firebase": "^10.12.5",
|
||||
"google-auth-library": "^9.14.1",
|
||||
"helmet": "^7.1.0",
|
||||
"ioredis": "^5.3.2",
|
||||
"morgan": "^1.10.0",
|
||||
@ -3564,6 +3565,18 @@
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/agent-base": {
|
||||
"version": "7.1.1",
|
||||
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz",
|
||||
"integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"debug": "^4.3.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 14"
|
||||
}
|
||||
},
|
||||
"node_modules/ajv": {
|
||||
"version": "8.12.0",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz",
|
||||
@ -3784,11 +3797,12 @@
|
||||
"integrity": "sha512-3AungXC4I8kKsS9PuS4JH2nc+0bVY/mjgrephHTIi8fpEeGsTHBUJeosp0Wc1myYMElmD0B3Oc4XL/HVJ4PV2g=="
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.6.7",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.7.tgz",
|
||||
"integrity": "sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==",
|
||||
"version": "1.7.7",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz",
|
||||
"integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.4",
|
||||
"follow-redirects": "^1.15.6",
|
||||
"form-data": "^4.0.0",
|
||||
"proxy-from-env": "^1.1.0"
|
||||
}
|
||||
@ -3962,6 +3976,15 @@
|
||||
"resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz",
|
||||
"integrity": "sha512-V/Hy/X9Vt7f3BbPJEi8BdVFMByHi+jNXrYkW3huaybV/kQ0KJg0Y6PkEMbn+zeT+i+SiKZ/HMqJGIIt4LZDqNQ=="
|
||||
},
|
||||
"node_modules/bignumber.js": {
|
||||
"version": "9.1.2",
|
||||
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz",
|
||||
"integrity": "sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/binary-extensions": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz",
|
||||
@ -5887,15 +5910,16 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/follow-redirects": {
|
||||
"version": "1.15.5",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz",
|
||||
"integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==",
|
||||
"version": "1.15.9",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz",
|
||||
"integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=4.0"
|
||||
},
|
||||
@ -6056,6 +6080,35 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/gaxios": {
|
||||
"version": "6.7.1",
|
||||
"resolved": "https://registry.npmjs.org/gaxios/-/gaxios-6.7.1.tgz",
|
||||
"integrity": "sha512-LDODD4TMYx7XXdpwxAVRAIAuB0bzv0s+ywFonY46k126qzQHT9ygyoa9tncmOiQmmDrik65UYsEkv3lbfqQ3yQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"extend": "^3.0.2",
|
||||
"https-proxy-agent": "^7.0.1",
|
||||
"is-stream": "^2.0.0",
|
||||
"node-fetch": "^2.6.9",
|
||||
"uuid": "^9.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/gcp-metadata": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-6.1.0.tgz",
|
||||
"integrity": "sha512-Jh/AIwwgaxan+7ZUUmRLCjtchyDiqh4KjBJ5tW3plBZb5iL/BPcso8A5DlzeD9qlw0duCamnNdpFjxwaT0KyKg==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"gaxios": "^6.0.0",
|
||||
"json-bigint": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/gensync": {
|
||||
"version": "1.0.0-beta.2",
|
||||
"resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz",
|
||||
@ -6194,6 +6247,44 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/google-auth-library": {
|
||||
"version": "9.14.1",
|
||||
"resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-9.14.1.tgz",
|
||||
"integrity": "sha512-Rj+PMjoNFGFTmtItH7gHfbHpGVSb3vmnGK3nwNBqxQF9NoBpttSZI/rc0WiM63ma2uGDQtYEkMHkK9U6937NiA==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"base64-js": "^1.3.0",
|
||||
"ecdsa-sig-formatter": "^1.0.11",
|
||||
"gaxios": "^6.1.1",
|
||||
"gcp-metadata": "^6.1.0",
|
||||
"gtoken": "^7.0.0",
|
||||
"jws": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/google-auth-library/node_modules/jwa": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.0.tgz",
|
||||
"integrity": "sha512-jrZ2Qx916EA+fq9cEAeCROWPTfCwi1IVHqT2tapuqLEVVDKFDENFw1oL+MwrTvH6msKxsd1YTDVw6uKEcsrLEA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"buffer-equal-constant-time": "1.0.1",
|
||||
"ecdsa-sig-formatter": "1.0.11",
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/google-auth-library/node_modules/jws": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jws/-/jws-4.0.0.tgz",
|
||||
"integrity": "sha512-KDncfTmOZoOMTFG4mBlG0qUIOlc03fmzH+ru6RgYVZhPkyiy/92Owlt/8UEN+a4TXR1FQetfIpJE8ApdvdVxTg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"jwa": "^2.0.0",
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/gopd": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz",
|
||||
@ -6217,6 +6308,40 @@
|
||||
"integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/gtoken": {
|
||||
"version": "7.1.0",
|
||||
"resolved": "https://registry.npmjs.org/gtoken/-/gtoken-7.1.0.tgz",
|
||||
"integrity": "sha512-pCcEwRi+TKpMlxAQObHDQ56KawURgyAf6jtIY046fJ5tIv3zDe/LEIubckAO8fj6JnAxLdmWkUfNyulQ2iKdEw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"gaxios": "^6.0.0",
|
||||
"jws": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/gtoken/node_modules/jwa": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.0.tgz",
|
||||
"integrity": "sha512-jrZ2Qx916EA+fq9cEAeCROWPTfCwi1IVHqT2tapuqLEVVDKFDENFw1oL+MwrTvH6msKxsd1YTDVw6uKEcsrLEA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"buffer-equal-constant-time": "1.0.1",
|
||||
"ecdsa-sig-formatter": "1.0.11",
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/gtoken/node_modules/jws": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jws/-/jws-4.0.0.tgz",
|
||||
"integrity": "sha512-KDncfTmOZoOMTFG4mBlG0qUIOlc03fmzH+ru6RgYVZhPkyiy/92Owlt/8UEN+a4TXR1FQetfIpJE8ApdvdVxTg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"jwa": "^2.0.0",
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/har-schema": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz",
|
||||
@ -6384,6 +6509,19 @@
|
||||
"npm": ">=1.3.7"
|
||||
}
|
||||
},
|
||||
"node_modules/https-proxy-agent": {
|
||||
"version": "7.0.5",
|
||||
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.5.tgz",
|
||||
"integrity": "sha512-1e4Wqeblerz+tMKPIq2EMGiiWW1dIjZOksyHWSUm1rmuvw/how9hBHZ38lAGj5ID4Ik6EdkOw7NmWPy6LAwalw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"agent-base": "^7.0.2",
|
||||
"debug": "4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 14"
|
||||
}
|
||||
},
|
||||
"node_modules/human-signals": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz",
|
||||
@ -6689,7 +6827,6 @@
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz",
|
||||
"integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
@ -7533,6 +7670,15 @@
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/json-bigint": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-1.0.0.tgz",
|
||||
"integrity": "sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bignumber.js": "^9.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/json-buffer": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz",
|
||||
|
@ -31,13 +31,14 @@
|
||||
"@nestjs/websockets": "^10.3.8",
|
||||
"@tuya/tuya-connector-nodejs": "^2.1.2",
|
||||
"argon2": "^0.40.1",
|
||||
"axios": "^1.6.7",
|
||||
"axios": "^1.7.7",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.1",
|
||||
"crypto-js": "^4.2.0",
|
||||
"express-rate-limit": "^7.1.5",
|
||||
"firebase": "^10.12.5",
|
||||
"google-auth-library": "^9.14.1",
|
||||
"helmet": "^7.1.0",
|
||||
"ioredis": "^5.3.2",
|
||||
"morgan": "^1.10.0",
|
||||
|
@ -2,7 +2,6 @@ import { Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import config from './config';
|
||||
import { AuthenticationModule } from './auth/auth.module';
|
||||
import { AuthenticationController } from './auth/controllers/authentication.controller';
|
||||
import { UserModule } from './users/user.module';
|
||||
import { RoomModule } from './room/room.module';
|
||||
import { GroupModule } from './group/group.module';
|
||||
@ -53,7 +52,6 @@ import { ScheduleModule } from './schedule/schedule.module';
|
||||
VisitorPasswordModule,
|
||||
ScheduleModule,
|
||||
],
|
||||
controllers: [AuthenticationController],
|
||||
providers: [
|
||||
{
|
||||
provide: APP_INTERCEPTOR,
|
||||
|
@ -1,6 +1,4 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AuthenticationController } from './controllers/authentication.controller';
|
||||
import { AuthenticationService } from './services/authentication.service';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { UserRepositoryModule } from '@app/common/modules/user/user.repository.module';
|
||||
import { CommonModule } from '../../libs/common/src';
|
||||
@ -16,9 +14,8 @@ import { RoleTypeRepository } from '@app/common/modules/role-type/repositories';
|
||||
|
||||
@Module({
|
||||
imports: [ConfigModule, UserRepositoryModule, CommonModule],
|
||||
controllers: [AuthenticationController, UserAuthController],
|
||||
controllers: [UserAuthController],
|
||||
providers: [
|
||||
AuthenticationService,
|
||||
UserAuthService,
|
||||
UserRepository,
|
||||
UserSessionRepository,
|
||||
@ -26,6 +23,6 @@ import { RoleTypeRepository } from '@app/common/modules/role-type/repositories';
|
||||
UserRoleRepository,
|
||||
RoleTypeRepository,
|
||||
],
|
||||
exports: [AuthenticationService, UserAuthService],
|
||||
exports: [UserAuthService],
|
||||
})
|
||||
export class AuthenticationModule {}
|
||||
|
@ -1,17 +0,0 @@
|
||||
import { Controller, Post } from '@nestjs/common';
|
||||
import { AuthenticationService } from '../services/authentication.service';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
|
||||
@Controller({
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: 'authentication',
|
||||
})
|
||||
@ApiTags('Tuya Auth')
|
||||
export class AuthenticationController {
|
||||
constructor(private readonly authenticationService: AuthenticationService) {}
|
||||
@Post('auth2')
|
||||
async Authentication() {
|
||||
return await this.authenticationService.main();
|
||||
}
|
||||
}
|
@ -1,2 +1 @@
|
||||
export * from './authentication.controller';
|
||||
export * from './user-auth.controller';
|
||||
|
@ -84,7 +84,7 @@ export class UserAuthController {
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(SuperAdminRoleGuard)
|
||||
@Get('user/list')
|
||||
@Get('user')
|
||||
async userList() {
|
||||
const userList = await this.userAuthService.userList();
|
||||
return {
|
||||
|
@ -41,5 +41,5 @@ export class UserSignUpDto {
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
public regionUuid: string;
|
||||
public regionUuid?: string;
|
||||
}
|
||||
|
@ -1,19 +1,23 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
||||
import { IsEmail, IsOptional, IsString } from 'class-validator';
|
||||
|
||||
export class UserLoginDto {
|
||||
@ApiProperty()
|
||||
@IsEmail()
|
||||
@IsNotEmpty()
|
||||
email: string;
|
||||
@IsOptional()
|
||||
email?: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
password: string;
|
||||
password?: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
regionUuid?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
googleCode?: string;
|
||||
}
|
||||
|
@ -1,120 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import * as qs from 'qs';
|
||||
import * as crypto from 'crypto';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import axios from 'axios';
|
||||
@Injectable()
|
||||
export class AuthenticationService {
|
||||
private token: string;
|
||||
private deviceId: string;
|
||||
private accessKey: string;
|
||||
private secretKey: string;
|
||||
|
||||
constructor(private readonly configService: ConfigService) {
|
||||
(this.deviceId = this.configService.get<string>('auth-config.DEVICE_ID')),
|
||||
(this.accessKey = this.configService.get<string>(
|
||||
'auth-config.ACCESS_KEY',
|
||||
)),
|
||||
(this.secretKey = this.configService.get<string>(
|
||||
'auth-config.SECRET_KEY',
|
||||
));
|
||||
}
|
||||
|
||||
async main() {
|
||||
await this.getToken();
|
||||
const data = await this.getDeviceInfo(this.deviceId);
|
||||
console.log('fetch success: ', JSON.stringify(data));
|
||||
return JSON.stringify(data);
|
||||
}
|
||||
|
||||
async getToken() {
|
||||
const method = 'GET';
|
||||
const timestamp = Date.now().toString();
|
||||
const signUrl = 'https://openapi.tuyaeu.com/v1.0/token?grant_type=1';
|
||||
const contentHash = crypto.createHash('sha256').update('').digest('hex');
|
||||
const stringToSign = [method, contentHash, '', signUrl].join('\n');
|
||||
const signStr = this.accessKey + timestamp + stringToSign;
|
||||
|
||||
const headers = {
|
||||
t: timestamp,
|
||||
sign_method: 'HMAC-SHA256',
|
||||
client_id: this.accessKey,
|
||||
sign: await this.encryptStr(signStr, this.secretKey),
|
||||
};
|
||||
|
||||
const { data: login } = await axios.get(
|
||||
'https://openapi.tuyaeu.com/v1.0/token',
|
||||
{
|
||||
params: {
|
||||
grant_type: 1,
|
||||
},
|
||||
headers,
|
||||
},
|
||||
);
|
||||
|
||||
if (!login || !login.success) {
|
||||
throw new Error(`fetch failed: ${login.msg}`);
|
||||
}
|
||||
this.token = login.result.access_token;
|
||||
}
|
||||
|
||||
async getDeviceInfo(deviceId: string) {
|
||||
const query = {};
|
||||
const method = 'POST';
|
||||
const url = `https://openapi.tuyaeu.com/v1.0/devices/${deviceId}/commands`;
|
||||
const reqHeaders: { [k: string]: string } = await this.getRequestSign(
|
||||
url,
|
||||
method,
|
||||
{},
|
||||
query,
|
||||
);
|
||||
|
||||
const { data } = await axios.post(url, {}, reqHeaders);
|
||||
|
||||
if (!data || !data.success) {
|
||||
throw new Error(`request api failed: ${data.msg}`);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
async encryptStr(str: string, secret: string): Promise<string> {
|
||||
return crypto
|
||||
.createHmac('sha256', secret)
|
||||
.update(str, 'utf8')
|
||||
.digest('hex')
|
||||
.toUpperCase();
|
||||
}
|
||||
|
||||
async getRequestSign(
|
||||
path: string,
|
||||
method: string,
|
||||
query: { [k: string]: any } = {},
|
||||
body: { [k: string]: any } = {},
|
||||
) {
|
||||
const t = Date.now().toString();
|
||||
const [uri, pathQuery] = path.split('?');
|
||||
const queryMerged = Object.assign(query, qs.parse(pathQuery));
|
||||
const sortedQuery: { [k: string]: string } = {};
|
||||
Object.keys(queryMerged)
|
||||
.sort()
|
||||
.forEach((i) => (sortedQuery[i] = query[i]));
|
||||
|
||||
const querystring = decodeURIComponent(qs.stringify(sortedQuery));
|
||||
const url = querystring ? `${uri}?${querystring}` : uri;
|
||||
const contentHash = crypto
|
||||
.createHash('sha256')
|
||||
.update(JSON.stringify(body))
|
||||
.digest('hex');
|
||||
const stringToSign = [method, contentHash, '', url].join('\n');
|
||||
const signStr = this.accessKey + this.token + t + stringToSign;
|
||||
return {
|
||||
t,
|
||||
path: url,
|
||||
client_id: 'this.accessKey',
|
||||
sign: await this.encryptStr(signStr, this.secretKey),
|
||||
sign_method: 'HMAC-SHA256',
|
||||
access_token: this.token,
|
||||
};
|
||||
}
|
||||
}
|
@ -1,2 +1 @@
|
||||
export * from './authentication.service';
|
||||
export * from './user-auth.service';
|
||||
|
@ -3,7 +3,6 @@ import {
|
||||
BadRequestException,
|
||||
ForbiddenException,
|
||||
Injectable,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { UserSignUpDto } from '../dtos/user-auth.dto';
|
||||
import { HelperHashService } from '../../../libs/common/src/helper/services';
|
||||
@ -19,6 +18,7 @@ import * as argon2 from 'argon2';
|
||||
import { differenceInSeconds } from '@app/common/helper/differenceInSeconds';
|
||||
import { LessThan, MoreThan } from 'typeorm';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { UUID } from 'typeorm/driver/mongodb/bson.typings';
|
||||
|
||||
@Injectable()
|
||||
export class UserAuthService {
|
||||
@ -89,13 +89,38 @@ export class UserAuthService {
|
||||
|
||||
async userLogin(data: UserLoginDto) {
|
||||
try {
|
||||
const user = await this.authService.validateUser(
|
||||
let user;
|
||||
if (data.googleCode) {
|
||||
const googleUserData = await this.authService.login({
|
||||
googleCode: data.googleCode,
|
||||
});
|
||||
const userExists = await this.userRepository.exists({
|
||||
where: {
|
||||
email: googleUserData['email'],
|
||||
},
|
||||
});
|
||||
user = await this.userRepository.findOne({
|
||||
where: {
|
||||
email: googleUserData['email'],
|
||||
},
|
||||
});
|
||||
if (!userExists) {
|
||||
await this.signUp({
|
||||
email: googleUserData['email'],
|
||||
firstName: googleUserData['given_name'],
|
||||
lastName: googleUserData['family_name'],
|
||||
password: googleUserData['email'],
|
||||
});
|
||||
}
|
||||
data.email = googleUserData['email'];
|
||||
data.password = googleUserData['password'];
|
||||
}
|
||||
if (!data.googleCode) {
|
||||
user = await this.authService.validateUser(
|
||||
data.email,
|
||||
data.password,
|
||||
data.regionUuid,
|
||||
);
|
||||
if (!user) {
|
||||
throw new UnauthorizedException('Invalid login credentials.');
|
||||
}
|
||||
const session = await Promise.all([
|
||||
await this.sessionRepository.update(
|
||||
@ -110,7 +135,7 @@ export class UserAuthService {
|
||||
isLoggedOut: false,
|
||||
}),
|
||||
]);
|
||||
return await this.authService.login({
|
||||
const res = await this.authService.login({
|
||||
email: user.email,
|
||||
userId: user.uuid,
|
||||
uuid: user.uuid,
|
||||
@ -119,6 +144,7 @@ export class UserAuthService {
|
||||
}),
|
||||
sessionId: session[1].uuid,
|
||||
});
|
||||
return res;
|
||||
} catch (error) {
|
||||
throw new BadRequestException('Invalid credentials');
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import {
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Param,
|
||||
Post,
|
||||
@ -32,7 +31,6 @@ export class AutomationController {
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post()
|
||||
async addAutomation(@Body() addAutomationDto: AddAutomationDto) {
|
||||
try {
|
||||
const automation =
|
||||
await this.automationService.addAutomation(addAutomationDto);
|
||||
return {
|
||||
@ -41,43 +39,22 @@ export class AutomationController {
|
||||
message: 'Automation added successfully',
|
||||
data: automation,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get(':unitUuid')
|
||||
async getAutomationByUnit(@Param('unitUuid') unitUuid: string) {
|
||||
try {
|
||||
const automation =
|
||||
await this.automationService.getAutomationByUnit(unitUuid);
|
||||
return automation;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('details/:automationId')
|
||||
async getAutomationDetails(@Param('automationId') automationId: string) {
|
||||
try {
|
||||
const automation =
|
||||
await this.automationService.getAutomationDetails(automationId);
|
||||
return automation;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
``;
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -86,18 +63,11 @@ export class AutomationController {
|
||||
@Param('unitUuid') unitUuid: string,
|
||||
@Param('automationId') automationId: string,
|
||||
) {
|
||||
try {
|
||||
await this.automationService.deleteAutomation(unitUuid, automationId);
|
||||
return {
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'Automation Deleted Successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -106,7 +76,6 @@ export class AutomationController {
|
||||
@Body() updateAutomationDto: UpdateAutomationDto,
|
||||
@Param('automationId') automationId: string,
|
||||
) {
|
||||
try {
|
||||
const automation = await this.automationService.updateAutomation(
|
||||
updateAutomationDto,
|
||||
automationId,
|
||||
@ -117,12 +86,6 @@ export class AutomationController {
|
||||
message: 'Automation updated successfully',
|
||||
data: automation,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -131,7 +94,6 @@ export class AutomationController {
|
||||
@Body() updateAutomationStatusDto: UpdateAutomationStatusDto,
|
||||
@Param('automationId') automationId: string,
|
||||
) {
|
||||
try {
|
||||
await this.automationService.updateAutomationStatus(
|
||||
updateAutomationStatusDto,
|
||||
automationId,
|
||||
@ -141,11 +103,5 @@ export class AutomationController {
|
||||
success: true,
|
||||
message: 'Automation status updated successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Param,
|
||||
Post,
|
||||
@ -35,7 +34,6 @@ export class BuildingController {
|
||||
@UseGuards(JwtAuthGuard, CheckCommunityTypeGuard)
|
||||
@Post()
|
||||
async addBuilding(@Body() addBuildingDto: AddBuildingDto) {
|
||||
try {
|
||||
const building = await this.buildingService.addBuilding(addBuildingDto);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
@ -43,28 +41,14 @@ export class BuildingController {
|
||||
message: 'Building added successfully',
|
||||
data: building,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, BuildingPermissionGuard)
|
||||
@Get(':buildingUuid')
|
||||
async getBuildingByUuid(@Param('buildingUuid') buildingUuid: string) {
|
||||
try {
|
||||
const building =
|
||||
await this.buildingService.getBuildingByUuid(buildingUuid);
|
||||
const building = await this.buildingService.getBuildingByUuid(buildingUuid);
|
||||
return building;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@ -74,84 +58,49 @@ export class BuildingController {
|
||||
@Param('buildingUuid') buildingUuid: string,
|
||||
@Query() query: GetBuildingChildDto,
|
||||
) {
|
||||
try {
|
||||
const building = await this.buildingService.getBuildingChildByUuid(
|
||||
buildingUuid,
|
||||
query,
|
||||
);
|
||||
return building;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, BuildingPermissionGuard)
|
||||
@Get('parent/:buildingUuid')
|
||||
async getBuildingParentByUuid(@Param('buildingUuid') buildingUuid: string) {
|
||||
try {
|
||||
const building =
|
||||
await this.buildingService.getBuildingParentByUuid(buildingUuid);
|
||||
return building;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(AdminRoleGuard, CheckUserBuildingGuard)
|
||||
@Post('user')
|
||||
async addUserBuilding(@Body() addUserBuildingDto: AddUserBuildingDto) {
|
||||
try {
|
||||
await this.buildingService.addUserBuilding(addUserBuildingDto);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'user building added successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('user/:userUuid')
|
||||
async getBuildingsByUserId(@Param('userUuid') userUuid: string) {
|
||||
try {
|
||||
return await this.buildingService.getBuildingsByUserId(userUuid);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, BuildingPermissionGuard)
|
||||
@Put('rename/:buildingUuid')
|
||||
@Put(':buildingUuid')
|
||||
async renameBuildingByUuid(
|
||||
@Param('buildingUuid') buildingUuid: string,
|
||||
@Body() updateBuildingDto: UpdateBuildingNameDto,
|
||||
) {
|
||||
try {
|
||||
const building = await this.buildingService.renameBuildingByUuid(
|
||||
buildingUuid,
|
||||
updateBuildingDto,
|
||||
);
|
||||
return building;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
import { HttpExceptionFilter } from './http-exception.filter';
|
||||
|
||||
describe('HttpExceptionFilter', () => {
|
||||
it('should be defined', () => {
|
||||
expect(new HttpExceptionFilter()).toBeDefined();
|
||||
});
|
||||
});
|
38
src/common/filters/http-exception/http-exception.filter.ts
Normal file
38
src/common/filters/http-exception/http-exception.filter.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import {
|
||||
ExceptionFilter,
|
||||
Catch,
|
||||
ArgumentsHost,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
} from '@nestjs/common';
|
||||
import { Response } from 'express';
|
||||
|
||||
@Catch()
|
||||
export class HttpExceptionFilter implements ExceptionFilter {
|
||||
catch(exception: unknown, host: ArgumentsHost) {
|
||||
const ctx = host.switchToHttp();
|
||||
const response = ctx.getResponse<Response>();
|
||||
const request = ctx.getRequest<Request>();
|
||||
const status =
|
||||
exception instanceof HttpException
|
||||
? exception.getStatus()
|
||||
: HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
|
||||
const message =
|
||||
exception instanceof HttpException
|
||||
? exception.getResponse()
|
||||
: 'Internal server error';
|
||||
|
||||
const errorResponse = {
|
||||
statusCode: status,
|
||||
timestamp: new Date().toISOString(),
|
||||
path: request.url,
|
||||
error: message,
|
||||
};
|
||||
|
||||
// Optionally log the exception
|
||||
console.error(`Error occurred:`, exception);
|
||||
|
||||
response.status(status).json(errorResponse);
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Param,
|
||||
Post,
|
||||
@ -18,7 +17,6 @@ import {
|
||||
} from '../dtos/add.community.dto';
|
||||
import { GetCommunityChildDto } from '../dtos/get.community.dto';
|
||||
import { UpdateCommunityNameDto } from '../dtos/update.community.dto';
|
||||
// import { CheckUserCommunityGuard } from 'src/guards/user.community.guard';
|
||||
import { AdminRoleGuard } from 'src/guards/admin.role.guard';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
@ -37,51 +35,29 @@ export class CommunityController {
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post()
|
||||
async addCommunity(@Body() addCommunityDto: AddCommunityDto) {
|
||||
try {
|
||||
const community =
|
||||
await this.communityService.addCommunity(addCommunityDto);
|
||||
const community = await this.communityService.addCommunity(addCommunityDto);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'Community added successfully',
|
||||
data: community,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get(':communityUuid')
|
||||
async getCommunityByUuid(@Param('communityUuid') communityUuid: string) {
|
||||
try {
|
||||
const community =
|
||||
await this.communityService.getCommunityByUuid(communityUuid);
|
||||
return community;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get()
|
||||
async getCommunities() {
|
||||
try {
|
||||
const communities = await this.communityService.getCommunities();
|
||||
return communities;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -90,69 +66,41 @@ export class CommunityController {
|
||||
@Param('communityUuid') communityUuid: string,
|
||||
@Query() query: GetCommunityChildDto,
|
||||
) {
|
||||
try {
|
||||
const community = await this.communityService.getCommunityChildByUuid(
|
||||
communityUuid,
|
||||
query,
|
||||
);
|
||||
return community;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('user/:userUuid')
|
||||
async getCommunitiesByUserId(@Param('userUuid') userUuid: string) {
|
||||
try {
|
||||
return await this.communityService.getCommunitiesByUserId(userUuid);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(AdminRoleGuard)
|
||||
@Post('user')
|
||||
async addUserCommunity(@Body() addUserCommunityDto: AddUserCommunityDto) {
|
||||
try {
|
||||
await this.communityService.addUserCommunity(addUserCommunityDto);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'user community added successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put('rename/:communityUuid')
|
||||
@Put(':communityUuid')
|
||||
async renameCommunityByUuid(
|
||||
@Param('communityUuid') communityUuid: string,
|
||||
@Body() updateCommunityDto: UpdateCommunityNameDto,
|
||||
) {
|
||||
try {
|
||||
const community = await this.communityService.renameCommunityByUuid(
|
||||
communityUuid,
|
||||
updateCommunityDto,
|
||||
);
|
||||
return community;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ import {
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Param,
|
||||
Post,
|
||||
@ -32,7 +31,6 @@ export class DeviceMessagesSubscriptionController {
|
||||
async addDeviceMessagesSubscription(
|
||||
@Body() deviceMessagesAddDto: DeviceMessagesAddDto,
|
||||
) {
|
||||
try {
|
||||
const addDetails =
|
||||
await this.deviceMessagesSubscriptionService.addDeviceMessagesSubscription(
|
||||
deviceMessagesAddDto,
|
||||
@ -42,12 +40,6 @@ export class DeviceMessagesSubscriptionController {
|
||||
message: 'Device Messages Subscription Added Successfully',
|
||||
data: addDetails,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@ -57,7 +49,6 @@ export class DeviceMessagesSubscriptionController {
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Param('userUuid') userUuid: string,
|
||||
) {
|
||||
try {
|
||||
const deviceDetails =
|
||||
await this.deviceMessagesSubscriptionService.getDeviceMessagesSubscription(
|
||||
userUuid,
|
||||
@ -68,12 +59,6 @@ export class DeviceMessagesSubscriptionController {
|
||||
message: 'User Device Subscription fetched Successfully',
|
||||
data: deviceDetails,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -81,7 +66,6 @@ export class DeviceMessagesSubscriptionController {
|
||||
async deleteDeviceMessagesSubscription(
|
||||
@Body() deviceMessagesAddDto: DeviceMessagesAddDto,
|
||||
) {
|
||||
try {
|
||||
await this.deviceMessagesSubscriptionService.deleteDeviceMessagesSubscription(
|
||||
deviceMessagesAddDto,
|
||||
);
|
||||
@ -89,11 +73,5 @@ export class DeviceMessagesSubscriptionController {
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'User subscription deleted Successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import {
|
||||
Post,
|
||||
Query,
|
||||
Param,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
UseGuards,
|
||||
Req,
|
||||
@ -44,7 +43,6 @@ export class DeviceController {
|
||||
@UseGuards(SuperAdminRoleGuard, CheckDeviceGuard)
|
||||
@Post()
|
||||
async addDeviceUser(@Body() addDeviceDto: AddDeviceDto) {
|
||||
try {
|
||||
const device = await this.deviceService.addDeviceUser(addDeviceDto);
|
||||
|
||||
return {
|
||||
@ -53,25 +51,12 @@ export class DeviceController {
|
||||
message: 'device added successfully',
|
||||
data: device,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('user/:userUuid')
|
||||
async getDevicesByUser(@Param('userUuid') userUuid: string) {
|
||||
try {
|
||||
return await this.deviceService.getDevicesByUser(userUuid);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, CheckRoomGuard)
|
||||
@ -80,31 +65,17 @@ export class DeviceController {
|
||||
@Query() getDeviceByRoomUuidDto: GetDeviceByRoomUuidDto,
|
||||
@Req() req: any,
|
||||
) {
|
||||
try {
|
||||
const userUuid = req.user.uuid;
|
||||
return await this.deviceService.getDevicesByRoomId(
|
||||
getDeviceByRoomUuidDto,
|
||||
userUuid,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('unit/:unitUuid')
|
||||
async getDevicesByUnitId(@Param('unitUuid') unitUuid: string) {
|
||||
try {
|
||||
return await this.deviceService.getDevicesByUnitId(unitUuid);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, CheckRoomGuard)
|
||||
@ -112,7 +83,6 @@ export class DeviceController {
|
||||
async updateDeviceInRoom(
|
||||
@Body() updateDeviceInRoomDto: UpdateDeviceInRoomDto,
|
||||
) {
|
||||
try {
|
||||
const device = await this.deviceService.updateDeviceInRoom(
|
||||
updateDeviceInRoomDto,
|
||||
);
|
||||
@ -123,12 +93,6 @@ export class DeviceController {
|
||||
message: 'device updated in room successfully',
|
||||
data: device,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@ -138,18 +102,11 @@ export class DeviceController {
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Req() req: any,
|
||||
) {
|
||||
try {
|
||||
const userUuid = req.user.uuid;
|
||||
return await this.deviceService.getDeviceDetailsByDeviceId(
|
||||
deviceUuid,
|
||||
userUuid,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, CheckUserHavePermission)
|
||||
@ -157,29 +114,13 @@ export class DeviceController {
|
||||
async getDeviceInstructionByDeviceId(
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
) {
|
||||
try {
|
||||
return await this.deviceService.getDeviceInstructionByDeviceId(
|
||||
deviceUuid,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
return await this.deviceService.getDeviceInstructionByDeviceId(deviceUuid);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, CheckUserHavePermission)
|
||||
@Get(':deviceUuid/functions/status')
|
||||
async getDevicesInstructionStatus(@Param('deviceUuid') deviceUuid: string) {
|
||||
try {
|
||||
return await this.deviceService.getDevicesInstructionStatus(deviceUuid);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@ -189,17 +130,7 @@ export class DeviceController {
|
||||
@Body() controlDeviceDto: ControlDeviceDto,
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
) {
|
||||
try {
|
||||
return await this.deviceService.controlDevice(
|
||||
controlDeviceDto,
|
||||
deviceUuid,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
return await this.deviceService.controlDevice(controlDeviceDto, deviceUuid);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -208,43 +139,22 @@ export class DeviceController {
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Param('firmwareVersion') firmwareVersion: number,
|
||||
) {
|
||||
try {
|
||||
return await this.deviceService.updateDeviceFirmware(
|
||||
deviceUuid,
|
||||
firmwareVersion,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('gateway/:gatewayUuid/devices')
|
||||
async getDevicesInGateway(@Param('gatewayUuid') gatewayUuid: string) {
|
||||
try {
|
||||
return await this.deviceService.getDevicesInGateway(gatewayUuid);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get()
|
||||
async getAllDevices() {
|
||||
try {
|
||||
return await this.deviceService.getAllDevices();
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -253,14 +163,7 @@ export class DeviceController {
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Query() query: GetDeviceLogsDto,
|
||||
) {
|
||||
try {
|
||||
return await this.deviceService.getDeviceLogs(deviceUuid, query);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -268,16 +171,7 @@ export class DeviceController {
|
||||
async batchControlDevices(
|
||||
@Body() batchControlDevicesDto: BatchControlDevicesDto,
|
||||
) {
|
||||
try {
|
||||
return await this.deviceService.batchControlDevices(
|
||||
batchControlDevicesDto,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
return await this.deviceService.batchControlDevices(batchControlDevicesDto);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -285,14 +179,7 @@ export class DeviceController {
|
||||
async batchStatusDevices(
|
||||
@Query() batchStatusDevicesDto: BatchStatusDevicesDto,
|
||||
) {
|
||||
try {
|
||||
return await this.deviceService.batchStatusDevices(batchStatusDevicesDto);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -300,15 +187,8 @@ export class DeviceController {
|
||||
async batchFactoryResetDevices(
|
||||
@Body() batchFactoryResetDevicesDto: BatchFactoryResetDevicesDto,
|
||||
) {
|
||||
try {
|
||||
return await this.deviceService.batchFactoryResetDevices(
|
||||
batchFactoryResetDevicesDto,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ export class DeviceService {
|
||||
return await this.deviceRepository.findOne({
|
||||
where: {
|
||||
uuid: deviceUuid,
|
||||
isActive: true,
|
||||
},
|
||||
...(withProductDevice && { relations: ['productDevice'] }),
|
||||
});
|
||||
@ -72,6 +73,7 @@ export class DeviceService {
|
||||
return await this.deviceRepository.findOne({
|
||||
where: {
|
||||
deviceTuyaUuid,
|
||||
isActive: true,
|
||||
},
|
||||
relations: ['productDevice'],
|
||||
});
|
||||
@ -128,6 +130,7 @@ export class DeviceService {
|
||||
const devices = await this.deviceRepository.find({
|
||||
where: {
|
||||
user: { uuid: userUuid },
|
||||
isActive: true,
|
||||
permission: {
|
||||
userUuid,
|
||||
permissionType: {
|
||||
@ -174,6 +177,7 @@ export class DeviceService {
|
||||
const devices = await this.deviceRepository.find({
|
||||
where: {
|
||||
spaceDevice: { uuid: getDeviceByRoomUuidDto.roomUuid },
|
||||
isActive: true,
|
||||
permission: {
|
||||
userUuid,
|
||||
permissionType: {
|
||||
@ -223,6 +227,7 @@ export class DeviceService {
|
||||
const device = await this.deviceRepository.findOne({
|
||||
where: {
|
||||
uuid: updateDeviceInRoomDto.deviceUuid,
|
||||
isActive: true,
|
||||
},
|
||||
relations: ['spaceDevice', 'spaceDevice.parent'],
|
||||
});
|
||||
@ -409,7 +414,7 @@ export class DeviceService {
|
||||
}
|
||||
async checkAllDevicesHaveSameProductUuid(deviceUuids: string[]) {
|
||||
const firstDevice = await this.deviceRepository.findOne({
|
||||
where: { uuid: deviceUuids[0] },
|
||||
where: { uuid: deviceUuids[0], isActive: true },
|
||||
relations: ['productDevice'],
|
||||
});
|
||||
|
||||
@ -421,7 +426,7 @@ export class DeviceService {
|
||||
|
||||
for (let i = 1; i < deviceUuids.length; i++) {
|
||||
const device = await this.deviceRepository.findOne({
|
||||
where: { uuid: deviceUuids[i] },
|
||||
where: { uuid: deviceUuids[i], isActive: true },
|
||||
relations: ['productDevice'],
|
||||
});
|
||||
|
||||
@ -465,6 +470,11 @@ export class DeviceService {
|
||||
if (operationResult.success) {
|
||||
// Add to success results if operationResult.success is true
|
||||
successResults.push({ deviceUuid, result: operationResult });
|
||||
// Update isActive to false in the repository for the successfully reset device
|
||||
await this.deviceRepository.update(
|
||||
{ uuid: deviceUuid },
|
||||
{ isActive: false },
|
||||
);
|
||||
} else {
|
||||
// Add to failed results if operationResult.success is false
|
||||
failedResults.push({ deviceUuid, error: operationResult.msg });
|
||||
@ -645,6 +655,7 @@ export class DeviceService {
|
||||
const device = await this.deviceRepository.findOne({
|
||||
where: {
|
||||
uuid: deviceUuid,
|
||||
isActive: true,
|
||||
permission: {
|
||||
userUuid: userUuid,
|
||||
},
|
||||
@ -669,7 +680,10 @@ export class DeviceService {
|
||||
|
||||
const devices = await Promise.all(
|
||||
response.map(async (device: any) => {
|
||||
const deviceDetails = await this.getDeviceByDeviceTuyaUuid(device.id);
|
||||
try {
|
||||
const deviceDetails = await this.getDeviceByDeviceTuyaUuid(
|
||||
device.id,
|
||||
);
|
||||
if (deviceDetails.deviceTuyaUuid) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { id, ...rest } = device;
|
||||
@ -682,6 +696,9 @@ export class DeviceService {
|
||||
};
|
||||
}
|
||||
return null;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
@ -770,6 +787,9 @@ export class DeviceService {
|
||||
parent: {
|
||||
uuid: unitUuid,
|
||||
},
|
||||
devicesSpaceEntity: {
|
||||
isActive: true,
|
||||
},
|
||||
},
|
||||
relations: ['devicesSpaceEntity', 'devicesSpaceEntity.productDevice'],
|
||||
});
|
||||
@ -804,6 +824,7 @@ export class DeviceService {
|
||||
async getAllDevices(): Promise<GetDeviceDetailsInterface[]> {
|
||||
try {
|
||||
const devices = await this.deviceRepository.find({
|
||||
where: { isActive: true },
|
||||
relations: [
|
||||
'spaceDevice.parent',
|
||||
'productDevice',
|
||||
|
@ -4,7 +4,6 @@ import {
|
||||
Controller,
|
||||
Post,
|
||||
Param,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Get,
|
||||
Delete,
|
||||
@ -32,7 +31,6 @@ export class DoorLockController {
|
||||
@Body() addDoorLockDto: AddDoorLockOnlineDto,
|
||||
@Param('doorLockUuid') doorLockUuid: string,
|
||||
) {
|
||||
try {
|
||||
const temporaryPassword =
|
||||
await this.doorLockService.addOnlineTemporaryPassword(
|
||||
addDoorLockDto,
|
||||
@ -47,12 +45,6 @@ export class DoorLockController {
|
||||
id: temporaryPassword.id,
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -60,7 +52,6 @@ export class DoorLockController {
|
||||
async addOfflineOneTimeTemporaryPassword(
|
||||
@Param('doorLockUuid') doorLockUuid: string,
|
||||
) {
|
||||
try {
|
||||
const temporaryPassword =
|
||||
await this.doorLockService.addOfflineOneTimeTemporaryPassword(
|
||||
doorLockUuid,
|
||||
@ -72,12 +63,6 @@ export class DoorLockController {
|
||||
message: 'offline temporary password added successfully',
|
||||
data: temporaryPassword,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -87,7 +72,6 @@ export class DoorLockController {
|
||||
addDoorLockOfflineTempMultipleTimeDto: AddDoorLockOfflineTempMultipleTimeDto,
|
||||
@Param('doorLockUuid') doorLockUuid: string,
|
||||
) {
|
||||
try {
|
||||
const temporaryPassword =
|
||||
await this.doorLockService.addOfflineMultipleTimeTemporaryPassword(
|
||||
addDoorLockOfflineTempMultipleTimeDto,
|
||||
@ -100,12 +84,6 @@ export class DoorLockController {
|
||||
message: 'offline temporary password added successfully',
|
||||
data: temporaryPassword,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -113,16 +91,9 @@ export class DoorLockController {
|
||||
async getOnlineTemporaryPasswords(
|
||||
@Param('doorLockUuid') doorLockUuid: string,
|
||||
) {
|
||||
try {
|
||||
return await this.doorLockService.getOnlineTemporaryPasswordsMultiple(
|
||||
doorLockUuid,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -131,21 +102,11 @@ export class DoorLockController {
|
||||
@Param('doorLockUuid') doorLockUuid: string,
|
||||
@Param('passwordId') passwordId: string,
|
||||
) {
|
||||
try {
|
||||
await this.doorLockService.deleteDoorLockPassword(
|
||||
doorLockUuid,
|
||||
passwordId,
|
||||
);
|
||||
await this.doorLockService.deleteDoorLockPassword(doorLockUuid, passwordId);
|
||||
return {
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'Temporary Password deleted Successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -153,16 +114,9 @@ export class DoorLockController {
|
||||
async getOfflineOneTimeTemporaryPasswords(
|
||||
@Param('doorLockUuid') doorLockUuid: string,
|
||||
) {
|
||||
try {
|
||||
return await this.doorLockService.getOfflineOneTimeTemporaryPasswords(
|
||||
doorLockUuid,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -170,16 +124,9 @@ export class DoorLockController {
|
||||
async getOfflineMultipleTimeTemporaryPasswords(
|
||||
@Param('doorLockUuid') doorLockUuid: string,
|
||||
) {
|
||||
try {
|
||||
return await this.doorLockService.getOfflineMultipleTimeTemporaryPasswords(
|
||||
doorLockUuid,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@ -191,7 +138,6 @@ export class DoorLockController {
|
||||
@Param('doorLockUuid') doorLockUuid: string,
|
||||
@Param('passwordId') passwordId: string,
|
||||
) {
|
||||
try {
|
||||
const temporaryPassword =
|
||||
await this.doorLockService.updateOfflineTemporaryPassword(
|
||||
updateDoorLockOfflineTempDto,
|
||||
@ -205,18 +151,11 @@ export class DoorLockController {
|
||||
message: 'offline temporary password updated successfully',
|
||||
data: temporaryPassword,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('open/:doorLockUuid')
|
||||
async openDoorLock(@Param('doorLockUuid') doorLockUuid: string) {
|
||||
try {
|
||||
await this.doorLockService.openDoorLock(doorLockUuid);
|
||||
|
||||
return {
|
||||
@ -224,11 +163,5 @@ export class DoorLockController {
|
||||
success: true,
|
||||
message: 'door lock opened successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -859,6 +859,7 @@ export class DoorLockService {
|
||||
return await this.deviceRepository.findOne({
|
||||
where: {
|
||||
uuid: deviceUuid,
|
||||
isActive: true,
|
||||
},
|
||||
...(withProductDevice && { relations: ['productDevice'] }),
|
||||
});
|
||||
|
18
src/error-message/error-message.service.spec.ts
Normal file
18
src/error-message/error-message.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { ErrorMessageService } from './error-message.service';
|
||||
|
||||
describe('ErrorMessageService', () => {
|
||||
let service: ErrorMessageService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [ErrorMessageService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<ErrorMessageService>(ErrorMessageService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
40
src/error-message/error-message.service.ts
Normal file
40
src/error-message/error-message.service.ts
Normal file
@ -0,0 +1,40 @@
|
||||
// src/common/services/error-message.service.ts
|
||||
import { Injectable } from '@nestjs/common';
|
||||
type ErrorMessageKey = keyof typeof ErrorMessageService.prototype.messages;
|
||||
|
||||
@Injectable()
|
||||
export class ErrorMessageService {
|
||||
public readonly messages = {
|
||||
NOT_FOUND: '{entity} not found', // Single key for "not found" errors
|
||||
INVALID_MINUTES: 'Invalid minutes value',
|
||||
INVALID_TIME_FORMAT: 'Invalid time format',
|
||||
USER_NOT_FOUND: '{entity} not found', // Can reuse NOT_FOUND if desired
|
||||
INTERNAL_SERVER_ERROR: 'Internal server error',
|
||||
ERROR_ADDING_TEMP_PASSWORD:
|
||||
'Error adding {type} temporary password from Tuya',
|
||||
INVALID_UUID: 'Invalid {entity} UUID',
|
||||
USER_ALREADY_BELONGS: 'This user already belongs to this {entity}',
|
||||
USER_HAS_NO_ENTITIES: 'This user has no {entity}',
|
||||
DEVICE_OPERATION_FAILED: 'All device operations failed',
|
||||
REQUEST_FAILED: 'Error processing {operation} request',
|
||||
COOLDOWN_ERROR:
|
||||
'Please wait {time} more seconds before requesting a new OTP.',
|
||||
};
|
||||
|
||||
getMessage(
|
||||
key: ErrorMessageKey,
|
||||
params?: Record<string, string | number>,
|
||||
): string {
|
||||
let message = this.messages[key] || 'Unknown error';
|
||||
|
||||
// Replace placeholders with provided params
|
||||
if (params) {
|
||||
Object.keys(params).forEach((param) => {
|
||||
const regex = new RegExp(`{${param}}`, 'g');
|
||||
message = message.replace(regex, params[param].toString());
|
||||
});
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Param,
|
||||
Post,
|
||||
@ -35,7 +34,6 @@ export class FloorController {
|
||||
@UseGuards(JwtAuthGuard, CheckBuildingTypeGuard)
|
||||
@Post()
|
||||
async addFloor(@Body() addFloorDto: AddFloorDto) {
|
||||
try {
|
||||
const floor = await this.floorService.addFloor(addFloorDto);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
@ -43,27 +41,14 @@ export class FloorController {
|
||||
message: 'Floor added successfully',
|
||||
data: floor,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, FloorPermissionGuard)
|
||||
@Get(':floorUuid')
|
||||
async getFloorByUuid(@Param('floorUuid') floorUuid: string) {
|
||||
try {
|
||||
const floor = await this.floorService.getFloorByUuid(floorUuid);
|
||||
return floor;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@ -73,85 +58,47 @@ export class FloorController {
|
||||
@Param('floorUuid') floorUuid: string,
|
||||
@Query() query: GetFloorChildDto,
|
||||
) {
|
||||
try {
|
||||
const floor = await this.floorService.getFloorChildByUuid(
|
||||
floorUuid,
|
||||
query,
|
||||
);
|
||||
const floor = await this.floorService.getFloorChildByUuid(floorUuid, query);
|
||||
return floor;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, FloorPermissionGuard)
|
||||
@Get('parent/:floorUuid')
|
||||
async getFloorParentByUuid(@Param('floorUuid') floorUuid: string) {
|
||||
try {
|
||||
const floor = await this.floorService.getFloorParentByUuid(floorUuid);
|
||||
return floor;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(AdminRoleGuard, CheckUserFloorGuard)
|
||||
@Post('user')
|
||||
async addUserFloor(@Body() addUserFloorDto: AddUserFloorDto) {
|
||||
try {
|
||||
await this.floorService.addUserFloor(addUserFloorDto);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'user floor added successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('user/:userUuid')
|
||||
async getFloorsByUserId(@Param('userUuid') userUuid: string) {
|
||||
try {
|
||||
return await this.floorService.getFloorsByUserId(userUuid);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, FloorPermissionGuard)
|
||||
@Put('rename/:floorUuid')
|
||||
@Put(':floorUuid')
|
||||
async renameFloorByUuid(
|
||||
@Param('floorUuid') floorUuid: string,
|
||||
@Body() updateFloorNameDto: UpdateFloorNameDto,
|
||||
) {
|
||||
try {
|
||||
const floor = await this.floorService.renameFloorByUuid(
|
||||
floorUuid,
|
||||
updateFloorNameDto,
|
||||
);
|
||||
return floor;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,5 @@
|
||||
import { GroupService } from '../services/group.service';
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
UseGuards,
|
||||
Param,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Req,
|
||||
} from '@nestjs/common';
|
||||
import { Controller, Get, UseGuards, Param, Req } from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { UnitPermissionGuard } from 'src/guards/unit.permission.guard';
|
||||
@ -25,14 +17,7 @@ export class GroupController {
|
||||
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
|
||||
@Get(':unitUuid')
|
||||
async getGroupsBySpaceUuid(@Param('unitUuid') unitUuid: string) {
|
||||
try {
|
||||
return await this.groupService.getGroupsByUnitUuid(unitUuid);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
|
||||
@ -42,7 +27,6 @@ export class GroupController {
|
||||
@Param('groupName') groupName: string,
|
||||
@Req() req: any,
|
||||
) {
|
||||
try {
|
||||
const userUuid = req.user.uuid;
|
||||
|
||||
return await this.groupService.getUnitDevicesByGroupName(
|
||||
@ -50,11 +34,5 @@ export class GroupController {
|
||||
groupName,
|
||||
userUuid,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
||||
import { ProductRepository } from '@app/common/modules/product/repositories';
|
||||
import { PermissionType } from '@app/common/constants/permission-type.enum';
|
||||
import { In } from 'typeorm';
|
||||
import { ProductType } from '@app/common/constants/product-type.enum';
|
||||
|
||||
@Injectable()
|
||||
export class GroupService {
|
||||
@ -44,8 +45,24 @@ export class GroupService {
|
||||
});
|
||||
|
||||
const uniqueGroupNames = [...new Set(groupNames)];
|
||||
|
||||
return uniqueGroupNames.map((groupName) => ({ groupName }));
|
||||
const groups = uniqueGroupNames.map((groupName) => ({
|
||||
groupName: groupName as ProductType,
|
||||
}));
|
||||
const allowedProductTypes = [
|
||||
ProductType.ONE_1TG,
|
||||
ProductType.TWO_2TG,
|
||||
ProductType.THREE_3TG,
|
||||
ProductType.THREE_G,
|
||||
ProductType.TWO_G,
|
||||
ProductType.ONE_G,
|
||||
ProductType.GD,
|
||||
ProductType.WH,
|
||||
ProductType.AC,
|
||||
ProductType.CUR,
|
||||
];
|
||||
return groups.filter((group) =>
|
||||
allowedProductTypes.includes(group.groupName),
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
'This unit does not have any groups',
|
||||
|
@ -28,7 +28,7 @@ export class CheckProductUuidForAllDevicesGuard implements CanActivate {
|
||||
|
||||
async checkAllDevicesHaveSameProductUuid(deviceUuids: string[]) {
|
||||
const firstDevice = await this.deviceRepository.findOne({
|
||||
where: { uuid: deviceUuids[0] },
|
||||
where: { uuid: deviceUuids[0], isActive: true },
|
||||
relations: ['productDevice'],
|
||||
});
|
||||
|
||||
@ -40,7 +40,7 @@ export class CheckProductUuidForAllDevicesGuard implements CanActivate {
|
||||
|
||||
for (let i = 1; i < deviceUuids.length; i++) {
|
||||
const device = await this.deviceRepository.findOne({
|
||||
where: { uuid: deviceUuids[i] },
|
||||
where: { uuid: deviceUuids[i], isActive: true },
|
||||
relations: ['productDevice'],
|
||||
});
|
||||
|
||||
|
@ -56,6 +56,7 @@ export class CheckRoomGuard implements CanActivate {
|
||||
const response = await this.deviceRepository.findOne({
|
||||
where: {
|
||||
uuid: deviceUuid,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -58,7 +58,11 @@ export class CheckUserHaveControllablePermission implements CanActivate {
|
||||
deviceUuid: string,
|
||||
): Promise<string> {
|
||||
const device = await this.deviceRepository.findOne({
|
||||
where: { uuid: deviceUuid, permission: { userUuid: userUuid } },
|
||||
where: {
|
||||
uuid: deviceUuid,
|
||||
isActive: true,
|
||||
permission: { userUuid: userUuid },
|
||||
},
|
||||
relations: ['permission', 'permission.permissionType'],
|
||||
});
|
||||
|
||||
|
@ -59,7 +59,11 @@ export class CheckUserHavePermission implements CanActivate {
|
||||
deviceUuid: string,
|
||||
): Promise<string> {
|
||||
const device = await this.deviceRepository.findOne({
|
||||
where: { uuid: deviceUuid, permission: { userUuid: userUuid } },
|
||||
where: {
|
||||
uuid: deviceUuid,
|
||||
permission: { userUuid: userUuid },
|
||||
isActive: true,
|
||||
},
|
||||
relations: ['permission', 'permission.permissionType'],
|
||||
});
|
||||
|
||||
|
@ -6,6 +6,7 @@ import { setupSwaggerAuthentication } from '../libs/common/src/util/user-auth.sw
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
import { json, urlencoded } from 'body-parser';
|
||||
import { SeederService } from '@app/common/seed/services/seeder.service';
|
||||
import { HttpExceptionFilter } from './common/filters/http-exception/http-exception.filter';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
@ -15,6 +16,7 @@ async function bootstrap() {
|
||||
// Set the body parser limit to 1 MB
|
||||
app.use(json({ limit: '1mb' }));
|
||||
app.use(urlencoded({ limit: '1mb', extended: true }));
|
||||
app.useGlobalFilters(new HttpExceptionFilter());
|
||||
|
||||
app.use(
|
||||
rateLimit({
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Controller, Get, HttpException, HttpStatus } from '@nestjs/common';
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { RegionService } from '../services/region.service';
|
||||
import { ApiTags, ApiOperation } from '@nestjs/swagger';
|
||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||
@ -18,13 +18,6 @@ export class RegionController {
|
||||
description: ControllerRoute.REGION.ACTIONS.GET_REGIONS_DESCRIPTION,
|
||||
})
|
||||
async getAllRegions() {
|
||||
try {
|
||||
return await this.regionService.getAllRegions();
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,10 @@ import { RegionService } from './services/region.service';
|
||||
import { RegionController } from './controllers/region.controller';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { RegionRepository } from '@app/common/modules/region/repositories';
|
||||
import { CommonModule } from '@app/common';
|
||||
|
||||
@Module({
|
||||
imports: [ConfigModule],
|
||||
imports: [ConfigModule, CommonModule],
|
||||
controllers: [RegionController],
|
||||
providers: [RegionService, RegionRepository],
|
||||
exports: [RegionService],
|
||||
|
@ -2,23 +2,33 @@ import {
|
||||
BadRequestException,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Inject,
|
||||
Injectable,
|
||||
} from '@nestjs/common';
|
||||
import { RegionRepository } from '@app/common/modules/region/repositories';
|
||||
import { ErrorMessageService } from 'src/error-message/error-message.service';
|
||||
|
||||
@Injectable()
|
||||
export class RegionService {
|
||||
constructor(private readonly regionRepository: RegionRepository) {}
|
||||
constructor(
|
||||
private readonly regionRepository: RegionRepository,
|
||||
@Inject(ErrorMessageService)
|
||||
private readonly errorMessageService: ErrorMessageService,
|
||||
) {}
|
||||
async getAllRegions() {
|
||||
try {
|
||||
const regions = await this.regionRepository.find();
|
||||
|
||||
return regions;
|
||||
} catch (err) {
|
||||
if (err instanceof BadRequestException) {
|
||||
throw err; // Re-throw BadRequestException
|
||||
} else {
|
||||
throw new HttpException('Regions found', HttpStatus.NOT_FOUND);
|
||||
throw new HttpException(
|
||||
this.errorMessageService.getMessage('NOT_FOUND', {
|
||||
entity: 'Regions',
|
||||
}),
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Post,
|
||||
UseGuards,
|
||||
@ -24,32 +23,21 @@ export class RoleController {
|
||||
@UseGuards(SuperAdminRoleGuard)
|
||||
@Get('types')
|
||||
async fetchRoleTypes() {
|
||||
try {
|
||||
const roleTypes = await this.roleService.fetchRoleTypes();
|
||||
return {
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'Role Types fetched Successfully',
|
||||
data: roleTypes,
|
||||
};
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(SuperAdminRoleGuard)
|
||||
@Post()
|
||||
async addUserRoleType(@Body() addUserRoleDto: AddUserRoleDto) {
|
||||
try {
|
||||
await this.roleService.addUserRoleType(addUserRoleDto);
|
||||
return {
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'User Role Added Successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Param,
|
||||
Post,
|
||||
@ -33,7 +32,6 @@ export class RoomController {
|
||||
@UseGuards(JwtAuthGuard, CheckUnitTypeGuard)
|
||||
@Post()
|
||||
async addRoom(@Body() addRoomDto: AddRoomDto) {
|
||||
try {
|
||||
const room = await this.roomService.addRoom(addRoomDto);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
@ -41,93 +39,52 @@ export class RoomController {
|
||||
message: 'Room added successfully',
|
||||
data: room,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, RoomPermissionGuard)
|
||||
@Get(':roomUuid')
|
||||
async getRoomByUuid(@Param('roomUuid') roomUuid: string) {
|
||||
try {
|
||||
const room = await this.roomService.getRoomByUuid(roomUuid);
|
||||
return room;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, RoomPermissionGuard)
|
||||
@Get('parent/:roomUuid')
|
||||
async getRoomParentByUuid(@Param('roomUuid') roomUuid: string) {
|
||||
try {
|
||||
const room = await this.roomService.getRoomParentByUuid(roomUuid);
|
||||
return room;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(AdminRoleGuard, CheckUserRoomGuard)
|
||||
@Post('user')
|
||||
async addUserRoom(@Body() addUserRoomDto: AddUserRoomDto) {
|
||||
try {
|
||||
await this.roomService.addUserRoom(addUserRoomDto);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'user room added successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('user/:userUuid')
|
||||
async getRoomsByUserId(@Param('userUuid') userUuid: string) {
|
||||
try {
|
||||
return await this.roomService.getRoomsByUserId(userUuid);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, RoomPermissionGuard)
|
||||
@Put('rename/:roomUuid')
|
||||
@Put(':roomUuid')
|
||||
async renameRoomByUuid(
|
||||
@Param('roomUuid') roomUuid: string,
|
||||
@Body() updateRoomNameDto: UpdateRoomNameDto,
|
||||
) {
|
||||
try {
|
||||
const room = await this.roomService.renameRoomByUuid(
|
||||
roomUuid,
|
||||
updateRoomNameDto,
|
||||
);
|
||||
return room;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import {
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Param,
|
||||
Post,
|
||||
@ -28,7 +27,6 @@ export class SceneController {
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('tap-to-run')
|
||||
async addTapToRunScene(@Body() addSceneTapToRunDto: AddSceneTapToRunDto) {
|
||||
try {
|
||||
const tapToRunScene =
|
||||
await this.sceneService.addTapToRunScene(addSceneTapToRunDto);
|
||||
return {
|
||||
@ -37,27 +35,14 @@ export class SceneController {
|
||||
message: 'Scene added successfully',
|
||||
data: tapToRunScene,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('tap-to-run/:unitUuid')
|
||||
async getTapToRunSceneByUnit(@Param('unitUuid') unitUuid: string) {
|
||||
try {
|
||||
const tapToRunScenes =
|
||||
await this.sceneService.getTapToRunSceneByUnit(unitUuid);
|
||||
return tapToRunScenes;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -66,53 +51,31 @@ export class SceneController {
|
||||
@Param('unitUuid') unitUuid: string,
|
||||
@Param('sceneId') sceneId: string,
|
||||
) {
|
||||
try {
|
||||
await this.sceneService.deleteTapToRunScene(unitUuid, sceneId);
|
||||
return {
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'Scene Deleted Successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('tap-to-run/trigger/:sceneId')
|
||||
async triggerTapToRunScene(@Param('sceneId') sceneId: string) {
|
||||
try {
|
||||
await this.sceneService.triggerTapToRunScene(sceneId);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'Scene trigger successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('tap-to-run/details/:sceneId')
|
||||
async getTapToRunSceneDetails(@Param('sceneId') sceneId: string) {
|
||||
try {
|
||||
const tapToRunScenes =
|
||||
await this.sceneService.getTapToRunSceneDetails(sceneId);
|
||||
return tapToRunScenes;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
``;
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -121,7 +84,6 @@ export class SceneController {
|
||||
@Body() updateSceneTapToRunDto: UpdateSceneTapToRunDto,
|
||||
@Param('sceneId') sceneId: string,
|
||||
) {
|
||||
try {
|
||||
const tapToRunScene = await this.sceneService.updateTapToRunScene(
|
||||
updateSceneTapToRunDto,
|
||||
sceneId,
|
||||
@ -132,11 +94,5 @@ export class SceneController {
|
||||
message: 'Scene updated successfully',
|
||||
data: tapToRunScene,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import {
|
||||
Get,
|
||||
Post,
|
||||
Param,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
UseGuards,
|
||||
Put,
|
||||
@ -37,7 +36,6 @@ export class ScheduleController {
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Body() addScheduleDto: AddScheduleDto,
|
||||
) {
|
||||
try {
|
||||
const schedule = await this.scheduleService.addDeviceSchedule(
|
||||
deviceUuid,
|
||||
addScheduleDto,
|
||||
@ -49,12 +47,6 @@ export class ScheduleController {
|
||||
message: 'schedule added successfully',
|
||||
data: schedule,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -63,17 +55,10 @@ export class ScheduleController {
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Query() query: GetScheduleDeviceDto,
|
||||
) {
|
||||
try {
|
||||
return await this.scheduleService.getDeviceScheduleByCategory(
|
||||
deviceUuid,
|
||||
query.category,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -82,19 +67,12 @@ export class ScheduleController {
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Param('scheduleId') scheduleId: string,
|
||||
) {
|
||||
try {
|
||||
await this.scheduleService.deleteDeviceSchedule(deviceUuid, scheduleId);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'schedule deleted successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -103,7 +81,6 @@ export class ScheduleController {
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Body() enableScheduleDto: EnableScheduleDto,
|
||||
) {
|
||||
try {
|
||||
await this.scheduleService.enableDeviceSchedule(
|
||||
deviceUuid,
|
||||
enableScheduleDto,
|
||||
@ -113,12 +90,6 @@ export class ScheduleController {
|
||||
success: true,
|
||||
message: 'schedule updated successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -127,7 +98,6 @@ export class ScheduleController {
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Body() updateScheduleDto: UpdateScheduleDto,
|
||||
) {
|
||||
try {
|
||||
const schedule = await this.scheduleService.updateDeviceSchedule(
|
||||
deviceUuid,
|
||||
updateScheduleDto,
|
||||
@ -139,11 +109,5 @@ export class ScheduleController {
|
||||
message: 'schedule updated successfully',
|
||||
data: schedule,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,8 @@ export class ScheduleService {
|
||||
deviceDetails.productDevice.prodType !== ProductType.WH &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.ONE_1TG &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.TWO_2TG &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG
|
||||
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.GD
|
||||
) {
|
||||
throw new HttpException(
|
||||
'This device is not supported for schedule',
|
||||
@ -113,7 +114,8 @@ export class ScheduleService {
|
||||
deviceDetails.productDevice.prodType !== ProductType.WH &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.ONE_1TG &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.TWO_2TG &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG
|
||||
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.GD
|
||||
) {
|
||||
throw new HttpException(
|
||||
'This device is not supported for schedule',
|
||||
@ -166,7 +168,8 @@ export class ScheduleService {
|
||||
deviceDetails.productDevice.prodType !== ProductType.WH &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.ONE_1TG &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.TWO_2TG &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG
|
||||
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.GD
|
||||
) {
|
||||
throw new HttpException(
|
||||
'This device is not supported for schedule',
|
||||
@ -233,7 +236,8 @@ export class ScheduleService {
|
||||
deviceDetails.productDevice.prodType !== ProductType.WH &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.ONE_1TG &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.TWO_2TG &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG
|
||||
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.GD
|
||||
) {
|
||||
throw new HttpException(
|
||||
'This device is not supported for schedule',
|
||||
@ -294,6 +298,7 @@ export class ScheduleService {
|
||||
return await this.deviceRepository.findOne({
|
||||
where: {
|
||||
uuid: deviceUuid,
|
||||
isActive: true,
|
||||
},
|
||||
...(withProductDevice && { relations: ['productDevice'] }),
|
||||
});
|
||||
@ -317,7 +322,8 @@ export class ScheduleService {
|
||||
deviceDetails.productDevice.prodType !== ProductType.WH &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.ONE_1TG &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.TWO_2TG &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG
|
||||
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.GD
|
||||
) {
|
||||
throw new HttpException(
|
||||
'This device is not supported for schedule',
|
||||
|
@ -1,10 +1,4 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { Controller, Get, UseGuards } from '@nestjs/common';
|
||||
import { TimeZoneService } from '../services/timezone.service';
|
||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard';
|
||||
@ -22,13 +16,6 @@ export class TimeZoneController {
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get()
|
||||
async getAllTimeZones() {
|
||||
try {
|
||||
return await this.timeZoneService.getAllTimeZones();
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Param,
|
||||
Post,
|
||||
@ -38,7 +37,6 @@ export class UnitController {
|
||||
@UseGuards(JwtAuthGuard, CheckFloorTypeGuard)
|
||||
@Post()
|
||||
async addUnit(@Body() addUnitDto: AddUnitDto) {
|
||||
try {
|
||||
const unit = await this.unitService.addUnit(addUnitDto);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
@ -46,27 +44,14 @@ export class UnitController {
|
||||
message: 'Unit added successfully',
|
||||
data: unit,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
|
||||
@Get(':unitUuid')
|
||||
async getUnitByUuid(@Param('unitUuid') unitUuid: string) {
|
||||
try {
|
||||
const unit = await this.unitService.getUnitByUuid(unitUuid);
|
||||
return unit;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@ -76,95 +61,53 @@ export class UnitController {
|
||||
@Param('unitUuid') unitUuid: string,
|
||||
@Query() query: GetUnitChildDto,
|
||||
) {
|
||||
try {
|
||||
const unit = await this.unitService.getUnitChildByUuid(unitUuid, query);
|
||||
return unit;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
|
||||
@Get('parent/:unitUuid')
|
||||
async getUnitParentByUuid(@Param('unitUuid') unitUuid: string) {
|
||||
try {
|
||||
const unit = await this.unitService.getUnitParentByUuid(unitUuid);
|
||||
return unit;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, CheckUserUnitGuard)
|
||||
@Post('user')
|
||||
async addUserUnit(@Body() addUserUnitDto: AddUserUnitDto) {
|
||||
try {
|
||||
await this.unitService.addUserUnit(addUserUnitDto);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'user unit added successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('user/:userUuid')
|
||||
async getUnitsByUserId(@Param('userUuid') userUuid: string) {
|
||||
try {
|
||||
return await this.unitService.getUnitsByUserId(userUuid);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
|
||||
@Put('rename/:unitUuid')
|
||||
@Put(':unitUuid')
|
||||
async renameUnitByUuid(
|
||||
@Param('unitUuid') unitUuid: string,
|
||||
@Body() updateUnitNameDto: UpdateUnitNameDto,
|
||||
) {
|
||||
try {
|
||||
const unit = await this.unitService.renameUnitByUuid(
|
||||
unitUuid,
|
||||
updateUnitNameDto,
|
||||
);
|
||||
return unit;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
|
||||
@Get(':unitUuid/invitation-code')
|
||||
async getUnitInvitationCode(@Param('unitUuid') unitUuid: string) {
|
||||
try {
|
||||
const unit = await this.unitService.getUnitInvitationCode(unitUuid);
|
||||
return unit;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@ -173,18 +116,11 @@ export class UnitController {
|
||||
async verifyCodeAndAddUserUnit(
|
||||
@Body() addUserUnitUsingCodeDto: AddUserUnitUsingCodeDto,
|
||||
) {
|
||||
try {
|
||||
await this.unitService.verifyCodeAndAddUserUnit(addUserUnitUsingCodeDto);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'user unit added successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ import {
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Param,
|
||||
Post,
|
||||
@ -29,13 +28,11 @@ export class UserDevicePermissionController {
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(AdminRoleGuard)
|
||||
@Post('add')
|
||||
@Post()
|
||||
async addDevicePermission(
|
||||
@Body() userDevicePermissionDto: UserDevicePermissionAddDto,
|
||||
) {
|
||||
try {
|
||||
const addDetails =
|
||||
await this.userDevicePermissionService.addUserPermission(
|
||||
const addDetails = await this.userDevicePermissionService.addUserPermission(
|
||||
userDevicePermissionDto,
|
||||
);
|
||||
return {
|
||||
@ -43,22 +40,15 @@ export class UserDevicePermissionController {
|
||||
message: 'User Permission for Devices Added Successfully',
|
||||
data: addDetails,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(AdminRoleGuard)
|
||||
@Put('edit/:devicePermissionUuid')
|
||||
@Put(':devicePermissionUuid')
|
||||
async editDevicePermission(
|
||||
@Param('devicePermissionUuid') devicePermissionUuid: string,
|
||||
@Body() userDevicePermissionEditDto: UserDevicePermissionEditDto,
|
||||
) {
|
||||
try {
|
||||
await this.userDevicePermissionService.editUserPermission(
|
||||
devicePermissionUuid,
|
||||
userDevicePermissionEditDto,
|
||||
@ -67,19 +57,12 @@ export class UserDevicePermissionController {
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'User Permission for Devices Updated Successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(AdminRoleGuard)
|
||||
@Get(':deviceUuid/list')
|
||||
@Get(':deviceUuid')
|
||||
async fetchDevicePermission(@Param('deviceUuid') deviceUuid: string) {
|
||||
try {
|
||||
const deviceDetails =
|
||||
await this.userDevicePermissionService.fetchUserPermission(deviceUuid);
|
||||
return {
|
||||
@ -87,9 +70,6 @@ export class UserDevicePermissionController {
|
||||
message: 'Device Details fetched Successfully',
|
||||
data: deviceDetails,
|
||||
};
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(AdminRoleGuard)
|
||||
@ -97,7 +77,6 @@ export class UserDevicePermissionController {
|
||||
async deleteDevicePermission(
|
||||
@Param('devicePermissionUuid') devicePermissionUuid: string,
|
||||
) {
|
||||
try {
|
||||
await this.userDevicePermissionService.deleteDevicePermission(
|
||||
devicePermissionUuid,
|
||||
);
|
||||
@ -105,11 +84,5 @@ export class UserDevicePermissionController {
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'User Permission for Devices Deleted Successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Param,
|
||||
Post,
|
||||
@ -35,7 +34,6 @@ export class UserNotificationController {
|
||||
async addUserSubscription(
|
||||
@Body() userNotificationAddDto: UserNotificationAddDto,
|
||||
) {
|
||||
try {
|
||||
const addDetails = await this.userNotificationService.addUserSubscription(
|
||||
userNotificationAddDto,
|
||||
);
|
||||
@ -44,19 +42,12 @@ export class UserNotificationController {
|
||||
message: 'User Notification Added Successfully',
|
||||
data: addDetails,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get(':userUuid')
|
||||
async fetchUserSubscriptions(@Param('userUuid') userUuid: string) {
|
||||
try {
|
||||
const userDetails =
|
||||
await this.userNotificationService.fetchUserSubscriptions(userUuid);
|
||||
return {
|
||||
@ -64,12 +55,6 @@ export class UserNotificationController {
|
||||
message: 'User Notification fetched Successfully',
|
||||
data: { ...userDetails },
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -77,7 +62,6 @@ export class UserNotificationController {
|
||||
async updateUserSubscription(
|
||||
@Body() userNotificationUpdateDto: UserNotificationUpdateDto,
|
||||
) {
|
||||
try {
|
||||
await this.userNotificationService.updateUserSubscription(
|
||||
userNotificationUpdateDto,
|
||||
);
|
||||
@ -85,11 +69,5 @@ export class UserNotificationController {
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'User subscription updated Successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ import {
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Param,
|
||||
Put,
|
||||
@ -34,14 +33,7 @@ export class UserController {
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get(':userUuid')
|
||||
async getUserDetailsByUserUuid(@Param('userUuid') userUuid: string) {
|
||||
try {
|
||||
return await this.userService.getUserDetailsByUserUuid(userUuid);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, CheckProfilePictureGuard)
|
||||
@ -50,7 +42,6 @@ export class UserController {
|
||||
@Param('userUuid') userUuid: string,
|
||||
@Body() updateProfilePictureDataDto: UpdateProfilePictureDataDto,
|
||||
) {
|
||||
try {
|
||||
const userData = await this.userService.updateProfilePictureByUserUuid(
|
||||
userUuid,
|
||||
updateProfilePictureDataDto,
|
||||
@ -61,12 +52,6 @@ export class UserController {
|
||||
message: 'profile picture updated successfully',
|
||||
data: userData,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -75,7 +60,6 @@ export class UserController {
|
||||
@Param('userUuid') userUuid: string,
|
||||
@Body() updateRegionDataDto: UpdateRegionDataDto,
|
||||
) {
|
||||
try {
|
||||
const userData = await this.userService.updateRegionByUserUuid(
|
||||
userUuid,
|
||||
updateRegionDataDto,
|
||||
@ -86,12 +70,6 @@ export class UserController {
|
||||
message: 'region updated successfully',
|
||||
data: userData,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -100,7 +78,6 @@ export class UserController {
|
||||
@Param('userUuid') userUuid: string,
|
||||
@Body() updateTimezoneDataDto: UpdateTimezoneDataDto,
|
||||
) {
|
||||
try {
|
||||
const userData = await this.userService.updateTimezoneByUserUuid(
|
||||
userUuid,
|
||||
updateTimezoneDataDto,
|
||||
@ -111,12 +88,6 @@ export class UserController {
|
||||
message: 'timezone updated successfully',
|
||||
data: userData,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -125,7 +96,6 @@ export class UserController {
|
||||
@Param('userUuid') userUuid: string,
|
||||
@Body() updateNameDto: UpdateNameDto,
|
||||
) {
|
||||
try {
|
||||
const userData = await this.userService.updateNameByUserUuid(
|
||||
userUuid,
|
||||
updateNameDto,
|
||||
@ -136,12 +106,6 @@ export class UserController {
|
||||
message: 'name updated successfully',
|
||||
data: userData,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(SuperAdminRoleGuard)
|
||||
|
@ -3,7 +3,6 @@ import {
|
||||
Body,
|
||||
Controller,
|
||||
Post,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
UseGuards,
|
||||
Get,
|
||||
@ -35,7 +34,6 @@ export class VisitorPasswordController {
|
||||
@Body() addDoorLockOnlineMultipleDto: AddDoorLockOnlineMultipleDto,
|
||||
@Req() req: any,
|
||||
) {
|
||||
try {
|
||||
const userUuid = req.user.uuid;
|
||||
const temporaryPasswords =
|
||||
await this.visitorPasswordService.addOnlineTemporaryPasswordMultipleTime(
|
||||
@ -47,12 +45,6 @@ export class VisitorPasswordController {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
data: temporaryPasswords,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -61,7 +53,6 @@ export class VisitorPasswordController {
|
||||
@Body() addDoorLockOnlineOneTimeDto: AddDoorLockOnlineOneTimeDto,
|
||||
@Req() req: any,
|
||||
) {
|
||||
try {
|
||||
const userUuid = req.user.uuid;
|
||||
const temporaryPasswords =
|
||||
await this.visitorPasswordService.addOnlineTemporaryPasswordOneTime(
|
||||
@ -73,12 +64,6 @@ export class VisitorPasswordController {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
data: temporaryPasswords,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -87,7 +72,6 @@ export class VisitorPasswordController {
|
||||
@Body() addDoorLockOfflineOneTimeDto: AddDoorLockOfflineOneTimeDto,
|
||||
@Req() req: any,
|
||||
) {
|
||||
try {
|
||||
const userUuid = req.user.uuid;
|
||||
const temporaryPassword =
|
||||
await this.visitorPasswordService.addOfflineOneTimeTemporaryPassword(
|
||||
@ -99,12 +83,6 @@ export class VisitorPasswordController {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
data: temporaryPassword,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -114,7 +92,6 @@ export class VisitorPasswordController {
|
||||
addDoorLockOfflineMultipleDto: AddDoorLockOfflineMultipleDto,
|
||||
@Req() req: any,
|
||||
) {
|
||||
try {
|
||||
const userUuid = req.user.uuid;
|
||||
const temporaryPassword =
|
||||
await this.visitorPasswordService.addOfflineMultipleTimeTemporaryPassword(
|
||||
@ -126,37 +103,17 @@ export class VisitorPasswordController {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
data: temporaryPassword,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get()
|
||||
async GetVisitorPassword() {
|
||||
try {
|
||||
return await this.visitorPasswordService.getPasswords();
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('/devices')
|
||||
async GetVisitorDevices() {
|
||||
try {
|
||||
return await this.visitorPasswordService.getAllPassDevices();
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -450,6 +450,7 @@ export class VisitorPasswordService {
|
||||
productDevice: {
|
||||
prodType: ProductType.DL,
|
||||
},
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
const data = [];
|
||||
@ -492,6 +493,7 @@ export class VisitorPasswordService {
|
||||
productDevice: {
|
||||
prodType: ProductType.DL,
|
||||
},
|
||||
isActive: true,
|
||||
},
|
||||
relations: ['productDevice'],
|
||||
});
|
||||
@ -857,6 +859,7 @@ export class VisitorPasswordService {
|
||||
return await this.deviceRepository.findOne({
|
||||
where: {
|
||||
uuid: deviceUuid,
|
||||
isActive: true,
|
||||
},
|
||||
...(withProductDevice && { relations: ['productDevice'] }),
|
||||
});
|
||||
|
Reference in New Issue
Block a user