presence status
This commit is contained in:
@@ -15,17 +15,16 @@ function IsAtLeastOneNameProvided(validationOptions?: ValidationOptions) {
|
|||||||
name: 'isAtLeastOneNameProvided',
|
name: 'isAtLeastOneNameProvided',
|
||||||
validator: {
|
validator: {
|
||||||
validate(value, args) {
|
validate(value, args) {
|
||||||
const object = args?.object as AppMetadataDto;
|
const object = args?.object as PresenceStatusDto;
|
||||||
const hasLocalized =
|
const hasTitle =
|
||||||
typeof object.localized === 'string' &&
|
typeof object.title === 'string' && object.title.trim().length > 0;
|
||||||
object.localized.trim().length > 0;
|
const hasSubtitle =
|
||||||
const hasUnlocalized =
|
typeof object.subtitle === 'string' &&
|
||||||
typeof object.unlocalized === 'string' &&
|
object.subtitle.trim().length > 0;
|
||||||
object.unlocalized.trim().length > 0;
|
return hasTitle || hasSubtitle;
|
||||||
return hasLocalized || hasUnlocalized;
|
|
||||||
},
|
},
|
||||||
defaultMessage() {
|
defaultMessage() {
|
||||||
return 'At least one of localized or unlocalized must be a non-empty string';
|
return 'At least one of title or subtitle must be a non-empty string';
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -33,19 +32,19 @@ function IsAtLeastOneNameProvided(validationOptions?: ValidationOptions) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AppMetadataDto {
|
export class PresenceStatusDto {
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
@MaxLength(200)
|
@MaxLength(200)
|
||||||
@IsAtLeastOneNameProvided()
|
@IsAtLeastOneNameProvided()
|
||||||
localized: string | null;
|
title: string | null;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
@MaxLength(200)
|
@MaxLength(200)
|
||||||
unlocalized: string | null;
|
subtitle: string | null;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
appIconB64: string | null;
|
graphicsB64: string | null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { IsEnum, ValidateNested } from 'class-validator';
|
import { IsEnum, ValidateNested } from 'class-validator';
|
||||||
import { Type } from 'class-transformer';
|
import { Type } from 'class-transformer';
|
||||||
import { AppMetadataDto } from './app-metadata.dto';
|
import { PresenceStatusDto } from './app-metadata.dto';
|
||||||
|
|
||||||
export enum UserState {
|
export enum UserState {
|
||||||
IDLE = 'idle',
|
IDLE = 'idle',
|
||||||
@@ -9,8 +9,8 @@ export enum UserState {
|
|||||||
|
|
||||||
export class UserStatusDto {
|
export class UserStatusDto {
|
||||||
@ValidateNested()
|
@ValidateNested()
|
||||||
@Type(() => AppMetadataDto)
|
@Type(() => PresenceStatusDto)
|
||||||
appMetadata: AppMetadataDto;
|
presenceStatus: PresenceStatusDto;
|
||||||
|
|
||||||
@IsEnum(UserState)
|
@IsEnum(UserState)
|
||||||
state: UserState;
|
state: UserState;
|
||||||
|
|||||||
@@ -486,10 +486,10 @@ describe('StateGateway', () => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const data: UserStatusDto = {
|
const data: UserStatusDto = {
|
||||||
appMetadata: {
|
presenceStatus: {
|
||||||
localized: null,
|
title: null,
|
||||||
unlocalized: 'VS Code',
|
subtitle: 'VS Code',
|
||||||
appIconB64: null,
|
graphicsB64: null,
|
||||||
},
|
},
|
||||||
state: UserState.IDLE,
|
state: UserState.IDLE,
|
||||||
};
|
};
|
||||||
@@ -522,10 +522,10 @@ describe('StateGateway', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const data: UserStatusDto = {
|
const data: UserStatusDto = {
|
||||||
appMetadata: {
|
presenceStatus: {
|
||||||
localized: null,
|
title: null,
|
||||||
unlocalized: 'VS Code',
|
subtitle: 'VS Code',
|
||||||
appIconB64: null,
|
graphicsB64: null,
|
||||||
},
|
},
|
||||||
state: UserState.IDLE,
|
state: UserState.IDLE,
|
||||||
};
|
};
|
||||||
@@ -549,10 +549,10 @@ describe('StateGateway', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const data: UserStatusDto = {
|
const data: UserStatusDto = {
|
||||||
appMetadata: {
|
presenceStatus: {
|
||||||
localized: null,
|
title: null,
|
||||||
unlocalized: 'VS Code',
|
subtitle: 'VS Code',
|
||||||
appIconB64: null,
|
graphicsB64: null,
|
||||||
},
|
},
|
||||||
state: UserState.IDLE,
|
state: UserState.IDLE,
|
||||||
};
|
};
|
||||||
@@ -572,10 +572,10 @@ describe('StateGateway', () => {
|
|||||||
data: {},
|
data: {},
|
||||||
};
|
};
|
||||||
const data: UserStatusDto = {
|
const data: UserStatusDto = {
|
||||||
appMetadata: {
|
presenceStatus: {
|
||||||
localized: null,
|
title: null,
|
||||||
unlocalized: 'VS Code',
|
subtitle: 'VS Code',
|
||||||
appIconB64: null,
|
graphicsB64: null,
|
||||||
},
|
},
|
||||||
state: UserState.IDLE,
|
state: UserState.IDLE,
|
||||||
};
|
};
|
||||||
@@ -605,10 +605,10 @@ describe('StateGateway', () => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const data: UserStatusDto = {
|
const data: UserStatusDto = {
|
||||||
appMetadata: {
|
presenceStatus: {
|
||||||
localized: null,
|
title: null,
|
||||||
unlocalized: 'VS Code',
|
subtitle: 'VS Code',
|
||||||
appIconB64: null,
|
graphicsB64: null,
|
||||||
},
|
},
|
||||||
state: UserState.IDLE,
|
state: UserState.IDLE,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user