mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
refactor(companies): one verified identity per company, no general manager
Replaces the owner/general-manager/PoA trio with a single identity whose
subject is the PoA when the company declares one and the owner otherwise.
- Drop the general manager everywhere: entity columns, DTOs, required-field
list, self-service attributes, gm* identity handling.
- New explicit poaDeclared answer ("yes"/"no") replaces poaSameAsOwner. A
DARS delegation letter is required iff it is "yes"; a freight forwarder is
forced to "yes" server-side and gets no waiver.
- Owner name/email/phone become typeable and required, prefilled from the
eTrade lookup, never falling back to the authenticated account.
- Store eTrade's manager separately (etradeManagerName/Phone) and expose
ownerMatchesEtrade so backoffice compares the asserted owner against the
licence instead of against itself.
- Foreign companies satisfy the identity with Fayda or a passport number, on
whichever subject is verifying (poaPassportNumber added).
- Write companies.email/phone from the owner unconditionally, so a company
without a Fayda-verified owner still has a notification address.
This commit is contained in:
@@ -12,8 +12,8 @@ import { DataSource, EntityManager } from "typeorm";
|
||||
* `companies.contact_person_phone` is deliberately NOT consulted: the live write
|
||||
* path stores that value in the `attributes` jsonb and has never populated the
|
||||
* column, so every reader of it was silently falling through to `phone` anyway.
|
||||
* `companies.general_manager_email` is the same trap on the email side — see
|
||||
* {@link companyNotifyEmailExpr}.
|
||||
* The retired `general_manager_email` column was the same trap on the email
|
||||
* side — see {@link companyNotifyEmailExpr}.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -50,24 +50,30 @@ export function companyNotifyPhoneExpr(alias: string): string {
|
||||
* SQL expression for the company's notification address, given the joined `pc`
|
||||
* alias.
|
||||
*
|
||||
* `companies.email` alone is not enough: it is written from ONE place — a
|
||||
* Fayda-verified owner's email claim — so a foreign company, whose owner proves
|
||||
* identity by passport instead, never gets one. Readers papered over that with
|
||||
* `COALESCE(email, general_manager_email)`, but that column has the same problem
|
||||
* `contact_person_phone` has above: onboarding writes the value into the
|
||||
* `attributes` jsonb and nothing has ever populated the column, so the fallback
|
||||
* could not fire and the mail was dropped in silence.
|
||||
* `companies.email` is now the owner's email, written on every profile save
|
||||
* whether or not the owner verified with Fayda — and the owner's email is a
|
||||
* required onboarding field, so a company that finished onboarding has one.
|
||||
* (It used to be written ONLY for a Fayda-verified owner, which meant every
|
||||
* foreign company had none; the gap was papered over with a
|
||||
* `general_manager_email` leg that could never fire, because onboarding wrote
|
||||
* that value into `attributes` and nothing ever populated the column.)
|
||||
*
|
||||
* So: the company address, then the two the customer actually filled in during
|
||||
* onboarding, then the account that registered them — which always has one,
|
||||
* signup requires it. `NULLIF` because a blank jsonb key is not an address and
|
||||
* `COALESCE` would happily stop on it.
|
||||
* The `generalManagerEmail` attribute is still consulted, after the contact
|
||||
* person: the general manager was removed, but companies onboarded before that
|
||||
* may carry an address there and nowhere else. RemoveGeneralManager backfills
|
||||
* `companies.email` from it, so this is belt-and-braces for rows that migration
|
||||
* could not resolve.
|
||||
*
|
||||
* `NULLIF` because a blank jsonb key is not an address and `COALESCE` would
|
||||
* happily stop on it. The account that registered the company is the last
|
||||
* resort — signup guarantees it has one.
|
||||
*/
|
||||
export function companyNotifyEmailExpr(alias: string): string {
|
||||
return `COALESCE(
|
||||
NULLIF(${alias}.email, ''),
|
||||
NULLIF(${alias}.attributes->>'generalManagerEmail', ''),
|
||||
NULLIF(${alias}.attributes->>'ownerEmail', ''),
|
||||
NULLIF(${alias}.attributes->>'contactPersonEmail', ''),
|
||||
NULLIF(${alias}.attributes->>'generalManagerEmail', ''),
|
||||
NULLIF(pc.email, '')
|
||||
)`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user