improve name-check: match base name without entity suffix (LLC/Inc/Corp), flag close matches
This commit is contained in:
parent
e0ba8acc90
commit
2f635227aa
1 changed files with 13 additions and 2 deletions
|
|
@ -721,12 +721,21 @@ router.post("/api/v1/dot/name-check", async (req, res) => {
|
|||
// Parse FMCSA result
|
||||
let fmcsaMatches: Record<string, unknown>[] = [];
|
||||
let fmcsaExactMatch = false;
|
||||
let fmcsaCloseMatch = false;
|
||||
if (fmcsaResult.status === "fulfilled") {
|
||||
fmcsaMatches = fmcsaResult.value.rows || [];
|
||||
const searchUpper = name.toUpperCase().replace(/\s+(LLC|INC|CORP|CORPORATION|LTD|LP|LLP|CO|COMPANY)\.?$/i, "").trim();
|
||||
fmcsaExactMatch = fmcsaMatches.some(
|
||||
(r: Record<string, unknown>) =>
|
||||
(r.legal_name as string || "").toUpperCase() === name.toUpperCase(),
|
||||
);
|
||||
// Also check if the base name (without entity suffix) matches
|
||||
if (!fmcsaExactMatch) {
|
||||
fmcsaCloseMatch = fmcsaMatches.some((r: Record<string, unknown>) => {
|
||||
const legalUpper = (r.legal_name as string || "").toUpperCase().replace(/\s+(LLC|INC|CORP|CORPORATION|LTD|LP|LLP|CO|COMPANY)\.?$/i, "").trim();
|
||||
return legalUpper === searchUpper;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
res.json({
|
||||
|
|
@ -738,16 +747,18 @@ router.post("/api/v1/dot/name-check", async (req, res) => {
|
|||
entity_number: sosEntity.entity_number,
|
||||
entity_type: sosEntity.entity_type,
|
||||
} : null,
|
||||
fmcsa_in_use: fmcsaExactMatch,
|
||||
fmcsa_in_use: fmcsaExactMatch || fmcsaCloseMatch,
|
||||
fmcsa_matches: fmcsaMatches.slice(0, 10).map((r: Record<string, unknown>) => ({
|
||||
dot_number: r.dot_number,
|
||||
legal_name: r.legal_name,
|
||||
dba_name: r.dba_name,
|
||||
state: r.phy_state,
|
||||
})),
|
||||
available: sosAvailable !== false && !fmcsaExactMatch,
|
||||
available: sosAvailable !== false && !fmcsaExactMatch && !fmcsaCloseMatch,
|
||||
message: fmcsaExactMatch
|
||||
? `"${name}" is already registered with FMCSA (DOT# ${(fmcsaMatches.find((r: Record<string, unknown>) => (r.legal_name as string || "").toUpperCase() === name.toUpperCase()) as Record<string, unknown>)?.dot_number}). Choose a different name or use your existing entity.`
|
||||
: fmcsaCloseMatch
|
||||
? `A similar name is already registered with FMCSA: "${(fmcsaMatches[0] as Record<string, unknown>)?.legal_name}" (DOT# ${(fmcsaMatches[0] as Record<string, unknown>)?.dot_number}). This may cause confusion — consider a more distinct name.`
|
||||
: sosAvailable === false
|
||||
? `"${name}" is already registered in ${stateCode}. The name may still be usable if it's your entity.`
|
||||
: sosAvailable === true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue