mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 07:07:21 +00:00
Compare commits
4 Commits
5cf45c30f4
...
09322c5b80
Author | SHA1 | Date | |
---|---|---|---|
09322c5b80 | |||
74d3620d0e | |||
83be80d9f6 | |||
2589e391ed |
@ -1,5 +1,6 @@
|
|||||||
import { PlatformType } from '@app/common/constants/platform-type.enum';
|
import { PlatformType } from '@app/common/constants/platform-type.enum';
|
||||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||||
|
import { UserEntity } from '@app/common/modules/user/entities';
|
||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
Injectable,
|
Injectable,
|
||||||
@ -32,7 +33,7 @@ export class AuthService {
|
|||||||
pass: string,
|
pass: string,
|
||||||
regionUuid?: string,
|
regionUuid?: string,
|
||||||
platform?: PlatformType,
|
platform?: PlatformType,
|
||||||
): Promise<any> {
|
): Promise<Omit<UserEntity, 'password'>> {
|
||||||
const user = await this.userRepository.findOne({
|
const user = await this.userRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
email,
|
email,
|
||||||
@ -70,8 +71,9 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const { password, ...result } = user;
|
// const { password, ...result } = user;
|
||||||
return result;
|
delete user.password;
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createSession(data): Promise<UserSessionEntity> {
|
async createSession(data): Promise<UserSessionEntity> {
|
||||||
@ -114,6 +116,7 @@ export class AuthService {
|
|||||||
hasAcceptedWebAgreement: user.hasAcceptedWebAgreement,
|
hasAcceptedWebAgreement: user.hasAcceptedWebAgreement,
|
||||||
hasAcceptedAppAgreement: user.hasAcceptedAppAgreement,
|
hasAcceptedAppAgreement: user.hasAcceptedAppAgreement,
|
||||||
project: user?.project,
|
project: user?.project,
|
||||||
|
bookingPoints: user?.bookingPoints,
|
||||||
};
|
};
|
||||||
if (payload.googleCode) {
|
if (payload.googleCode) {
|
||||||
const profile = await this.getProfile(payload.googleCode);
|
const profile = await this.getProfile(payload.googleCode);
|
||||||
|
@ -220,6 +220,11 @@ export class ControllerRoute {
|
|||||||
public static readonly UPDATE_SPACE_DESCRIPTION =
|
public static readonly UPDATE_SPACE_DESCRIPTION =
|
||||||
'Updates a space by its UUID and community ID. You can update the name, parent space, and other properties. If a parent space is provided and not already a parent, its `isParent` flag will be set to true.';
|
'Updates a space by its UUID and community ID. You can update the name, parent space, and other properties. If a parent space is provided and not already a parent, its `isParent` flag will be set to true.';
|
||||||
|
|
||||||
|
public static readonly UPDATE_CHILDREN_SPACES_ORDER_OF_A_SPACE_SUMMARY =
|
||||||
|
'Update the order of child spaces under a specific parent space';
|
||||||
|
public static readonly UPDATE_CHILDREN_SPACES_ORDER_OF_A_SPACE_DESCRIPTION =
|
||||||
|
'Updates the order of child spaces under a specific parent space. You can provide a new order for the child spaces.';
|
||||||
|
|
||||||
public static readonly GET_HEIRARCHY_SUMMARY = 'Get space hierarchy';
|
public static readonly GET_HEIRARCHY_SUMMARY = 'Get space hierarchy';
|
||||||
public static readonly GET_HEIRARCHY_DESCRIPTION =
|
public static readonly GET_HEIRARCHY_DESCRIPTION =
|
||||||
'This endpoint retrieves the hierarchical structure of spaces under a given space ID. It returns all the child spaces nested within the specified space, organized by their parent-child relationships. ';
|
'This endpoint retrieves the hierarchical structure of spaces under a given space ID. It returns all the child spaces nested within the specified space, organized by their parent-child relationships. ';
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
|
||||||
|
|
||||||
export class SpaceLinkEntity extends AbstractEntity {}
|
|
@ -6,9 +6,9 @@ import {
|
|||||||
OneToMany,
|
OneToMany,
|
||||||
OneToOne,
|
OneToOne,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
import { SpaceDto } from '../dtos';
|
|
||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
import { AqiSpaceDailyPollutantStatsEntity } from '../../aqi/entities';
|
import { AqiSpaceDailyPollutantStatsEntity } from '../../aqi/entities';
|
||||||
|
import { BookableSpaceEntity } from '../../booking/entities';
|
||||||
import { CommunityEntity } from '../../community/entities';
|
import { CommunityEntity } from '../../community/entities';
|
||||||
import { DeviceEntity } from '../../device/entities';
|
import { DeviceEntity } from '../../device/entities';
|
||||||
import { InviteUserSpaceEntity } from '../../Invite-user/entities';
|
import { InviteUserSpaceEntity } from '../../Invite-user/entities';
|
||||||
@ -17,9 +17,9 @@ import { PresenceSensorDailySpaceEntity } from '../../presence-sensor/entities';
|
|||||||
import { SceneEntity } from '../../scene/entities';
|
import { SceneEntity } from '../../scene/entities';
|
||||||
import { SpaceModelEntity } from '../../space-model';
|
import { SpaceModelEntity } from '../../space-model';
|
||||||
import { UserSpaceEntity } from '../../user/entities';
|
import { UserSpaceEntity } from '../../user/entities';
|
||||||
|
import { SpaceDto } from '../dtos';
|
||||||
import { SpaceProductAllocationEntity } from './space-product-allocation.entity';
|
import { SpaceProductAllocationEntity } from './space-product-allocation.entity';
|
||||||
import { SubspaceEntity } from './subspace/subspace.entity';
|
import { SubspaceEntity } from './subspace/subspace.entity';
|
||||||
import { BookableSpaceEntity } from '../../booking/entities';
|
|
||||||
|
|
||||||
@Entity({ name: 'space' })
|
@Entity({ name: 'space' })
|
||||||
export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
||||||
@ -64,6 +64,12 @@ export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
|||||||
})
|
})
|
||||||
public disabled: boolean;
|
public disabled: boolean;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
type: Number,
|
||||||
|
})
|
||||||
|
public order?: number;
|
||||||
|
|
||||||
@OneToMany(() => SubspaceEntity, (subspace) => subspace.space, {
|
@OneToMany(() => SubspaceEntity, (subspace) => subspace.space, {
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
|
@ -11,9 +11,6 @@ export class SpaceRepository extends Repository<SpaceEntity> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class SpaceLinkRepository {}
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class InviteSpaceRepository extends Repository<InviteSpaceEntity> {
|
export class InviteSpaceRepository extends Repository<InviteSpaceEntity> {
|
||||||
constructor(private dataSource: DataSource) {
|
constructor(private dataSource: DataSource) {
|
||||||
|
@ -82,6 +82,12 @@ export class UserEntity extends AbstractEntity<UserDto> {
|
|||||||
})
|
})
|
||||||
public isActive: boolean;
|
public isActive: boolean;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
type: Number,
|
||||||
|
})
|
||||||
|
public bookingPoints?: number;
|
||||||
|
|
||||||
@Column({ default: false })
|
@Column({ default: false })
|
||||||
hasAcceptedWebAgreement: boolean;
|
hasAcceptedWebAgreement: boolean;
|
||||||
|
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
import { UserRepository } from '../../../libs/common/src/modules/user/repositories';
|
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||||
|
import { differenceInSeconds } from '@app/common/helper/differenceInSeconds';
|
||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
ForbiddenException,
|
ForbiddenException,
|
||||||
Injectable,
|
Injectable,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { UserSignUpDto } from '../dtos/user-auth.dto';
|
|
||||||
import { HelperHashService } from '../../../libs/common/src/helper/services';
|
|
||||||
import { UserLoginDto } from '../dtos/user-login.dto';
|
|
||||||
import { AuthService } from '../../../libs/common/src/auth/services/auth.service';
|
|
||||||
import { UserSessionRepository } from '../../../libs/common/src/modules/session/repositories/session.repository';
|
|
||||||
import { UserOtpRepository } from '../../../libs/common/src/modules/user/repositories/user.repository';
|
|
||||||
import { ForgetPasswordDto, UserOtpDto, VerifyOtpDto } from '../dtos';
|
|
||||||
import { EmailService } from '../../../libs/common/src/util/email.service';
|
|
||||||
import { OtpType } from '../../../libs/common/src/constants/otp-type.enum';
|
|
||||||
import { UserEntity } from '../../../libs/common/src/modules/user/entities/user.entity';
|
|
||||||
import * as argon2 from 'argon2';
|
|
||||||
import { differenceInSeconds } from '@app/common/helper/differenceInSeconds';
|
|
||||||
import { LessThan, MoreThan } from 'typeorm';
|
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
import * as argon2 from 'argon2';
|
||||||
import { RoleService } from 'src/role/services';
|
import { RoleService } from 'src/role/services';
|
||||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
import { LessThan, MoreThan } from 'typeorm';
|
||||||
|
import { AuthService } from '../../../libs/common/src/auth/services/auth.service';
|
||||||
|
import { OtpType } from '../../../libs/common/src/constants/otp-type.enum';
|
||||||
|
import { HelperHashService } from '../../../libs/common/src/helper/services';
|
||||||
|
import { UserSessionRepository } from '../../../libs/common/src/modules/session/repositories/session.repository';
|
||||||
|
import { UserEntity } from '../../../libs/common/src/modules/user/entities/user.entity';
|
||||||
|
import { UserRepository } from '../../../libs/common/src/modules/user/repositories';
|
||||||
|
import { UserOtpRepository } from '../../../libs/common/src/modules/user/repositories/user.repository';
|
||||||
|
import { EmailService } from '../../../libs/common/src/util/email.service';
|
||||||
|
import { ForgetPasswordDto, UserOtpDto, VerifyOtpDto } from '../dtos';
|
||||||
|
import { UserSignUpDto } from '../dtos/user-auth.dto';
|
||||||
|
import { UserLoginDto } from '../dtos/user-login.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserAuthService {
|
export class UserAuthService {
|
||||||
@ -108,7 +108,7 @@ export class UserAuthService {
|
|||||||
|
|
||||||
async userLogin(data: UserLoginDto) {
|
async userLogin(data: UserLoginDto) {
|
||||||
try {
|
try {
|
||||||
let user;
|
let user: Omit<UserEntity, 'password'>;
|
||||||
if (data.googleCode) {
|
if (data.googleCode) {
|
||||||
const googleUserData = await this.authService.login({
|
const googleUserData = await this.authService.login({
|
||||||
googleCode: data.googleCode,
|
googleCode: data.googleCode,
|
||||||
@ -145,7 +145,7 @@ export class UserAuthService {
|
|||||||
}
|
}
|
||||||
const session = await Promise.all([
|
const session = await Promise.all([
|
||||||
await this.sessionRepository.update(
|
await this.sessionRepository.update(
|
||||||
{ userId: user.id },
|
{ userId: user?.['id'] },
|
||||||
{
|
{
|
||||||
isLoggedOut: true,
|
isLoggedOut: true,
|
||||||
},
|
},
|
||||||
@ -166,6 +166,7 @@ export class UserAuthService {
|
|||||||
hasAcceptedAppAgreement: user.hasAcceptedAppAgreement,
|
hasAcceptedAppAgreement: user.hasAcceptedAppAgreement,
|
||||||
project: user.project,
|
project: user.project,
|
||||||
sessionId: session[1].uuid,
|
sessionId: session[1].uuid,
|
||||||
|
bookingPoints: user.bookingPoints,
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -347,6 +348,7 @@ export class UserAuthService {
|
|||||||
userId: user.uuid,
|
userId: user.uuid,
|
||||||
uuid: user.uuid,
|
uuid: user.uuid,
|
||||||
type,
|
type,
|
||||||
|
bookingPoints: user.bookingPoints,
|
||||||
sessionId,
|
sessionId,
|
||||||
});
|
});
|
||||||
await this.authService.updateRefreshToken(user.uuid, tokens.refreshToken);
|
await this.authService.updateRefreshToken(user.uuid, tokens.refreshToken);
|
||||||
|
@ -5,7 +5,6 @@ import { ConfigModule } from '@nestjs/config';
|
|||||||
import { SpaceRepositoryModule } from '@app/common/modules/space/space.repository.module';
|
import { SpaceRepositoryModule } from '@app/common/modules/space/space.repository.module';
|
||||||
import {
|
import {
|
||||||
InviteSpaceRepository,
|
InviteSpaceRepository,
|
||||||
SpaceLinkRepository,
|
|
||||||
SpaceProductAllocationRepository,
|
SpaceProductAllocationRepository,
|
||||||
SpaceRepository,
|
SpaceRepository,
|
||||||
} from '@app/common/modules/space/repositories';
|
} from '@app/common/modules/space/repositories';
|
||||||
@ -16,14 +15,12 @@ import { CommunityRepository } from '@app/common/modules/community/repositories'
|
|||||||
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
||||||
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||||
import {
|
import {
|
||||||
SpaceLinkService,
|
|
||||||
SpaceService,
|
SpaceService,
|
||||||
SubspaceDeviceService,
|
SubspaceDeviceService,
|
||||||
SubSpaceService,
|
SubSpaceService,
|
||||||
ValidationService,
|
ValidationService,
|
||||||
} from 'src/space/services';
|
} from 'src/space/services';
|
||||||
import { TagService as NewTagService } from 'src/tags/services';
|
import { TagService as NewTagService } from 'src/tags/services';
|
||||||
import { TagService } from 'src/space/services/tag';
|
|
||||||
import {
|
import {
|
||||||
SpaceModelService,
|
SpaceModelService,
|
||||||
SubSpaceModelService,
|
SubSpaceModelService,
|
||||||
@ -81,16 +78,13 @@ import { AqiSpaceDailyPollutantStatsRepository } from '@app/common/modules/aqi/r
|
|||||||
SpaceService,
|
SpaceService,
|
||||||
InviteSpaceRepository,
|
InviteSpaceRepository,
|
||||||
// Todo: find out why this is needed
|
// Todo: find out why this is needed
|
||||||
SpaceLinkService,
|
|
||||||
SubSpaceService,
|
SubSpaceService,
|
||||||
ValidationService,
|
ValidationService,
|
||||||
NewTagService,
|
NewTagService,
|
||||||
SpaceModelService,
|
SpaceModelService,
|
||||||
SpaceProductAllocationService,
|
SpaceProductAllocationService,
|
||||||
SpaceLinkRepository,
|
|
||||||
SubspaceRepository,
|
SubspaceRepository,
|
||||||
// Todo: find out why this is needed
|
// Todo: find out why this is needed
|
||||||
TagService,
|
|
||||||
SubspaceDeviceService,
|
SubspaceDeviceService,
|
||||||
SubspaceProductAllocationService,
|
SubspaceProductAllocationService,
|
||||||
SpaceModelRepository,
|
SpaceModelRepository,
|
||||||
|
@ -38,7 +38,6 @@ import {
|
|||||||
} from '@app/common/modules/scene/repositories';
|
} from '@app/common/modules/scene/repositories';
|
||||||
import {
|
import {
|
||||||
InviteSpaceRepository,
|
InviteSpaceRepository,
|
||||||
SpaceLinkRepository,
|
|
||||||
SpaceProductAllocationRepository,
|
SpaceProductAllocationRepository,
|
||||||
SpaceRepository,
|
SpaceRepository,
|
||||||
} from '@app/common/modules/space';
|
} from '@app/common/modules/space';
|
||||||
@ -121,7 +120,6 @@ import { AqiSpaceDailyPollutantStatsRepository } from '@app/common/modules/aqi/r
|
|||||||
NewTagService,
|
NewTagService,
|
||||||
SpaceModelService,
|
SpaceModelService,
|
||||||
SpaceProductAllocationService,
|
SpaceProductAllocationService,
|
||||||
SpaceLinkRepository,
|
|
||||||
SubspaceRepository,
|
SubspaceRepository,
|
||||||
SubspaceDeviceService,
|
SubspaceDeviceService,
|
||||||
SubspaceProductAllocationService,
|
SubspaceProductAllocationService,
|
||||||
|
@ -22,7 +22,6 @@ import {
|
|||||||
} from '@app/common/modules/scene/repositories';
|
} from '@app/common/modules/scene/repositories';
|
||||||
import {
|
import {
|
||||||
InviteSpaceRepository,
|
InviteSpaceRepository,
|
||||||
SpaceLinkRepository,
|
|
||||||
SpaceProductAllocationRepository,
|
SpaceProductAllocationRepository,
|
||||||
SpaceRepository,
|
SpaceRepository,
|
||||||
} from '@app/common/modules/space';
|
} from '@app/common/modules/space';
|
||||||
@ -96,7 +95,6 @@ import { AqiSpaceDailyPollutantStatsRepository } from '@app/common/modules/aqi/r
|
|||||||
SpaceModelService,
|
SpaceModelService,
|
||||||
SpaceProductAllocationService,
|
SpaceProductAllocationService,
|
||||||
SqlLoaderService,
|
SqlLoaderService,
|
||||||
SpaceLinkRepository,
|
|
||||||
SubspaceRepository,
|
SubspaceRepository,
|
||||||
SubspaceDeviceService,
|
SubspaceDeviceService,
|
||||||
SubspaceProductAllocationService,
|
SubspaceProductAllocationService,
|
||||||
|
@ -23,7 +23,6 @@ import {
|
|||||||
} from '@app/common/modules/scene/repositories';
|
} from '@app/common/modules/scene/repositories';
|
||||||
import {
|
import {
|
||||||
InviteSpaceRepository,
|
InviteSpaceRepository,
|
||||||
SpaceLinkRepository,
|
|
||||||
SpaceProductAllocationRepository,
|
SpaceProductAllocationRepository,
|
||||||
SpaceRepository,
|
SpaceRepository,
|
||||||
} from '@app/common/modules/space';
|
} from '@app/common/modules/space';
|
||||||
@ -94,7 +93,6 @@ const CommandHandlers = [CreateOrphanSpaceHandler];
|
|||||||
SpaceModelService,
|
SpaceModelService,
|
||||||
DeviceService,
|
DeviceService,
|
||||||
SpaceProductAllocationService,
|
SpaceProductAllocationService,
|
||||||
SpaceLinkRepository,
|
|
||||||
SubspaceRepository,
|
SubspaceRepository,
|
||||||
SubspaceDeviceService,
|
SubspaceDeviceService,
|
||||||
SubspaceProductAllocationService,
|
SubspaceProductAllocationService,
|
||||||
|
@ -22,7 +22,6 @@ import {
|
|||||||
} from '@app/common/modules/scene/repositories';
|
} from '@app/common/modules/scene/repositories';
|
||||||
import {
|
import {
|
||||||
InviteSpaceRepository,
|
InviteSpaceRepository,
|
||||||
SpaceLinkRepository,
|
|
||||||
SpaceProductAllocationRepository,
|
SpaceProductAllocationRepository,
|
||||||
SpaceRepository,
|
SpaceRepository,
|
||||||
} from '@app/common/modules/space';
|
} from '@app/common/modules/space';
|
||||||
@ -93,7 +92,6 @@ const CommandHandlers = [
|
|||||||
DeviceRepository,
|
DeviceRepository,
|
||||||
TuyaService,
|
TuyaService,
|
||||||
CommunityRepository,
|
CommunityRepository,
|
||||||
SpaceLinkRepository,
|
|
||||||
InviteSpaceRepository,
|
InviteSpaceRepository,
|
||||||
NewTagService,
|
NewTagService,
|
||||||
DeviceService,
|
DeviceService,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
||||||
import { SpaceService } from '../services';
|
|
||||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||||
|
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||||
import {
|
import {
|
||||||
Body,
|
Body,
|
||||||
Controller,
|
Controller,
|
||||||
@ -12,12 +11,14 @@ import {
|
|||||||
Query,
|
Query,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { AddSpaceDto, CommunitySpaceParam, UpdateSpaceDto } from '../dtos';
|
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
|
||||||
import { GetSpaceParam } from '../dtos/get.space.param';
|
|
||||||
import { PermissionsGuard } from 'src/guards/permissions.guard';
|
|
||||||
import { Permissions } from 'src/decorators/permissions.decorator';
|
import { Permissions } from 'src/decorators/permissions.decorator';
|
||||||
|
import { PermissionsGuard } from 'src/guards/permissions.guard';
|
||||||
|
import { AddSpaceDto, CommunitySpaceParam, UpdateSpaceDto } from '../dtos';
|
||||||
import { GetSpaceDto } from '../dtos/get.space.dto';
|
import { GetSpaceDto } from '../dtos/get.space.dto';
|
||||||
|
import { GetSpaceParam } from '../dtos/get.space.param';
|
||||||
|
import { OrderSpacesDto } from '../dtos/order.spaces.dto';
|
||||||
|
import { SpaceService } from '../services';
|
||||||
|
|
||||||
@ApiTags('Space Module')
|
@ApiTags('Space Module')
|
||||||
@Controller({
|
@Controller({
|
||||||
@ -65,6 +66,26 @@ export class SpaceController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@UseGuards(PermissionsGuard)
|
||||||
|
@Permissions('SPACE_UPDATE')
|
||||||
|
@ApiOperation({
|
||||||
|
summary:
|
||||||
|
ControllerRoute.SPACE.ACTIONS
|
||||||
|
.UPDATE_CHILDREN_SPACES_ORDER_OF_A_SPACE_SUMMARY,
|
||||||
|
description:
|
||||||
|
ControllerRoute.SPACE.ACTIONS
|
||||||
|
.UPDATE_CHILDREN_SPACES_ORDER_OF_A_SPACE_DESCRIPTION,
|
||||||
|
})
|
||||||
|
@Post(':parentSpaceUuid/spaces/order')
|
||||||
|
async updateSpacesOrder(
|
||||||
|
@Body() orderSpacesDto: OrderSpacesDto,
|
||||||
|
@Param() communitySpaceParam: CommunitySpaceParam,
|
||||||
|
@Param('parentSpaceUuid') parentSpaceUuid: string,
|
||||||
|
) {
|
||||||
|
return this.spaceService.updateSpacesOrder(parentSpaceUuid, orderSpacesDto);
|
||||||
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(PermissionsGuard)
|
@UseGuards(PermissionsGuard)
|
||||||
@Permissions('SPACE_DELETE')
|
@Permissions('SPACE_DELETE')
|
||||||
|
13
src/space/dtos/order.spaces.dto.ts
Normal file
13
src/space/dtos/order.spaces.dto.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { ArrayUnique, IsNotEmpty, IsUUID } from 'class-validator';
|
||||||
|
|
||||||
|
export class OrderSpacesDto {
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'List of children spaces associated with the space',
|
||||||
|
type: [String],
|
||||||
|
})
|
||||||
|
@IsNotEmpty()
|
||||||
|
@ArrayUnique()
|
||||||
|
@IsUUID('4', { each: true, message: 'Invalid space UUID provided' })
|
||||||
|
spacesUuids: string[];
|
||||||
|
}
|
@ -2,6 +2,7 @@ import { ORPHAN_SPACE_NAME } from '@app/common/constants/orphan-constant';
|
|||||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
import { Type } from 'class-transformer';
|
import { Type } from 'class-transformer';
|
||||||
import {
|
import {
|
||||||
|
ArrayUnique,
|
||||||
IsArray,
|
IsArray,
|
||||||
IsNumber,
|
IsNumber,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
@ -49,6 +50,20 @@ export class UpdateSpaceDto {
|
|||||||
description: 'List of subspace modifications',
|
description: 'List of subspace modifications',
|
||||||
type: [UpdateSubspaceDto],
|
type: [UpdateSubspaceDto],
|
||||||
})
|
})
|
||||||
|
@ArrayUnique((subspace) => subspace.subspaceName, {
|
||||||
|
message(validationArguments) {
|
||||||
|
const subspaces = validationArguments.value;
|
||||||
|
const nameCounts = subspaces.reduce((acc, curr) => {
|
||||||
|
acc[curr.subspaceName] = (acc[curr.subspaceName] || 0) + 1;
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
// Find duplicates
|
||||||
|
const duplicates = Object.keys(nameCounts).filter(
|
||||||
|
(name) => nameCounts[name] > 1,
|
||||||
|
);
|
||||||
|
return `Duplicate subspace names found: ${duplicates.join(', ')}`;
|
||||||
|
},
|
||||||
|
})
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@ValidateNested({ each: true })
|
@ValidateNested({ each: true })
|
||||||
|
@ -2,6 +2,5 @@ export * from './space.service';
|
|||||||
export * from './space-user.service';
|
export * from './space-user.service';
|
||||||
export * from './space-device.service';
|
export * from './space-device.service';
|
||||||
export * from './subspace';
|
export * from './subspace';
|
||||||
export * from './space-link';
|
|
||||||
export * from './space-scene.service';
|
export * from './space-scene.service';
|
||||||
export * from './space-validation.service';
|
export * from './space-validation.service';
|
||||||
|
@ -1 +0,0 @@
|
|||||||
export * from './space-link.service';
|
|
@ -1,6 +0,0 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
|
|
||||||
// todo: find out why we need to import this
|
|
||||||
// in community module in order for the whole system to work
|
|
||||||
@Injectable()
|
|
||||||
export class SpaceLinkService {}
|
|
@ -33,6 +33,7 @@ import {
|
|||||||
} from '../dtos';
|
} from '../dtos';
|
||||||
import { CreateProductAllocationDto } from '../dtos/create-product-allocation.dto';
|
import { CreateProductAllocationDto } from '../dtos/create-product-allocation.dto';
|
||||||
import { GetSpaceDto } from '../dtos/get.space.dto';
|
import { GetSpaceDto } from '../dtos/get.space.dto';
|
||||||
|
import { OrderSpacesDto } from '../dtos/order.spaces.dto';
|
||||||
import { SpaceWithParentsDto } from '../dtos/space.parents.dto';
|
import { SpaceWithParentsDto } from '../dtos/space.parents.dto';
|
||||||
import { SpaceProductAllocationService } from './space-product-allocation.service';
|
import { SpaceProductAllocationService } from './space-product-allocation.service';
|
||||||
import { ValidationService } from './space-validation.service';
|
import { ValidationService } from './space-validation.service';
|
||||||
@ -355,6 +356,32 @@ export class SpaceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateSpacesOrder(
|
||||||
|
parentSpaceUuid: string,
|
||||||
|
{ spacesUuids }: OrderSpacesDto,
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
await this.spaceRepository.update(
|
||||||
|
{ uuid: In(spacesUuids), parent: { uuid: parentSpaceUuid } },
|
||||||
|
{
|
||||||
|
order: () =>
|
||||||
|
'CASE ' +
|
||||||
|
spacesUuids
|
||||||
|
.map((s, index) => `WHEN uuid = '${s}' THEN ${index + 1}`)
|
||||||
|
.join(' ') +
|
||||||
|
' END',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error updating spaces order:', error);
|
||||||
|
throw new HttpException(
|
||||||
|
'An error occurred while updating spaces order',
|
||||||
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async delete(params: GetSpaceParam): Promise<BaseResponseDto> {
|
async delete(params: GetSpaceParam): Promise<BaseResponseDto> {
|
||||||
const queryRunner = this.dataSource.createQueryRunner();
|
const queryRunner = this.dataSource.createQueryRunner();
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
@ -426,7 +453,7 @@ export class SpaceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async disableSpace(space: SpaceEntity, orphanSpace: SpaceEntity) {
|
private async disableSpace(space: SpaceEntity, orphanSpace: SpaceEntity) {
|
||||||
await this.commandBus.execute(
|
await this.commandBus.execute(
|
||||||
new DisableSpaceCommand({ spaceUuid: space.uuid, orphanSpace }),
|
new DisableSpaceCommand({ spaceUuid: space.uuid, orphanSpace }),
|
||||||
);
|
);
|
||||||
@ -709,10 +736,21 @@ export class SpaceService {
|
|||||||
rootSpaces.push(map.get(space.uuid)!); // Push only root spaces
|
rootSpaces.push(map.get(space.uuid)!); // Push only root spaces
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
rootSpaces.forEach(this.sortSpaceChildren.bind(this));
|
||||||
return rootSpaces;
|
return rootSpaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private sortSpaceChildren(space: SpaceEntity) {
|
||||||
|
if (space.children && space.children.length > 0) {
|
||||||
|
space.children.sort((a, b) => {
|
||||||
|
const aOrder = a.order ?? Infinity;
|
||||||
|
const bOrder = b.order ?? Infinity;
|
||||||
|
return aOrder - bOrder;
|
||||||
|
});
|
||||||
|
space.children.forEach(this.sortSpaceChildren.bind(this)); // Recursively sort children of children
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private validateSpaceCreationCriteria({
|
private validateSpaceCreationCriteria({
|
||||||
spaceModelUuid,
|
spaceModelUuid,
|
||||||
productAllocations,
|
productAllocations,
|
||||||
|
@ -23,7 +23,7 @@ export class SubspaceProductAllocationService {
|
|||||||
// spaceAllocationsToExclude?: SpaceProductAllocationEntity[],
|
// spaceAllocationsToExclude?: SpaceProductAllocationEntity[],
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (!allocationsData.length) return;
|
if (!allocationsData?.length) return;
|
||||||
|
|
||||||
const allocations: SubspaceProductAllocationEntity[] = [];
|
const allocations: SubspaceProductAllocationEntity[] = [];
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ export class SubspaceProductAllocationService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Create the product-tag mapping based on the processed tags
|
// Create the product-tag mapping based on the processed tags
|
||||||
const productTagMapping = subspace.productAllocations.map(
|
const productTagMapping = subspace.productAllocations?.map(
|
||||||
({ tagUuid, tagName, productUuid }) => {
|
({ tagUuid, tagName, productUuid }) => {
|
||||||
const inputTag = tagUuid
|
const inputTag = tagUuid
|
||||||
? createdTagsByUUID.get(tagUuid)
|
? createdTagsByUUID.get(tagUuid)
|
||||||
|
@ -39,7 +39,7 @@ export class SubSpaceService {
|
|||||||
private readonly subspaceProductAllocationService: SubspaceProductAllocationService,
|
private readonly subspaceProductAllocationService: SubspaceProductAllocationService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async createSubspaces(
|
private async createSubspaces(
|
||||||
subspaceData: Array<{
|
subspaceData: Array<{
|
||||||
subspaceName: string;
|
subspaceName: string;
|
||||||
space: SpaceEntity;
|
space: SpaceEntity;
|
||||||
|
@ -1 +0,0 @@
|
|||||||
export * from './tag.service';
|
|
@ -1,8 +0,0 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
|
|
||||||
// todo: find out why we need to import this
|
|
||||||
// in community module in order for the whole system to work
|
|
||||||
@Injectable()
|
|
||||||
export class TagService {
|
|
||||||
constructor() {}
|
|
||||||
}
|
|
@ -37,7 +37,6 @@ import {
|
|||||||
} from '@app/common/modules/space-model';
|
} from '@app/common/modules/space-model';
|
||||||
import {
|
import {
|
||||||
InviteSpaceRepository,
|
InviteSpaceRepository,
|
||||||
SpaceLinkRepository,
|
|
||||||
SpaceProductAllocationRepository,
|
SpaceProductAllocationRepository,
|
||||||
SpaceRepository,
|
SpaceRepository,
|
||||||
} from '@app/common/modules/space/repositories';
|
} from '@app/common/modules/space/repositories';
|
||||||
@ -116,7 +115,6 @@ export const CommandHandlers = [DisableSpaceHandler];
|
|||||||
SubspaceRepository,
|
SubspaceRepository,
|
||||||
DeviceRepository,
|
DeviceRepository,
|
||||||
CommunityRepository,
|
CommunityRepository,
|
||||||
SpaceLinkRepository,
|
|
||||||
UserSpaceRepository,
|
UserSpaceRepository,
|
||||||
UserRepository,
|
UserRepository,
|
||||||
SpaceUserService,
|
SpaceUserService,
|
||||||
|
Reference in New Issue
Block a user