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.
- package/dist/bruce-models.es5.js +30 -44
- package/dist/bruce-models.es5.js.map +1 -1
- package/dist/bruce-models.umd.js +30 -44
- package/dist/bruce-models.umd.js.map +1 -1
- package/dist/lib/entity/entity-attachment.js +30 -44
- package/dist/lib/entity/entity-attachment.js.map +1 -1
- package/dist/types/entity/entity-attachment.d.ts +10 -17
- package/package.json +1 -1
|
@@ -18,8 +18,8 @@ const api_1 = require("../api/api");
|
|
|
18
18
|
*/
|
|
19
19
|
var EntityAttachment;
|
|
20
20
|
(function (EntityAttachment) {
|
|
21
|
-
function GetCacheKey(
|
|
22
|
-
return api_1.Api.ECacheKey.Attachment + api_1.Api.ECacheKey.Id +
|
|
21
|
+
function GetCacheKey(id) {
|
|
22
|
+
return api_1.Api.ECacheKey.Attachment + api_1.Api.ECacheKey.Id + id;
|
|
23
23
|
}
|
|
24
24
|
EntityAttachment.GetCacheKey = GetCacheKey;
|
|
25
25
|
function GetListCacheKey(entityId) {
|
|
@@ -28,33 +28,40 @@ var EntityAttachment;
|
|
|
28
28
|
EntityAttachment.GetListCacheKey = GetListCacheKey;
|
|
29
29
|
function Update(params) {
|
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
const { api,
|
|
32
|
-
if (!(
|
|
33
|
-
|
|
31
|
+
const { api, attachments, req, entityId } = params;
|
|
32
|
+
if (!(attachments === null || attachments === void 0 ? void 0 : attachments.length)) {
|
|
33
|
+
return {
|
|
34
|
+
attachments: []
|
|
35
|
+
};
|
|
34
36
|
}
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
const res = yield api.POST(`entity/${entityId}/attachments`, {
|
|
38
|
+
attachments
|
|
39
|
+
}, api_1.Api.PrepReqParams(req));
|
|
40
|
+
for (let i = 0; i < attachments.length; i++) {
|
|
41
|
+
if (attachments[i].ID) {
|
|
42
|
+
api.Cache.Remove(GetCacheKey(attachments[i].ID));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
api.Cache.Remove(GetListCacheKey(entityId));
|
|
39
46
|
return {
|
|
40
|
-
|
|
47
|
+
attachments: res.attachments
|
|
41
48
|
};
|
|
42
49
|
});
|
|
43
50
|
}
|
|
44
51
|
EntityAttachment.Update = Update;
|
|
45
52
|
function UpdateOrder(params) {
|
|
46
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
const { api, entityId, attachmentTypeId: typeId,
|
|
48
|
-
if (!entityId || !typeId || !(
|
|
49
|
-
throw ("Entity ID, Type ID, and
|
|
54
|
+
const { api, entityId, attachmentTypeId: typeId, attachments, req: reqParams } = params;
|
|
55
|
+
if (!entityId || !typeId || !(attachments === null || attachments === void 0 ? void 0 : attachments.length)) {
|
|
56
|
+
throw ("Entity ID, Type ID, and Attachments are required.");
|
|
50
57
|
}
|
|
51
58
|
const reqData = {
|
|
52
59
|
"DisplayOrder.Start": 0,
|
|
53
|
-
"ClientFile.ID":
|
|
60
|
+
"ClientFile.ID": attachments.map(x => x["ClientFile.ID"])
|
|
54
61
|
};
|
|
55
62
|
yield api.POST(`entity/${entityId}/attachments/${typeId}/setOrder`, reqData, api_1.Api.PrepReqParams(reqParams));
|
|
56
|
-
for (let i = 0; i <
|
|
57
|
-
api.Cache.Remove(GetCacheKey(
|
|
63
|
+
for (let i = 0; i < attachments.length; i++) {
|
|
64
|
+
api.Cache.Remove(GetCacheKey(attachments[i].ID));
|
|
58
65
|
}
|
|
59
66
|
api.Cache.RemoveByStartsWith(GetListCacheKey(entityId));
|
|
60
67
|
});
|
|
@@ -62,36 +69,15 @@ var EntityAttachment;
|
|
|
62
69
|
EntityAttachment.UpdateOrder = UpdateOrder;
|
|
63
70
|
function Delete(params) {
|
|
64
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
const { api,
|
|
66
|
-
if (!
|
|
67
|
-
throw ("Entity
|
|
72
|
+
const { api, attachmentId, entityId, req } = params;
|
|
73
|
+
if (!attachmentId || !entityId) {
|
|
74
|
+
throw ("Entity id and attachment id.");
|
|
68
75
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
};
|
|
72
|
-
yield api.POST(`entity/${data["Entity.ID"]}/attachments/${data["EntityAttachmentType.ID"]}/delete`, reqData, api_1.Api.PrepReqParams(reqParams));
|
|
73
|
-
api.Cache.Remove(GetCacheKey(data["Entity.ID"], data["EntityAttachmentType.ID"], data["ClientFile.ID"]));
|
|
74
|
-
api.Cache.RemoveByStartsWith(GetListCacheKey(data["Entity.ID"]));
|
|
76
|
+
yield api.DELETE(`entity/${entityId}/attachments/${attachmentId}`, api_1.Api.PrepReqParams(req));
|
|
77
|
+
api.Cache.Remove(GetCacheKey(attachmentId));
|
|
75
78
|
});
|
|
76
79
|
}
|
|
77
80
|
EntityAttachment.Delete = Delete;
|
|
78
|
-
function DeleteByFileIds(params) {
|
|
79
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
const { api, entityId, attachmentTypeId: typeId, fileIds, req: reqParams } = params;
|
|
81
|
-
if (!entityId || !typeId || !(fileIds === null || fileIds === void 0 ? void 0 : fileIds.length)) {
|
|
82
|
-
throw ("Entity ID, Type ID, and File IDs are required.");
|
|
83
|
-
}
|
|
84
|
-
const reqData = {
|
|
85
|
-
"ClientFile.ID": fileIds
|
|
86
|
-
};
|
|
87
|
-
yield api.POST(`entity/${entityId}/attachments/${typeId}/delete`, reqData, api_1.Api.PrepReqParams(reqParams));
|
|
88
|
-
for (let i = 0; i < fileIds.length; i++) {
|
|
89
|
-
api.Cache.Remove(GetCacheKey(entityId, typeId, fileIds[i]));
|
|
90
|
-
}
|
|
91
|
-
api.Cache.RemoveByStartsWith(GetListCacheKey(entityId));
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
EntityAttachment.DeleteByFileIds = DeleteByFileIds;
|
|
95
81
|
function GetListByEntityId(params) {
|
|
96
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
97
83
|
const { api, entityId, req: reqParams } = params;
|
|
@@ -106,7 +92,7 @@ var EntityAttachment;
|
|
|
106
92
|
try {
|
|
107
93
|
const data = yield api.GET(`entity/${entityId}/attachments`, api_1.Api.PrepReqParams(reqParams));
|
|
108
94
|
res({
|
|
109
|
-
attachments: data.Items
|
|
95
|
+
attachments: (data.attachments ? data.attachments : data.Items)
|
|
110
96
|
});
|
|
111
97
|
}
|
|
112
98
|
catch (e) {
|
|
@@ -126,7 +112,7 @@ var EntityAttachment;
|
|
|
126
112
|
}
|
|
127
113
|
const url = `entity/${entityId}/attachment/${typeId}`;
|
|
128
114
|
const res = yield api.UPLOAD(url, file, api_1.Api.PrepReqParams(reqParams));
|
|
129
|
-
api.Cache.
|
|
115
|
+
api.Cache.Remove(GetListCacheKey(entityId));
|
|
130
116
|
return {
|
|
131
117
|
attachment: res
|
|
132
118
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-attachment.js","sourceRoot":"","sources":["../../../src/entity/entity-attachment.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAiC;AAOjC;;;;GAIG;AACH,IAAiB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"entity-attachment.js","sourceRoot":"","sources":["../../../src/entity/entity-attachment.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAiC;AAOjC;;;;GAIG;AACH,IAAiB,gBAAgB,CAqIhC;AArID,WAAiB,gBAAgB;IAC7B,SAAgB,WAAW,CAAC,EAAU;QAClC,OAAO,SAAG,CAAC,SAAS,CAAC,UAAU,GAAG,SAAG,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,CAAC;IAC5D,CAAC;IAFe,4BAAW,cAE1B,CAAA;IAED,SAAgB,eAAe,CAAC,QAAgB;QAC5C,OAAO,SAAG,CAAC,SAAS,CAAC,UAAU,GAAG,SAAG,CAAC,SAAS,CAAC,MAAM,G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AM,GAAG,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,SAAG,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;YACtE,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC5C,OAAO;gBACH,UAAU,EAAE,GAAG;aAClB,CAAC;QACN,CAAC;KAAA;IAnBqB,uBAAM,SAmB3B,CAAA;AACL,CAAC,EArIgB,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAqIhC"}
|
|
@@ -9,43 +9,36 @@ declare type Type = EntityAttachmentType.EType | string;
|
|
|
9
9
|
* The same file can be attached to multiple entities.
|
|
10
10
|
*/
|
|
11
11
|
export declare namespace EntityAttachment {
|
|
12
|
-
function GetCacheKey(
|
|
12
|
+
function GetCacheKey(id: number): string;
|
|
13
13
|
function GetListCacheKey(entityId: string): string;
|
|
14
14
|
interface IAttachment {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
ID: number;
|
|
16
|
+
ClientFile?: ClientFile.IClientFile;
|
|
17
|
+
Group?: string;
|
|
17
18
|
"ClientFile.ID": string;
|
|
18
|
-
DisplayOrder
|
|
19
|
+
DisplayOrder?: number;
|
|
19
20
|
"Entity.ID": string;
|
|
20
21
|
"EntityAttachmentType.ID": Type;
|
|
21
22
|
}
|
|
22
|
-
interface IAttachmentUpdate extends IAttachment {
|
|
23
|
-
oldAttachmentTypeId: Type;
|
|
24
|
-
}
|
|
25
23
|
function Update(params: {
|
|
26
24
|
api: BruceApi.Api;
|
|
27
|
-
|
|
25
|
+
entityId: string;
|
|
26
|
+
attachments: IAttachment[];
|
|
28
27
|
req?: Api.IReqParams;
|
|
29
28
|
}): Promise<{
|
|
30
|
-
|
|
29
|
+
attachments: IAttachment[];
|
|
31
30
|
}>;
|
|
32
31
|
function UpdateOrder(params: {
|
|
33
32
|
api: BruceApi.Api;
|
|
34
33
|
entityId: string;
|
|
35
34
|
attachmentTypeId: Type;
|
|
36
|
-
|
|
35
|
+
attachments: IAttachment[];
|
|
37
36
|
req?: Api.IReqParams;
|
|
38
37
|
}): Promise<void>;
|
|
39
38
|
function Delete(params: {
|
|
40
|
-
api: BruceApi.Api;
|
|
41
|
-
attachment: IAttachment;
|
|
42
|
-
req?: Api.IReqParams;
|
|
43
|
-
}): Promise<void>;
|
|
44
|
-
function DeleteByFileIds(params: {
|
|
45
39
|
api: BruceApi.Api;
|
|
46
40
|
entityId: string;
|
|
47
|
-
|
|
48
|
-
fileIds: string[];
|
|
41
|
+
attachmentId: number;
|
|
49
42
|
req?: Api.IReqParams;
|
|
50
43
|
}): Promise<void>;
|
|
51
44
|
function GetListByEntityId(params: {
|