feat: add manager guide and contextual help

This commit is contained in:
Bastian Wagner
2026-08-02 09:22:16 +02:00
parent 6eab6251d5
commit 0e8ac74116
43 changed files with 1002 additions and 6 deletions

View File

@@ -0,0 +1,24 @@
import { validate } from 'class-validator';
import { AuthUpdateDto } from './auth-update.dto';
describe('AuthUpdateDto help preference', () => {
it('rejects a non-boolean helpTextsEnabled value', async () => {
const dto = Object.assign(new AuthUpdateDto(), {
helpTextsEnabled: 'yes',
});
const errors = await validate(dto);
expect(errors.some((error) => error.property === 'helpTextsEnabled')).toBe(
true,
);
});
it('accepts a boolean helpTextsEnabled value without requiring profile fields', async () => {
const dto = Object.assign(new AuthUpdateDto(), {
helpTextsEnabled: false,
});
await expect(validate(dto)).resolves.toEqual([]);
});
});

View File

@@ -1,8 +1,12 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsOptional, MinLength, Validate } from 'class-validator';
import { IsBoolean, IsNotEmpty, IsOptional, MinLength } from 'class-validator';
import { IsExist } from '../../utils/validators/is-exists.validator';
export class AuthUpdateDto {
@ApiProperty({ default: true })
@IsOptional()
@IsBoolean()
helpTextsEnabled?: boolean;
@ApiProperty({ example: 'John' })
@IsOptional()

View File

@@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddHelpTextsEnabled1785520800000 implements MigrationInterface {
name = 'AddHelpTextsEnabled1785520800000';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
'ALTER TABLE "user" ADD "helpTextsEnabled" boolean NOT NULL DEFAULT true',
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
'ALTER TABLE "user" DROP COLUMN "helpTextsEnabled"',
);
}
}

View File

@@ -0,0 +1,31 @@
import { getMetadataArgsStorage } from 'typeorm';
import { User } from '../../users/entities/user.entity';
describe('AddHelpTextsEnabled1785520800000', () => {
it('adds a reversible enabled-by-default user preference', async () => {
const migrationModule = require('./1785520800000-AddHelpTextsEnabled');
const migration = new migrationModule.AddHelpTextsEnabled1785520800000();
const queryRunner = { query: jest.fn() } as any;
await migration.up(queryRunner);
expect(queryRunner.query).toHaveBeenCalledWith(
'ALTER TABLE "user" ADD "helpTextsEnabled" boolean NOT NULL DEFAULT true',
);
queryRunner.query.mockClear();
await migration.down(queryRunner);
expect(queryRunner.query).toHaveBeenCalledWith(
'ALTER TABLE "user" DROP COLUMN "helpTextsEnabled"',
);
});
it('keeps the user entity default aligned with the migration', () => {
const column = getMetadataArgsStorage().columns.find(
(candidate) =>
candidate.target === User &&
candidate.propertyName === 'helpTextsEnabled',
);
expect(column?.options).toMatchObject({ type: Boolean, default: true });
});
});

View File

@@ -65,6 +65,9 @@ export class User extends EntityHelper {
@Column({ nullable: true })
lastName: string | null;
@Column({ default: true })
helpTextsEnabled: boolean;
@ManyToOne(() => Role, {
eager: true,
})