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.
@@ -2941,8 +2941,8 @@ var EntityAttachmentType;
2941
2941
  */
2942
2942
  var EntityAttachment;
2943
2943
  (function (EntityAttachment) {
2944
- function GetCacheKey(entityId, typeId, fileId) {
2945
- return Api.ECacheKey.Attachment + Api.ECacheKey.Id + entityId + Api.ECacheKey.Id + typeId + Api.ECacheKey.Id + fileId;
2944
+ function GetCacheKey(id) {
2945
+ return Api.ECacheKey.Attachment + Api.ECacheKey.Id + id;
2946
2946
  }
2947
2947
  EntityAttachment.GetCacheKey = GetCacheKey;
2948
2948
  function GetListCacheKey(entityId) {
@@ -2951,33 +2951,40 @@ var EntityAttachment;
2951
2951
  EntityAttachment.GetListCacheKey = GetListCacheKey;
2952
2952
  function Update(params) {
2953
2953
  return __awaiter(this, void 0, void 0, function* () {
2954
- const { api, attachment: data, req: reqParams } = params;
2955
- 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"])) {
2956
- throw ("Entity ID, Type ID, and File ID are required.");
2954
+ const { api, attachments, req, entityId } = params;
2955
+ if (!(attachments === null || attachments === void 0 ? void 0 : attachments.length)) {
2956
+ return {
2957
+ attachments: []
2958
+ };
2959
+ }
2960
+ const res = yield api.POST(`entity/${entityId}/attachments`, {
2961
+ attachments
2962
+ }, Api.PrepReqParams(req));
2963
+ for (let i = 0; i < attachments.length; i++) {
2964
+ if (attachments[i].ID) {
2965
+ api.Cache.Remove(GetCacheKey(attachments[i].ID));
2966
+ }
2957
2967
  }
2958
- const url = `entity/${data["Entity.ID"]}/attachment/${data.oldAttachmentTypeId}/${data["ClientFile.ID"]}`;
2959
- const res = yield api.PUT(url, data, Api.PrepReqParams(reqParams));
2960
- api.Cache.Remove(GetCacheKey(data["Entity.ID"], data["EntityAttachmentType.ID"], data["ClientFile.ID"]));
2961
- api.Cache.RemoveByStartsWith(GetListCacheKey(data["Entity.ID"]));
2968
+ api.Cache.Remove(GetListCacheKey(entityId));
2962
2969
  return {
2963
- attachment: res
2970
+ attachments: res.attachments
2964
2971
  };
2965
2972
  });
2966
2973
  }
2967
2974
  EntityAttachment.Update = Update;
2968
2975
  function UpdateOrder(params) {
2969
2976
  return __awaiter(this, void 0, void 0, function* () {
2970
- const { api, entityId, attachmentTypeId: typeId, fileIds, req: reqParams } = params;
2971
- if (!entityId || !typeId || !(fileIds === null || fileIds === void 0 ? void 0 : fileIds.length)) {
2972
- throw ("Entity ID, Type ID, and File IDs are required.");
2977
+ const { api, entityId, attachmentTypeId: typeId, attachments, req: reqParams } = params;
2978
+ if (!entityId || !typeId || !(attachments === null || attachments === void 0 ? void 0 : attachments.length)) {
2979
+ throw ("Entity ID, Type ID, and Attachments are required.");
2973
2980
  }
2974
2981
  const reqData = {
2975
2982
  "DisplayOrder.Start": 0,
2976
- "ClientFile.ID": fileIds
2983
+ "ClientFile.ID": attachments.map(x => x["ClientFile.ID"])
2977
2984
  };
2978
2985
  yield api.POST(`entity/${entityId}/attachments/${typeId}/setOrder`, reqData, Api.PrepReqParams(reqParams));
2979
- for (let i = 0; i < fileIds.length; i++) {
2980
- api.Cache.Remove(GetCacheKey(entityId, typeId, fileIds[i]));
2986
+ for (let i = 0; i < attachments.length; i++) {
2987
+ api.Cache.Remove(GetCacheKey(attachments[i].ID));
2981
2988
  }
2982
2989
  api.Cache.RemoveByStartsWith(GetListCacheKey(entityId));
2983
2990
  });
@@ -2985,36 +2992,15 @@ var EntityAttachment;
2985
2992
  EntityAttachment.UpdateOrder = UpdateOrder;
2986
2993
  function Delete(params) {
2987
2994
  return __awaiter(this, void 0, void 0, function* () {
2988
- const { api, attachment: data, req: reqParams } = params;
2989
- 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"])) {
2990
- throw ("Entity ID, Type ID, and File ID are required.");
2995
+ const { api, attachmentId, entityId, req } = params;
2996
+ if (!attachmentId || !entityId) {
2997
+ throw ("Entity id and attachment id.");
2991
2998
  }
2992
- const reqData = {
2993
- "ClientFile.ID": [data["ClientFile.ID"]]
2994
- };
2995
- yield api.POST(`entity/${data["Entity.ID"]}/attachments/${data["EntityAttachmentType.ID"]}/delete`, reqData, Api.PrepReqParams(reqParams));
2996
- api.Cache.Remove(GetCacheKey(data["Entity.ID"], data["EntityAttachmentType.ID"], data["ClientFile.ID"]));
2997
- api.Cache.RemoveByStartsWith(GetListCacheKey(data["Entity.ID"]));
2999
+ yield api.DELETE(`entity/${entityId}/attachments/${attachmentId}`, Api.PrepReqParams(req));
3000
+ api.Cache.Remove(GetCacheKey(attachmentId));
2998
3001
  });
2999
3002
  }
3000
3003
  EntityAttachment.Delete = Delete;
3001
- function DeleteByFileIds(params) {
3002
- return __awaiter(this, void 0, void 0, function* () {
3003
- const { api, entityId, attachmentTypeId: typeId, fileIds, req: reqParams } = params;
3004
- if (!entityId || !typeId || !(fileIds === null || fileIds === void 0 ? void 0 : fileIds.length)) {
3005
- throw ("Entity ID, Type ID, and File IDs are required.");
3006
- }
3007
- const reqData = {
3008
- "ClientFile.ID": fileIds
3009
- };
3010
- yield api.POST(`entity/${entityId}/attachments/${typeId}/delete`, reqData, Api.PrepReqParams(reqParams));
3011
- for (let i = 0; i < fileIds.length; i++) {
3012
- api.Cache.Remove(GetCacheKey(entityId, typeId, fileIds[i]));
3013
- }
3014
- api.Cache.RemoveByStartsWith(GetListCacheKey(entityId));
3015
- });
3016
- }
3017
- EntityAttachment.DeleteByFileIds = DeleteByFileIds;
3018
3004
  function GetListByEntityId(params) {
3019
3005
  return __awaiter(this, void 0, void 0, function* () {
3020
3006
  const { api, entityId, req: reqParams } = params;
@@ -3029,7 +3015,7 @@ var EntityAttachment;
3029
3015
  try {
3030
3016
  const data = yield api.GET(`entity/${entityId}/attachments`, Api.PrepReqParams(reqParams));
3031
3017
  res({
3032
- attachments: data.Items
3018
+ attachments: (data.attachments ? data.attachments : data.Items)
3033
3019
  });
3034
3020
  }
3035
3021
  catch (e) {
@@ -3049,7 +3035,7 @@ var EntityAttachment;
3049
3035
  }
3050
3036
  const url = `entity/${entityId}/attachment/${typeId}`;
3051
3037
  const res = yield api.UPLOAD(url, file, Api.PrepReqParams(reqParams));
3052
- api.Cache.RemoveByStartsWith(GetListCacheKey(entityId));
3038
+ api.Cache.Remove(GetListCacheKey(entityId));
3053
3039
  return {
3054
3040
  attachment: res
3055
3041
  };