|
@@ -3,6 +3,7 @@ import { Result } from '../Core/Result'
|
|
|
|
|
|
import { NotificationPayloadProps } from './NotificationPayloadProps'
|
|
|
import { NotificationType } from './NotificationType'
|
|
|
+import { Uuid } from '../Common/Uuid'
|
|
|
|
|
|
export class NotificationPayload extends ValueObject<NotificationPayloadProps> {
|
|
|
private constructor(props: NotificationPayloadProps) {
|
|
@@ -10,14 +11,45 @@ export class NotificationPayload extends ValueObject<NotificationPayloadProps> {
|
|
|
}
|
|
|
|
|
|
override toString(): string {
|
|
|
- return JSON.stringify(this.props)
|
|
|
+ return JSON.stringify({
|
|
|
+ version: this.props.version,
|
|
|
+ type: this.props.type.value,
|
|
|
+ sharedVaultUuid: this.props.sharedVaultUuid.value,
|
|
|
+ itemUuid: this.props.itemUuid ? this.props.itemUuid.value : undefined,
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
static createFromString(jsonPayload: string): Result<NotificationPayload> {
|
|
|
try {
|
|
|
const props = JSON.parse(jsonPayload)
|
|
|
|
|
|
- return NotificationPayload.create(props)
|
|
|
+ const typeOrError = NotificationType.create(props.type)
|
|
|
+ if (typeOrError.isFailed()) {
|
|
|
+ return Result.fail<NotificationPayload>(typeOrError.getError())
|
|
|
+ }
|
|
|
+ const type = typeOrError.getValue()
|
|
|
+
|
|
|
+ const sharedVaultUuidOrError = Uuid.create(props.sharedVaultUuid)
|
|
|
+ if (sharedVaultUuidOrError.isFailed()) {
|
|
|
+ return Result.fail<NotificationPayload>(sharedVaultUuidOrError.getError())
|
|
|
+ }
|
|
|
+ const sharedVaultUuid = sharedVaultUuidOrError.getValue()
|
|
|
+
|
|
|
+ let itemUuid: Uuid | undefined = undefined
|
|
|
+ if (props.itemUuid) {
|
|
|
+ const itemUuidOrError = Uuid.create(props.itemUuid)
|
|
|
+ if (itemUuidOrError.isFailed()) {
|
|
|
+ return Result.fail<NotificationPayload>(itemUuidOrError.getError())
|
|
|
+ }
|
|
|
+ itemUuid = itemUuidOrError.getValue()
|
|
|
+ }
|
|
|
+
|
|
|
+ return NotificationPayload.create({
|
|
|
+ version: props.version,
|
|
|
+ type,
|
|
|
+ sharedVaultUuid,
|
|
|
+ itemUuid,
|
|
|
+ })
|
|
|
} catch (error) {
|
|
|
return Result.fail<NotificationPayload>((error as Error).message)
|
|
|
}
|