UNPKG

@openinc/parse-server-opendash

Version:
28 lines (27 loc) 1.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.saveTicketMeta = saveTicketMeta; async function saveTicketMeta(ticket, value, fetchOptions) { const currentMeta = ticket.get("meta") ?? { fields: [], }; if (value) { const updatedMetaFields = currentMeta.fields ?? []; const newMetaFields = []; // overriding existing fields for (const field of value.fields) { const index = updatedMetaFields.findIndex((v) => v.name === field.name); if (index === -1) newMetaFields.push(field); else updatedMetaFields[index].value = field.value; } currentMeta.fields = [...updatedMetaFields, ...newMetaFields]; ticket.set("meta", { ...currentMeta, // use all existing values ...value, // override with new values fields: currentMeta.fields, // use the updated fields }); } return await ticket.save(null, fetchOptions); }