@ -22,12 +22,12 @@ class Telemetry {
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
class SupportChat {
|
||||
class Support {
|
||||
@Field(() => String)
|
||||
supportDriver: string;
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
supportFrontendKey: string | null;
|
||||
supportFrontChatId: string | undefined;
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
@ -44,6 +44,6 @@ export class ClientConfig {
|
||||
@Field(() => Boolean)
|
||||
debugMode: boolean;
|
||||
|
||||
@Field(() => SupportChat)
|
||||
supportChat: SupportChat;
|
||||
@Field(() => Support)
|
||||
support: Support;
|
||||
}
|
||||
|
||||
@ -23,9 +23,9 @@ export class ClientConfigResolver {
|
||||
},
|
||||
signInPrefilled: this.environmentService.isSignInPrefilled(),
|
||||
debugMode: this.environmentService.isDebugMode(),
|
||||
supportChat: {
|
||||
support: {
|
||||
supportDriver: this.environmentService.getSupportDriver(),
|
||||
supportFrontendKey: this.environmentService.getSupportFrontendKey(),
|
||||
supportFrontChatId: this.environmentService.getSupportFrontChatId(),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
import { Field, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
import { User } from 'src/core/@generated/user/user.model';
|
||||
|
||||
@ObjectType()
|
||||
export class UserWithHMACKey extends User {
|
||||
@Field(() => String, { nullable: true })
|
||||
supportHMACKey: string | null;
|
||||
}
|
||||
@ -43,7 +43,7 @@ import { EnvironmentService } from 'src/integrations/environment/environment.ser
|
||||
|
||||
import { UserService } from './user.service';
|
||||
|
||||
import { UserWithHMACKey } from './dto/user-with-HMAC';
|
||||
import { SupportDriver } from 'src/integrations/environment/interfaces/support.interface';
|
||||
|
||||
function getHMACKey(email?: string, key?: string | null) {
|
||||
if (!email || !key) return null;
|
||||
@ -61,26 +61,25 @@ export class UserResolver {
|
||||
private environmentService: EnvironmentService,
|
||||
) {}
|
||||
|
||||
@Query(() => UserWithHMACKey)
|
||||
@Query(() => User)
|
||||
async currentUser(
|
||||
@AuthUser() { id, email }: User,
|
||||
@AuthUser() { id }: User,
|
||||
@PrismaSelector({ modelName: 'User' })
|
||||
prismaSelect: PrismaSelect<'User'>,
|
||||
) {
|
||||
const key = this.environmentService.getSupportHMACKey();
|
||||
|
||||
|
||||
const select = prismaSelect.value;
|
||||
delete select['supportHMACKey'];
|
||||
|
||||
const user = await this.userService.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
select,
|
||||
select
|
||||
});
|
||||
assert(user, 'User not found');
|
||||
|
||||
return { ...user, supportHMACKey: getHMACKey(email, key) };
|
||||
return user;
|
||||
}
|
||||
|
||||
@UseFilters(ExceptionFilter)
|
||||
@ -141,6 +140,17 @@ export class UserResolver {
|
||||
return `${parent.firstName ?? ''} ${parent.lastName ?? ''}`;
|
||||
}
|
||||
|
||||
@ResolveField(() => String, {
|
||||
nullable: false,
|
||||
})
|
||||
supportUserHash(@Parent() parent: User): string | null {
|
||||
if (this.environmentService.getSupportDriver() !== SupportDriver.Front) {
|
||||
return null;
|
||||
}
|
||||
const key = this.environmentService.getSupportFrontHMACKey();
|
||||
return getHMACKey(parent.email, key);
|
||||
}
|
||||
|
||||
@Mutation(() => String)
|
||||
async uploadProfilePicture(
|
||||
@AuthUser() { id }: User,
|
||||
|
||||
@ -4,6 +4,7 @@ import { ConfigService } from '@nestjs/config';
|
||||
|
||||
import { AwsRegion } from './interfaces/aws-region.interface';
|
||||
import { StorageType } from './interfaces/storage.interface';
|
||||
import { SupportDriver } from './interfaces/support.interface';
|
||||
|
||||
@Injectable()
|
||||
export class EnvironmentService {
|
||||
@ -103,14 +104,14 @@ export class EnvironmentService {
|
||||
}
|
||||
|
||||
getSupportDriver(): string {
|
||||
return this.configService.get<string>('SUPPORT_DRIVER') ?? 'front';
|
||||
return this.configService.get<string>('SUPPORT_DRIVER') ?? SupportDriver.None;
|
||||
}
|
||||
|
||||
getSupportFrontendKey(): string | null {
|
||||
return this.configService.get<string>('SUPPORT_FRONTEND_KEY') ?? null;
|
||||
getSupportFrontChatId(): string | undefined {
|
||||
return this.configService.get<string>('SUPPORT_FRONT_CHAT_ID');
|
||||
}
|
||||
|
||||
getSupportHMACKey(): string | null {
|
||||
return this.configService.get<string>('SUPPORT_HMAC_KEY') ?? null;
|
||||
getSupportFrontHMACKey(): string | undefined {
|
||||
return this.configService.get<string>('SUPPORT_FRONT_HMAC_KEY');
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ import { StorageType } from './interfaces/storage.interface';
|
||||
import { AwsRegion } from './interfaces/aws-region.interface';
|
||||
import { IsAWSRegion } from './decorators/is-aws-region.decorator';
|
||||
import { CastToBoolean } from './decorators/cast-to-boolean.decorator';
|
||||
import { SupportDriver } from './interfaces/support.interface';
|
||||
|
||||
export class EnvironmentVariables {
|
||||
// Misc
|
||||
@ -104,6 +105,19 @@ export class EnvironmentVariables {
|
||||
@IsString()
|
||||
@ValidateIf((env) => env.STORAGE_TYPE === StorageType.Local)
|
||||
STORAGE_LOCAL_PATH?: string;
|
||||
|
||||
// Support
|
||||
@IsEnum(SupportDriver)
|
||||
@IsOptional()
|
||||
SUPPORT_DRIVER?: SupportDriver;
|
||||
|
||||
@ValidateIf((env) => env.SUPPORT_DRIVER === SupportDriver.Front)
|
||||
@IsString()
|
||||
SUPPORT_FRONT_CHAT_ID?: AwsRegion;
|
||||
|
||||
@ValidateIf((env) => env.SUPPORT_DRIVER === SupportDriver.Front)
|
||||
@IsString()
|
||||
SUPPORT_FRONT_HMAC_KEY?: string;
|
||||
}
|
||||
|
||||
export function validate(config: Record<string, unknown>) {
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
export enum SupportDriver {
|
||||
None = 'none',
|
||||
Front = 'front',
|
||||
}
|
||||
Reference in New Issue
Block a user