commit 83c9e84000582b3f84a71c9b9856e0b051b4954e
parent 5fecdafb3b8e608ef6411412cbc7d58b8e28476a
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Sat, 19 Oct 2024 09:41:28 -0700
Add some more furniture validation
Verify the name is unique, and that the type exists and the style
exists for the type.
Diffstat:
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/files/floorplans/floorplan/backend.js b/files/floorplans/floorplan/backend.js
@@ -548,6 +548,7 @@ export class FloorplanBackend {
}
addFurniture(params, id) {
+ let backend = this
const f = this.updatedObject(params, id, {
width: {
required: true,
@@ -559,10 +560,22 @@ export class FloorplanBackend {
},
type: {
required: true,
- type: "string"
+ type: "string",
+ validate: function(type) {
+ return backend.params.furniture[type] != null
+ }
},
name: {
- type: "string"
+ type: "string",
+ validate: function(name) {
+ let maps = backend.cache.furniture
+ for (let k in maps) {
+ if (k != id && maps[k].name != null && maps[k].name === name) {
+ return false
+ }
+ }
+ return true
+ }
},
// Could do with verifying this
style: {
@@ -570,6 +583,10 @@ export class FloorplanBackend {
}
})
+ if (f.style != null && this.params.furniture[f.type].styles.indexOf(f.style) < 0) {
+ throw new Error(`${f.style} style for ${f.type} type: Invalid style for type`)
+ }
+
return this.addData(id ?? "furniture", f)
}