bruce-models 1.8.8 → 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.
@@ -2883,8 +2883,8 @@
2883
2883
  })(exports.EntityAttachmentType || (exports.EntityAttachmentType = {}));
2884
2884
 
2885
2885
  (function (EntityAttachment) {
2886
- function GetCacheKey(entityId, typeId, fileId) {
2887
- 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;
2888
2888
  }
2889
2889
  EntityAttachment.GetCacheKey = GetCacheKey;
2890
2890
  function GetListCacheKey(entityId) {
@@ -2893,33 +2893,40 @@
2893
2893
  EntityAttachment.GetListCacheKey = GetListCacheKey;
2894
2894
  function Update(params) {
2895
2895
  return __awaiter(this, void 0, void 0, function* () {
2896
- const { api, attachment: data, req: reqParams } = params;
2897
- 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"])) {
2898
- 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
+ }
2899
2909
  }
2900
- const url = `entity/${data["Entity.ID"]}/attachment/${data.oldAttachmentTypeId}/${data["ClientFile.ID"]}`;
2901
- const res = yield api.PUT(url, data, exports.Api.PrepReqParams(reqParams));
2902
- api.Cache.Remove(GetCacheKey(data["Entity.ID"], data["EntityAttachmentType.ID"], data["ClientFile.ID"]));
2903
- api.Cache.RemoveByStartsWith(GetListCacheKey(data["Entity.ID"]));
2910
+ api.Cache.Remove(GetListCacheKey(entityId));
2904
2911
  return {
2905
- attachment: res
2912
+ attachments: res.attachments
2906
2913
  };
2907
2914
  });
2908
2915
  }
2909
2916
  EntityAttachment.Update = Update;
2910
2917
  function UpdateOrder(params) {
2911
2918
  return __awaiter(this, void 0, void 0, function* () {
2912
- const { api, entityId, attachmentTypeId: typeId, fileIds, req: reqParams } = params;
2913
- if (!entityId || !typeId || !(fileIds === null || fileIds === void 0 ? void 0 : fileIds.length)) {
2914
- 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.");
2915
2922
  }
2916
2923
  const reqData = {
2917
2924
  "DisplayOrder.Start": 0,
2918
- "ClientFile.ID": fileIds
2925
+ "ClientFile.ID": attachments.map(x => x["ClientFile.ID"])
2919
2926
  };
2920
2927
  yield api.POST(`entity/${entityId}/attachments/${typeId}/setOrder`, reqData, exports.Api.PrepReqParams(reqParams));
2921
- for (let i = 0; i < fileIds.length; i++) {
2922
- 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));
2923
2930
  }
2924
2931
  api.Cache.RemoveByStartsWith(GetListCacheKey(entityId));
2925
2932
  });
@@ -2927,36 +2934,15 @@
2927
2934
  EntityAttachment.UpdateOrder = UpdateOrder;
2928
2935
  function Delete(params) {
2929
2936
  return __awaiter(this, void 0, void 0, function* () {
2930
- const { api, attachment: data, req: reqParams } = params;
2931
- 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"])) {
2932
- 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.");
2933
2940
  }
2934
- const reqData = {
2935
- "ClientFile.ID": [data["ClientFile.ID"]]
2936
- };
2937
- yield api.POST(`entity/${data["Entity.ID"]}/attachments/${data["EntityAttachmentType.ID"]}/delete`, reqData, exports.Api.PrepReqParams(reqParams));
2938
- api.Cache.Remove(GetCacheKey(data["Entity.ID"], data["EntityAttachmentType.ID"], data["ClientFile.ID"]));
2939
- 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));
2940
2943
  });
2941
2944
  }
2942
2945
  EntityAttachment.Delete = Delete;
2943
- function DeleteByFileIds(params) {
2944
- return __awaiter(this, void 0, void 0, function* () {
2945
- const { api, entityId, attachmentTypeId: typeId, fileIds, req: reqParams } = params;
2946
- if (!entityId || !typeId || !(fileIds === null || fileIds === void 0 ? void 0 : fileIds.length)) {
2947
- throw ("Entity ID, Type ID, and File IDs are required.");
2948
- }
2949
- const reqData = {
2950
- "ClientFile.ID": fileIds
2951
- };
2952
- yield api.POST(`entity/${entityId}/attachments/${typeId}/delete`, reqData, exports.Api.PrepReqParams(reqParams));
2953
- for (let i = 0; i < fileIds.length; i++) {
2954
- api.Cache.Remove(GetCacheKey(entityId, typeId, fileIds[i]));
2955
- }
2956
- api.Cache.RemoveByStartsWith(GetListCacheKey(entityId));
2957
- });
2958
- }
2959
- EntityAttachment.DeleteByFileIds = DeleteByFileIds;
2960
2946
  function GetListByEntityId(params) {
2961
2947
  return __awaiter(this, void 0, void 0, function* () {
2962
2948
  const { api, entityId, req: reqParams } = params;
@@ -2971,7 +2957,7 @@
2971
2957
  try {
2972
2958
  const data = yield api.GET(`entity/${entityId}/attachments`, exports.Api.PrepReqParams(reqParams));
2973
2959
  res({
2974
- attachments: data.Items
2960
+ attachments: (data.attachments ? data.attachments : data.Items)
2975
2961
  });
2976
2962
  }
2977
2963
  catch (e) {
@@ -2991,7 +2977,7 @@
2991
2977
  }
2992
2978
  const url = `entity/${entityId}/attachment/${typeId}`;
2993
2979
  const res = yield api.UPLOAD(url, file, exports.Api.PrepReqParams(reqParams));
2994
- api.Cache.RemoveByStartsWith(GetListCacheKey(entityId));
2980
+ api.Cache.Remove(GetListCacheKey(entityId));
2995
2981
  return {
2996
2982
  attachment: res
2997
2983
  };