rwadurian/backend/services/identity-service/src/domain/value-objects/account-sequence.vo.ts

20 lines
525 B
TypeScript

import { DomainError } from '@/shared/exceptions/domain.exception';
export class AccountSequence {
constructor(public readonly value: number) {
if (value <= 0) throw new DomainError('账户序列号必须大于0');
}
static create(value: number): AccountSequence {
return new AccountSequence(value);
}
static next(current: AccountSequence): AccountSequence {
return new AccountSequence(current.value + 1);
}
equals(other: AccountSequence): boolean {
return this.value === other.value;
}
}