Skip to content

Modular logistics and supply chain operating system (LSOS)

feat: add template serializer with EmbeddedRecordsMixin for queries

Ronald A Richardson92f2c32ed29f
diff --git a/console/app/serializers/template.js b/console/app/serializers/template.js
new file mode 100644
index 00000000..f93a909b
--- /dev/null
+++ b/console/app/serializers/template.js
@@ -0,0 +1,30 @@
+import ApplicationSerializer from '@fleetbase/ember-core/serializers/application';
+import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';
+
+/**
+ * Serializer for the Template model.
+ *
+ * Uses EmbeddedRecordsMixin so that the `queries` hasMany relationship is
+ * included inline in the save payload (both create and update requests).
+ * The backend TemplateController._syncQueries() reads this array and upserts
+ * or deletes TemplateQuery records accordingly.
+ *
+ * Serialization behaviour:
+ * - `queries` are embedded as `always` — they are included when serializing
+ * (save) and deserialized when normalizing (load) the template response.
+ * - The mixin's default `serializeHasMany` is suppressed for `queries` so
+ * that we can emit the plain array directly (the backend expects a flat
+ * array of query attribute objects, not JSON:API relationship links).
+ */
+export default class TemplateSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
+ /**
+ * Embedded relationship attributes.
+ *
+ * @var {Object}
+ */
+ get attrs() {
+ return {
+ queries: { embedded: 'always' },
+ };
+ }
+}