diff --git a/packages/core/src/auth/auth.controller.ts b/packages/core/src/auth/auth.controller.ts index 0d31a9e6c6e..3f6c2619050 100644 --- a/packages/core/src/auth/auth.controller.ts +++ b/packages/core/src/auth/auth.controller.ts @@ -47,7 +47,7 @@ export class AuthController { private readonly authService: AuthService, private readonly userService: UserService, private readonly commandBus: CommandBus - ) {} + ) { } /** * Check if the user is authenticated. @@ -169,8 +169,13 @@ export class AuthController { @Post('/signin.email') @Public() @UsePipes(new ValidationPipe({ transform: true })) - async sendWorkspaceSigninCode(@Body() entity: UserEmailDTO, @I18nLang() locale: LanguagesEnum): Promise { - return await this.commandBus.execute(new WorkspaceSigninSendCodeCommand(entity, locale)); + async sendWorkspaceSigninCode( + @Body() entity: UserEmailDTO, + @I18nLang() locale: LanguagesEnum + ): Promise { + return await this.commandBus.execute( + new WorkspaceSigninSendCodeCommand(entity, locale) + ); } /** @@ -185,8 +190,11 @@ export class AuthController { async confirmWorkspaceSigninByCode( @Query() query: Record, @Body() input: WorkspaceSigninEmailVerifyDTO - ): Promise { - return await this.authService.confirmWorkspaceSigninByCode(input, parseToBoolean(query.includeTeams)); + ): Promise { + return await this.authService.confirmWorkspaceSigninByCode( + input, + parseToBoolean(query.includeTeams) + ); } /** @@ -198,8 +206,12 @@ export class AuthController { @Post('/signin.workspace') @Public() @UsePipes(new ValidationPipe({ whitelist: true })) - async signinWorkspaceByToken(@Body() input: WorkspaceSigninDTO): Promise { - return await this.commandBus.execute(new WorkspaceSigninVerifyTokenCommand(input)); + async signinWorkspaceByToken( + @Body() input: WorkspaceSigninDTO + ): Promise { + return await this.commandBus.execute( + new WorkspaceSigninVerifyTokenCommand(input) + ); } /** diff --git a/packages/core/src/auth/auth.service.ts b/packages/core/src/auth/auth.service.ts index 30ea1753506..ac371b0dc4a 100644 --- a/packages/core/src/auth/auth.service.ts +++ b/packages/core/src/auth/auth.service.ts @@ -906,10 +906,7 @@ export class AuthService extends SocialAuthService { employeeId: string | null ): Promise { const query = this.typeOrmOrganizationTeamRepository.createQueryBuilder("organization_team"); - query.innerJoin('organization_team_employee', - p("team_member"), - p('"team_member"."organizationTeamId" = "organization_team"."id"') - ); + query.innerJoin(`organization_team_employee`, `team_member`, p('"team_member"."organizationTeamId" = "organization_team"."id"')); query.select([ p(`"${query.alias}"."id" AS "team_id"`), @@ -917,72 +914,49 @@ export class AuthService extends SocialAuthService { p(`"${query.alias}"."logo" AS "team_logo"`), p(`COALESCE(COUNT("team_member"."id"), 0) AS "team_member_count"`), p(`"${query.alias}"."profile_link" AS "profile_link"`), - p(`"${query.alias}"."prefix" AS "prefix")`) + p(`"${query.alias}"."prefix" AS "prefix"`) ]); - query.andWhere( - p(`"${query.alias}"."tenantId" = :tenantId`), { tenantId } - ); + query.andWhere(p(`"${query.alias}"."tenantId" = :tenantId`), { tenantId }); + query.andWhere(p(`"${query.alias}"."isActive" = :isActive`), { isActive: true }); + query.andWhere(p(`"${query.alias}"."isArchived" = :isArchived`), { isArchived: false }); // Sub Query to get only assigned teams for specific organizations const orgSubQuery = (cb: SelectQueryBuilder): string => { - const subQuery = cb.subQuery() - .select( - p('"user_organization"."organizationId"') - ).from( - p("user_organization"), - p("user_organization") - ); - subQuery.andWhere( - p(`"${subQuery.alias}"."isActive" = true`) - ); - subQuery.andWhere( - p(`"${subQuery.alias}"."userId" = :userId`), { userId } - ); - subQuery.andWhere( - p(`"${subQuery.alias}"."tenantId" = :tenantId`), { tenantId } - ); + const subQuery = cb.subQuery().select(p('"user_organization"."organizationId"')).from("user_organization", "user_organization"); + subQuery.andWhere(p(`"${subQuery.alias}"."isActive" = :isActive`), { isActive: true }); + subQuery.andWhere(p(`"${subQuery.alias}"."isArchived" = :isArchived`), { isArchived: false }); + subQuery.andWhere(p(`"${subQuery.alias}"."userId" = :userId`), { userId }); + subQuery.andWhere(p(`"${subQuery.alias}"."tenantId" = :tenantId`), { tenantId }); return subQuery.distinct(true).getQuery(); }; // Sub Query to get only assigned teams for specific organizations query.andWhere((cb: SelectQueryBuilder) => { - return (p(`"${query.alias}"."organizationId" IN `) + orgSubQuery(cb)); + return (p(`"${query.alias}"."organizationId" IN ` + orgSubQuery(cb))); }); // Sub Query to get only assigned teams for a specific employee for specific tenant query.andWhere((cb: SelectQueryBuilder) => { - const subQuery = cb.subQuery() - .select( - p('"organization_team_employee"."organizationTeamId"') - ) - .from( - p("organization_team_employee"), - p("organization_team_employee") - ); - subQuery.andWhere( - p(`"${subQuery.alias}"."tenantId" = :tenantId`), { tenantId } - ); + const subQuery = cb.subQuery().select(p('"organization_team_employee"."organizationTeamId"')).from("organization_team_employee", "organization_team_employee"); + subQuery.andWhere(p(`"${subQuery.alias}"."isActive" = :isActive`), { isActive: true }); + subQuery.andWhere(p(`"${subQuery.alias}"."isArchived" = :isArchived`), { isArchived: false }); + subQuery.andWhere(p(`"${subQuery.alias}"."tenantId" = :tenantId`), { tenantId }); if (isNotEmpty(employeeId)) { - subQuery.andWhere( - p(`"${subQuery.alias}"."employeeId" = :employeeId`), { employeeId } - ); + subQuery.andWhere(p(`"${subQuery.alias}"."employeeId" = :employeeId`), { employeeId }); } // Sub Query to get only assigned teams for specific organizations subQuery.andWhere((cb: SelectQueryBuilder) => { - return (p(`"${subQuery.alias}"."organizationId" IN `) + orgSubQuery(cb)); + return (p(`"${subQuery.alias}"."organizationId" IN ` + orgSubQuery(cb))); }); - return (p(`"${query.alias}"."id" IN `) + subQuery.distinct(true).getQuery()); + + return (p(`"${query.alias}"."id" IN ` + subQuery.distinct(true).getQuery())); }); - query.addGroupBy( - p(`"${query.alias}"."id"`) - ); - query.orderBy( - p(`"${query.alias}"."createdAt"`), 'DESC' - ); + query.addGroupBy(p(`"${query.alias}"."id"`)); + query.orderBy(p(`"${query.alias}"."createdAt"`), 'DESC'); return await query.getRawMany(); } diff --git a/packages/core/src/auth/dto/two-factor-dto.ts b/packages/core/src/auth/dto/two-factor-dto.ts index 9836c396914..af13bff5fff 100644 --- a/packages/core/src/auth/dto/two-factor-dto.ts +++ b/packages/core/src/auth/dto/two-factor-dto.ts @@ -1,13 +1,25 @@ -import { IntersectionType } from "@nestjs/swagger"; +import { ApiPropertyOptional, IntersectionType } from "@nestjs/swagger"; +import { IsBoolean, IsOptional } from "class-validator"; import { IUserCodeInput, IUserEmailInput, IUserTokenInput } from "@gauzy/contracts"; import { UserCodeDTO, UserEmailDTO, UserTokenDTO } from "../../user/dto"; +/** + * + */ export class WorkspaceSigninEmailVerifyDTO extends IntersectionType( UserEmailDTO, UserCodeDTO, -) implements IUserEmailInput, IUserCodeInput { } +) implements IUserEmailInput, IUserCodeInput { + @ApiPropertyOptional({ type: () => Boolean }) + @IsOptional() + @IsBoolean() + readonly includeTeams: boolean; +} +/** + * + */ export class WorkspaceSigninDTO extends IntersectionType( UserEmailDTO, UserTokenDTO,