bruce-models 1.8.7 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1973,7 +1973,9 @@
1973
1973
  const end = str.indexOf("}");
1974
1974
  if (end > -1) {
1975
1975
  if (start < end) {
1976
- return { path: str.substring(start + 2, end), text: str.substring(start, end) };
1976
+ const path = str.substring(start + 2, end);
1977
+ const txt = str.substring(start, end + 1);
1978
+ return { path: path, text: txt };
1977
1979
  }
1978
1980
  }
1979
1981
  }
@@ -2881,8 +2883,8 @@
2881
2883
  })(exports.EntityAttachmentType || (exports.EntityAttachmentType = {}));
2882
2884
 
2883
2885
  (function (EntityAttachment) {
2884
- function GetCacheKey(entityId, typeId, fileId) {
2885
- return exports.Api.ECacheKey.Attachment + exports.Api.ECacheKey.Id + entityId + exports.Api.ECacheKey.Id + typeId + exports.Api.ECacheKey.Id + fileId;
2886
+ function GetCacheKey(id) {
2887
+ return exports.Api.ECacheKey.Attachment + exports.Api.ECacheKey.Id + id;
2886
2888
  }
2887
2889
  EntityAttachment.GetCacheKey = GetCacheKey;
2888
2890
  function GetListCacheKey(entityId) {
@@ -2891,33 +2893,40 @@
2891
2893
  EntityAttachment.GetListCacheKey = GetListCacheKey;
2892
2894
  function Update(params) {
2893
2895
  return __awaiter(this, void 0, void 0, function* () {
2894
- const { api, attachment: data, req: reqParams } = params;
2895
- if (!(data === null || data === void 0 ? void 0 : data["Entity.ID"]) || !(data === null || data === void 0 ? void 0 : data["EntityAttachmentType.ID"]) || !(data === null || data === void 0 ? void 0 : data["ClientFile.ID"])) {
2896
- throw ("Entity ID, Type ID, and File ID are required.");
2896
+ const { api, attachments, req, entityId } = params;
2897
+ if (!(attachments === null || attachments === void 0 ? void 0 : attachments.length)) {
2898
+ return {
2899
+ attachments: []
2900
+ };
2901
+ }
2902
+ const res = yield api.POST(`entity/${entityId}/attachments`, {
2903
+ attachments
2904
+ }, exports.Api.PrepReqParams(req));
2905
+ for (let i = 0; i < attachments.length; i++) {
2906
+ if (attachments[i].ID) {
2907
+ api.Cache.Remove(GetCacheKey(attachments[i].ID));
2908
+ }
2897
2909
  }
2898
- const url = `entity/${data["Entity.ID"]}/attachment/${data.oldAttachmentTypeId}/${data["ClientFile.ID"]}`;
2899
- const res = yield api.PUT(url, data, exports.Api.PrepReqParams(reqParams));
2900
- api.Cache.Remove(GetCacheKey(data["Entity.ID"], data["EntityAttachmentType.ID"], data["ClientFile.ID"]));
2901
- api.Cache.RemoveByStartsWith(GetListCacheKey(data["Entity.ID"]));
2910
+ api.Cache.Remove(GetListCacheKey(entityId));
2902
2911
  return {
2903
- attachment: res
2912
+ attachments: res.attachments
2904
2913
  };
2905
2914
  });
2906
2915
  }
2907
2916
  EntityAttachment.Update = Update;
2908
2917
  function UpdateOrder(params) {
2909
2918
  return __awaiter(this, void 0, void 0, function* () {
2910
- const { api, entityId, attachmentTypeId: typeId, fileIds, req: reqParams } = params;
2911
- if (!entityId || !typeId || !(fileIds === null || fileIds === void 0 ? void 0 : fileIds.length)) {
2912
- throw ("Entity ID, Type ID, and File IDs are required.");
2919
+ const { api, entityId, attachmentTypeId: typeId, attachments, req: reqParams } = params;
2920
+ if (!entityId || !typeId || !(attachments === null || attachments === void 0 ? void 0 : attachments.length)) {
2921
+ throw ("Entity ID, Type ID, and Attachments are required.");
2913
2922
  }
2914
2923
  const reqData = {
2915
2924
  "DisplayOrder.Start": 0,
2916
- "ClientFile.ID": fileIds
2925
+ "ClientFile.ID": attachments.map(x => x["ClientFile.ID"])
2917
2926
  };
2918
2927
  yield api.POST(`entity/${entityId}/attachments/${typeId}/setOrder`, reqData, exports.Api.PrepReqParams(reqParams));
2919
- for (let i = 0; i < fileIds.length; i++) {
2920
- api.Cache.Remove(GetCacheKey(entityId, typeId, fileIds[i]));
2928
+ for (let i = 0; i < attachments.length; i++) {
2929
+ api.Cache.Remove(GetCacheKey(attachments[i].ID));
2921
2930
  }
2922
2931
  api.Cache.RemoveByStartsWith(GetListCacheKey(entityId));
2923
2932
  });
@@ -2925,36 +2934,15 @@
2925
2934
  EntityAttachment.UpdateOrder = UpdateOrder;
2926
2935
  function Delete(params) {
2927
2936
  return __awaiter(this, void 0, void 0, function* () {
2928
- const { api, attachment: data, req: reqParams } = params;
2929
- if (!(data === null || data === void 0 ? void 0 : data["Entity.ID"]) || !(data === null || data === void 0 ? void 0 : data["EntityAttachmentType.ID"]) || !(data === null || data === void 0 ? void 0 : data["ClientFile.ID"])) {
2930
- throw ("Entity ID, Type ID, and File ID are required.");
2937
+ const { api, attachmentId, entityId, req } = params;
2938
+ if (!attachmentId || !entityId) {
2939
+ throw ("Entity id and attachment id.");
2931
2940
  }
2932
- const reqData = {
2933
- "ClientFile.ID": [data["ClientFile.ID"]]
2934
- };
2935
- yield api.POST(`entity/${data["Entity.ID"]}/attachments/${data["EntityAttachmentType.ID"]}/delete`, reqData, exports.Api.PrepReqParams(reqParams));
2936
- api.Cache.Remove(GetCacheKey(data["Entity.ID"], data["EntityAttachmentType.ID"], data["ClientFile.ID"]));
2937
- api.Cache.RemoveByStartsWith(GetListCacheKey(data["Entity.ID"]));
2941
+ yield api.DELETE(`entity/${entityId}/attachments/${attachmentId}`, exports.Api.PrepReqParams(req));
2942
+ api.Cache.Remove(GetCacheKey(attachmentId));
2938
2943
  });
2939
2944
  }
2940
2945
  EntityAttachment.Delete = Delete;
2941
- function DeleteByFileIds(params) {
2942
- return __awaiter(this, void 0, void 0, function* () {
2943
- const { api, entityId, attachmentTypeId: typeId, fileIds, req: reqParams } = params;
2944
- if (!entityId || !typeId || !(fileIds === null || fileIds === void 0 ? void 0 : fileIds.length)) {
2945
- throw ("Entity ID, Type ID, and File IDs are required.");
2946
- }
2947
- const reqData = {
2948
- "ClientFile.ID": fileIds
2949
- };
2950
- yield api.POST(`entity/${entityId}/attachments/${typeId}/delete`, reqData, exports.Api.PrepReqParams(reqParams));
2951
- for (let i = 0; i < fileIds.length; i++) {
2952
- api.Cache.Remove(GetCacheKey(entityId, typeId, fileIds[i]));
2953
- }
2954
- api.Cache.RemoveByStartsWith(GetListCacheKey(entityId));
2955
- });
2956
- }
2957
- EntityAttachment.DeleteByFileIds = DeleteByFileIds;
2958
2946
  function GetListByEntityId(params) {
2959
2947
  return __awaiter(this, void 0, void 0, function* () {
2960
2948
  const { api, entityId, req: reqParams } = params;
@@ -2969,7 +2957,7 @@
2969
2957
  try {
2970
2958
  const data = yield api.GET(`entity/${entityId}/attachments`, exports.Api.PrepReqParams(reqParams));
2971
2959
  res({
2972
- attachments: data.Items
2960
+ attachments: (data.attachments ? data.attachments : data.Items)
2973
2961
  });
2974
2962
  }
2975
2963
  catch (e) {
@@ -2989,7 +2977,7 @@
2989
2977
  }
2990
2978
  const url = `entity/${entityId}/attachment/${typeId}`;
2991
2979
  const res = yield api.UPLOAD(url, file, exports.Api.PrepReqParams(reqParams));
2992
- api.Cache.RemoveByStartsWith(GetListCacheKey(entityId));
2980
+ api.Cache.Remove(GetListCacheKey(entityId));
2993
2981
  return {
2994
2982
  attachment: res
2995
2983
  };