-
Notifications
You must be signed in to change notification settings - Fork 0
uuid param
awekrx edited this page May 29, 2026
·
1 revision
import { uuidParam } from '@dev-suite/decorators/uuid-param'
parameter
Validate UUID argument format before use.
- Regex UUID checks in methods
- Repeated validator calls
class UserService {
get(id: string) {
if (!/^[0-9a-f-]{36}$/i.test(id)) throw new Error('Invalid UUID');
return this.repo.get(id);
}
}import { uuidParam } from '@dev-suite/decorators/uuid-param';
class UserService {
get(@uuidParam() id: string) {
return this.repo.get(id);
}
}- Centralizes cross-cutting behavior.
- Method/class/property code stays focused on domain logic.
class SessionService {
revoke(sessionId: string) {
if (!isUuid(sessionId)) throw new Error('Bad sessionId');
return this.sessions.revoke(sessionId);
}
}import { uuidParam } from '@dev-suite/decorators/uuid-param';
class SessionService {
revoke(@uuidParam({ message: 'Bad sessionId' }) sessionId: string) {
return this.sessions.revoke(sessionId);
}
}- Second scenario reuses same policy without duplication.
- Behavior is more consistent and easier to audit.