mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-14 08:53:11 +00:00
Adds electoral nuclei, leaderships, updates, and WhatsApp invite flows behind campaign auth, plus the consolidated schema migration that Vercel applies on deploy.
23 lines
790 B
TypeScript
23 lines
790 B
TypeScript
export type PopulatedRelationship = { id: number }
|
|
|
|
const isRelationshipId = (value: unknown): value is number =>
|
|
typeof value === 'number' && Number.isSafeInteger(value) && value > 0
|
|
|
|
export const isPopulatedRelationship = <Relationship extends PopulatedRelationship>(
|
|
value: unknown,
|
|
): value is Relationship =>
|
|
typeof value === 'object' && value !== null && 'id' in value && isRelationshipId(value.id)
|
|
|
|
export const relationshipId = (value: unknown): number | null => {
|
|
if (isRelationshipId(value)) return value
|
|
return isPopulatedRelationship(value) ? value.id : null
|
|
}
|
|
|
|
export const requireRelationshipId = (
|
|
value: unknown,
|
|
message = 'Relacionamento inválido.',
|
|
): number => {
|
|
const id = relationshipId(value)
|
|
if (id === null) throw new Error(message)
|
|
return id
|
|
}
|