1
0
Fork 0
mirror of synced 2024-08-19 03:51:29 +12:00

PR comments.

This commit is contained in:
mike12345567 2023-02-02 16:19:50 +00:00
parent 1704a1f266
commit 21556c215a
2 changed files with 40 additions and 41 deletions

View file

@ -120,14 +120,12 @@
} }
function getErrorCount(errors) { function getErrorCount(errors) {
return Object.entries(errors) return Object.entries(errors).filter(entry => !!entry[1]).length
.filter(entry => !!entry[1])
.map(entry => entry[0]).length
} }
function allRequiredAttributesSet() { function allRequiredAttributesSet() {
const base = fromTable && toTable && fromColumn && toColumn const base = fromTable && toTable && fromColumn && toColumn
if (isManyToOne) { if (relationshipType === RelationshipTypes.MANY_TO_ONE) {
return base && fromPrimary && fromForeign return base && fromPrimary && fromForeign
} else { } else {
return base && throughTable && throughFromKey && throughToKey return base && throughTable && throughFromKey && throughToKey
@ -140,39 +138,37 @@
} }
hasValidated = true hasValidated = true
errorChecker.setType(relationshipType) errorChecker.setType(relationshipType)
const errObj = {} errors = {
errObj.relationshipType = errorChecker.relationshipTypeSet(relationshipType) relationshipType: errorChecker.relationshipTypeSet(relationshipType),
errObj.fromTable = errorChecker.tableSet(fromTable) fromTable:
errObj.toTable = errorChecker.tableSet(toTable) errorChecker.tableSet(fromTable) ||
errObj.throughTable = errorChecker.throughTableSet(throughTable) errorChecker.doesRelationshipExists() ||
errObj.throughFromKey = errorChecker.manyForeignKeySet(throughFromKey) errorChecker.differentTables(fromId, toId, throughId),
errObj.throughToKey = errorChecker.manyForeignKeySet(throughToKey) toTable:
errObj.throughTable = errorChecker.throughIsNullable() errorChecker.tableSet(toTable) ||
errObj.fromForeign = errorChecker.foreignKeySet(fromForeign) errorChecker.doesRelationshipExists() ||
errObj.fromPrimary = errorChecker.primaryKeySet(fromPrimary) errorChecker.differentTables(toId, fromId, throughId),
errObj.fromTable = errorChecker.doesRelationshipExists() throughTable:
errObj.toTable = errorChecker.doesRelationshipExists() errorChecker.throughTableSet(throughTable) ||
// currently don't support relationships back onto the table itself, needs to relate out errorChecker.throughIsNullable() ||
errObj.fromTable = errorChecker.differentTables(fromId, toId, throughId) errorChecker.differentTables(throughId, fromId, toId),
errObj.toTable = errorChecker.differentTables(toId, fromId, throughId) throughFromKey: errorChecker.manyForeignKeySet(throughFromKey),
errObj.throughTable = errorChecker.differentTables(throughId, fromId, toId) throughToKey: errorChecker.manyForeignKeySet(throughToKey),
errObj.fromColumn = errorChecker.columnBeingUsed( fromForeign:
toTable, errorChecker.foreignKeySet(fromForeign) ||
fromColumn, errorChecker.typeMismatch(fromTable, toTable, fromPrimary, fromForeign),
originalFromColumnName fromPrimary: errorChecker.primaryKeySet(fromPrimary),
) fromColumn: errorChecker.columnBeingUsed(
errObj.toColumn = errorChecker.columnBeingUsed( toTable,
fromTable, fromColumn,
toColumn, originalFromColumnName
originalToColumnName ),
) toColumn: errorChecker.columnBeingUsed(
errObj.fromForeign = errorChecker.typeMismatch( fromTable,
fromTable, toColumn,
toTable, originalToColumnName
fromPrimary, ),
fromForeign }
)
errors = errObj
return getErrorCount(errors) === 0 return getErrorCount(errors) === 0
} }
@ -285,7 +281,7 @@
} }
function changed(fn) { function changed(fn) {
if (fn && typeof fn === "function") { if (typeof fn === "function") {
fn() fn()
} }
validate() validate()
@ -325,7 +321,10 @@
options={relationshipTypes} options={relationshipTypes}
bind:value={relationshipType} bind:value={relationshipType}
bind:error={errors.relationshipType} bind:error={errors.relationshipType}
on:change={changed} on:change={() =>
changed(() => {
hasValidated = false
})}
/> />
<div class="headings"> <div class="headings">
<Detail>Tables</Detail> <Detail>Tables</Detail>

View file

@ -1,7 +1,7 @@
import { RelationshipTypes } from "constants/backend" import { RelationshipTypes } from "constants/backend"
const typeMismatch = "Column type of the foreign key must match the primary key" const typeMismatch = "Column type of the foreign key must match the primary key"
const columnCantExist = "Column name cannot be an existing column" const columnBeingUsed = "Column name cannot be an existing column"
const mustBeDifferentTables = "From/to/through tables must be different" const mustBeDifferentTables = "From/to/through tables must be different"
const primaryKeyNotSet = "Please pick the primary key" const primaryKeyNotSet = "Please pick the primary key"
const throughNotNullable = const throughNotNullable =
@ -75,7 +75,7 @@ export class RelationshipErrorChecker {
} }
columnBeingUsed(table, column, ogName) { columnBeingUsed(table, column, ogName) {
return isColumnNameBeingUsed(table, column, ogName) ? columnCantExist : null return isColumnNameBeingUsed(table, column, ogName) ? columnBeingUsed : null
} }
typeMismatch(fromTable, toTable, primary, foreign) { typeMismatch(fromTable, toTable, primary, foreign) {