@qrvey/assets-sharing 0.0.1
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/.eslintrc +88 -0
- package/README.md +18 -0
- package/dist/cjs/common/common.type.js +3 -0
- package/dist/cjs/common/common.type.js.map +1 -0
- package/dist/cjs/common/constants.js +37 -0
- package/dist/cjs/common/constants.js.map +1 -0
- package/dist/cjs/common/persistence/base.js +15 -0
- package/dist/cjs/common/persistence/base.js.map +1 -0
- package/dist/cjs/common/persistence/poolClient.js +11 -0
- package/dist/cjs/common/persistence/poolClient.js.map +1 -0
- package/dist/cjs/context.js +10 -0
- package/dist/cjs/context.js.map +1 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/sharing/entities/details.js +109 -0
- package/dist/cjs/sharing/entities/details.js.map +1 -0
- package/dist/cjs/sharing/entities/sharing.js +63 -0
- package/dist/cjs/sharing/entities/sharing.js.map +1 -0
- package/dist/cjs/sharing/entities/types/details.type.js +3 -0
- package/dist/cjs/sharing/entities/types/details.type.js.map +1 -0
- package/dist/cjs/sharing/entities/types/sharing.type.js +3 -0
- package/dist/cjs/sharing/entities/types/sharing.type.js.map +1 -0
- package/dist/cjs/sharing/implementations/details.model.js +93 -0
- package/dist/cjs/sharing/implementations/details.model.js.map +1 -0
- package/dist/cjs/sharing/implementations/details.repository.js +63 -0
- package/dist/cjs/sharing/implementations/details.repository.js.map +1 -0
- package/dist/cjs/sharing/implementations/sharing.model.js +33 -0
- package/dist/cjs/sharing/implementations/sharing.model.js.map +1 -0
- package/dist/cjs/sharing/implementations/sharing.repository.js +31 -0
- package/dist/cjs/sharing/implementations/sharing.repository.js.map +1 -0
- package/dist/cjs/sharing/interfaces/details.interface.js +3 -0
- package/dist/cjs/sharing/interfaces/details.interface.js.map +1 -0
- package/dist/cjs/sharing/interfaces/sharingRepository.interface.js +3 -0
- package/dist/cjs/sharing/interfaces/sharingRepository.interface.js.map +1 -0
- package/dist/cjs/sharing/services/checkUserAccessLevel.js +44 -0
- package/dist/cjs/sharing/services/checkUserAccessLevel.js.map +1 -0
- package/dist/cjs/sharing/services/delete.js +32 -0
- package/dist/cjs/sharing/services/delete.js.map +1 -0
- package/dist/cjs/sharing/services/list.js +39 -0
- package/dist/cjs/sharing/services/list.js.map +1 -0
- package/dist/cjs/sharing/services/upsert.js +80 -0
- package/dist/cjs/sharing/services/upsert.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/esm/index.mjs +631 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/index.d.ts +108 -0
- package/package.json +50 -0
- package/src/common/common.type.ts +27 -0
- package/src/common/constants.ts +36 -0
- package/src/common/persistence/base.ts +13 -0
- package/src/common/persistence/poolClient.ts +7 -0
- package/src/context.ts +17 -0
- package/src/index.ts +29 -0
- package/src/sharing/entities/details.ts +143 -0
- package/src/sharing/entities/sharing.ts +84 -0
- package/src/sharing/entities/types/details.type.ts +58 -0
- package/src/sharing/entities/types/sharing.type.ts +24 -0
- package/src/sharing/implementations/details.model.ts +93 -0
- package/src/sharing/implementations/details.repository.ts +85 -0
- package/src/sharing/implementations/sharing.model.ts +33 -0
- package/src/sharing/implementations/sharing.repository.ts +36 -0
- package/src/sharing/interfaces/details.interface.ts +45 -0
- package/src/sharing/interfaces/sharingRepository.interface.ts +32 -0
- package/src/sharing/services/checkUserAccessLevel.ts +40 -0
- package/src/sharing/services/delete.ts +24 -0
- package/src/sharing/services/list.ts +45 -0
- package/src/sharing/services/upsert.ts +111 -0
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.json +19 -0
- package/tsup.config.cjs.ts +11 -0
- package/tsup.config.esm.ts +12 -0
- package/tsup.config.types.ts +9 -0
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { container, injectable, inject } from 'tsyringe';
|
|
3
|
+
import { CrudSchema, CrudService, buildFilter, getDbPool } from '@qrvey/data-persistence';
|
|
4
|
+
import { getId } from '@qrvey/id-generator';
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __defProps = Object.defineProperties;
|
|
8
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
10
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
+
var __spreadValues = (a, b) => {
|
|
15
|
+
for (var prop in b || (b = {}))
|
|
16
|
+
if (__hasOwnProp.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
if (__getOwnPropSymbols)
|
|
19
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
+
if (__propIsEnum.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
};
|
|
25
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
27
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
28
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
29
|
+
if (decorator = decorators[i])
|
|
30
|
+
result = (decorator(result)) || result;
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
34
|
+
|
|
35
|
+
// src/common/constants.ts
|
|
36
|
+
var ENVIRONMENT = {
|
|
37
|
+
SERVER_PREFIX: process.env.SERVER_PREFIX,
|
|
38
|
+
TABLE_PREFIX: process.env.TABLE_PREFIX
|
|
39
|
+
};
|
|
40
|
+
var DATABASE_INFO = {
|
|
41
|
+
DATA_PERSISTENCE_SCHEMA: "admin",
|
|
42
|
+
SERVER_PREFIX: ENVIRONMENT.SERVER_PREFIX,
|
|
43
|
+
TABLE_PREFIX: ENVIRONMENT.TABLE_PREFIX
|
|
44
|
+
};
|
|
45
|
+
var ORGANIZATION_QRVEY = "org:0";
|
|
46
|
+
var ASSET_TYPE = /* @__PURE__ */ ((ASSET_TYPE3) => {
|
|
47
|
+
ASSET_TYPE3["DX"] = "DX";
|
|
48
|
+
return ASSET_TYPE3;
|
|
49
|
+
})(ASSET_TYPE || {});
|
|
50
|
+
var SHARED_ORIGIN = /* @__PURE__ */ ((SHARED_ORIGIN4) => {
|
|
51
|
+
SHARED_ORIGIN4["INTERNAL"] = "INTERNAL";
|
|
52
|
+
SHARED_ORIGIN4["EXTERNAL"] = "EXTERNAL";
|
|
53
|
+
return SHARED_ORIGIN4;
|
|
54
|
+
})(SHARED_ORIGIN || {});
|
|
55
|
+
var SHARE_TYPE = /* @__PURE__ */ ((SHARE_TYPE4) => {
|
|
56
|
+
SHARE_TYPE4["USER"] = "USER";
|
|
57
|
+
SHARE_TYPE4["ROLE"] = "ROLE";
|
|
58
|
+
SHARE_TYPE4["ORGANIZATION"] = "ORGANIZATION";
|
|
59
|
+
return SHARE_TYPE4;
|
|
60
|
+
})(SHARE_TYPE || {});
|
|
61
|
+
var ACCESS_LEVEL = /* @__PURE__ */ ((ACCESS_LEVEL3) => {
|
|
62
|
+
ACCESS_LEVEL3[ACCESS_LEVEL3["NONE"] = 0] = "NONE";
|
|
63
|
+
ACCESS_LEVEL3[ACCESS_LEVEL3["CAN_USE"] = 1] = "CAN_USE";
|
|
64
|
+
ACCESS_LEVEL3[ACCESS_LEVEL3["CAN_EDIT"] = 2] = "CAN_EDIT";
|
|
65
|
+
ACCESS_LEVEL3[ACCESS_LEVEL3["ADMIN"] = 4] = "ADMIN";
|
|
66
|
+
return ACCESS_LEVEL3;
|
|
67
|
+
})(ACCESS_LEVEL || {});
|
|
68
|
+
var LIMIT_PER_PAGE = 10;
|
|
69
|
+
|
|
70
|
+
// src/sharing/implementations/details.model.ts
|
|
71
|
+
var SharingDetailsModel = class extends CrudSchema {
|
|
72
|
+
};
|
|
73
|
+
SharingDetailsModel.table = {
|
|
74
|
+
name: `${DATABASE_INFO.SERVER_PREFIX}_sharing_details`,
|
|
75
|
+
alias: `${DATABASE_INFO.TABLE_PREFIX}_sharing_details`
|
|
76
|
+
};
|
|
77
|
+
SharingDetailsModel.columns = {
|
|
78
|
+
sharing_details_id: { type: "string", primary: true },
|
|
79
|
+
asset_id: { type: "string" },
|
|
80
|
+
access_level: { type: "numeric" },
|
|
81
|
+
org_id: { type: "string" },
|
|
82
|
+
shared_with: { type: "string" },
|
|
83
|
+
shared_type: { type: "string" },
|
|
84
|
+
shared_email: { type: "string" },
|
|
85
|
+
share_origin: { type: "string" },
|
|
86
|
+
created_at: { type: "date" },
|
|
87
|
+
updated_at: { type: "date" },
|
|
88
|
+
deleted_at: { type: "date" }
|
|
89
|
+
};
|
|
90
|
+
SharingDetailsModel.indexes = {
|
|
91
|
+
sharingDetailsOrgId: {
|
|
92
|
+
name: "sharing_details_org_id_index",
|
|
93
|
+
columns: [
|
|
94
|
+
"org_id",
|
|
95
|
+
"asset_id",
|
|
96
|
+
"sharing_details_id",
|
|
97
|
+
"shared_with",
|
|
98
|
+
"shared_type",
|
|
99
|
+
"shared_email",
|
|
100
|
+
"share_origin"
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
sharingDetailsSharedWithAccessLevel: {
|
|
104
|
+
name: "sharing_details_shared_with_access_level_index",
|
|
105
|
+
columns: [
|
|
106
|
+
"shared_with",
|
|
107
|
+
"access_level",
|
|
108
|
+
"asset_id",
|
|
109
|
+
"sharing_details_id",
|
|
110
|
+
"org_id",
|
|
111
|
+
"shared_type",
|
|
112
|
+
"shared_email",
|
|
113
|
+
"share_origin"
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
sharingDetailsAccessLevelSharedWithOrgId: {
|
|
117
|
+
name: "sharing_details_access_level_shared_with_org_id_index",
|
|
118
|
+
columns: [
|
|
119
|
+
"access_level",
|
|
120
|
+
"shared_with",
|
|
121
|
+
"org_id",
|
|
122
|
+
"asset_id",
|
|
123
|
+
"sharing_details_id",
|
|
124
|
+
"shared_type",
|
|
125
|
+
"shared_email",
|
|
126
|
+
"share_origin"
|
|
127
|
+
]
|
|
128
|
+
},
|
|
129
|
+
sharingDetailsAccessLevelOrgId: {
|
|
130
|
+
name: "sharing_details_access_level_org_id_index",
|
|
131
|
+
columns: [
|
|
132
|
+
"access_level",
|
|
133
|
+
"org_id",
|
|
134
|
+
"asset_id",
|
|
135
|
+
"sharing_details_id",
|
|
136
|
+
"shared_with",
|
|
137
|
+
"shared_type",
|
|
138
|
+
"shared_email",
|
|
139
|
+
"share_origin"
|
|
140
|
+
]
|
|
141
|
+
},
|
|
142
|
+
sharingDetailsAssetId: {
|
|
143
|
+
name: "sharing_details_asset_id_index",
|
|
144
|
+
columns: [
|
|
145
|
+
"asset_id",
|
|
146
|
+
"sharing_details_id",
|
|
147
|
+
"org_id",
|
|
148
|
+
"shared_with",
|
|
149
|
+
"shared_type",
|
|
150
|
+
"shared_email",
|
|
151
|
+
"share_origin"
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
SharingDetailsModel.schema = DATABASE_INFO.DATA_PERSISTENCE_SCHEMA;
|
|
156
|
+
SharingDetailsModel.usePool = true;
|
|
157
|
+
var poolClient;
|
|
158
|
+
function getPoolClient() {
|
|
159
|
+
if (!poolClient)
|
|
160
|
+
poolClient = getDbPool();
|
|
161
|
+
return poolClient;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// src/common/persistence/base.ts
|
|
165
|
+
var BaseRepository = class extends CrudService {
|
|
166
|
+
constructor(schema) {
|
|
167
|
+
super(schema, getPoolClient());
|
|
168
|
+
}
|
|
169
|
+
filter(attribute, value) {
|
|
170
|
+
return buildFilter(attribute, value);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// src/sharing/implementations/details.repository.ts
|
|
175
|
+
var SharingDetailsRepository = class extends BaseRepository {
|
|
176
|
+
constructor() {
|
|
177
|
+
super(SharingDetailsModel);
|
|
178
|
+
}
|
|
179
|
+
async getOne(sharingDetailId) {
|
|
180
|
+
const params = {
|
|
181
|
+
filters: [this.filter("sharing_details_id", sharingDetailId)]
|
|
182
|
+
};
|
|
183
|
+
const response = await super.findItem(params);
|
|
184
|
+
return response;
|
|
185
|
+
}
|
|
186
|
+
async getList(options) {
|
|
187
|
+
const assetIndex = SharingDetailsModel.indexes.sharingDetailsAssetId;
|
|
188
|
+
const pagination = this.getPagination(options.pagination);
|
|
189
|
+
const params = {
|
|
190
|
+
pagination,
|
|
191
|
+
index: {
|
|
192
|
+
indexName: assetIndex.name,
|
|
193
|
+
columns: assetIndex.columns
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
const filterList = [this.filter("asset_id", options.data.assetId)];
|
|
197
|
+
if (options.filters) {
|
|
198
|
+
options.filters.forEach((filter) => {
|
|
199
|
+
filterList.push(this.filter(filter.column, filter.value));
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
params.filters = filterList;
|
|
203
|
+
if (options.sorting)
|
|
204
|
+
params.sorting = options.sorting;
|
|
205
|
+
const response = await super.find(params);
|
|
206
|
+
return response;
|
|
207
|
+
}
|
|
208
|
+
async create(details) {
|
|
209
|
+
const response = await super.create(details);
|
|
210
|
+
return response;
|
|
211
|
+
}
|
|
212
|
+
async patch(sharingDetailId, details) {
|
|
213
|
+
await super.update(
|
|
214
|
+
[this.filter("sharing_details_id", sharingDetailId)],
|
|
215
|
+
details
|
|
216
|
+
);
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
async delete(sharingDetailId) {
|
|
220
|
+
await super.remove([
|
|
221
|
+
this.filter("sharing_details_id", sharingDetailId)
|
|
222
|
+
]);
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
getPagination(options) {
|
|
226
|
+
var _a, _b;
|
|
227
|
+
return {
|
|
228
|
+
limit: (_a = options == null ? void 0 : options.limit) != null ? _a : LIMIT_PER_PAGE,
|
|
229
|
+
from: (_b = options == null ? void 0 : options.from) != null ? _b : void 0
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
var SharingModel = class extends CrudSchema {
|
|
234
|
+
};
|
|
235
|
+
SharingModel.table = {
|
|
236
|
+
name: `${DATABASE_INFO.SERVER_PREFIX}_sharing`,
|
|
237
|
+
alias: `${DATABASE_INFO.TABLE_PREFIX}_sharing`
|
|
238
|
+
};
|
|
239
|
+
SharingModel.columns = {
|
|
240
|
+
asset_id: { type: "string", primary: true },
|
|
241
|
+
asset_type: { type: "string" },
|
|
242
|
+
created_at: { type: "date" },
|
|
243
|
+
updated_at: { type: "date" },
|
|
244
|
+
deleted_at: { type: "date" },
|
|
245
|
+
qvAttributes: { type: "object" }
|
|
246
|
+
};
|
|
247
|
+
SharingModel.indexes = {
|
|
248
|
+
sharingAssetIdAssetType: {
|
|
249
|
+
name: "sharing_asset_id_asset_type_index",
|
|
250
|
+
columns: ["asset_id", "asset_type"]
|
|
251
|
+
},
|
|
252
|
+
sharingAssetType: {
|
|
253
|
+
name: "sharing_asset_type_index",
|
|
254
|
+
columns: ["asset_type"]
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
SharingModel.schema = DATABASE_INFO.DATA_PERSISTENCE_SCHEMA;
|
|
258
|
+
SharingModel.usePool = true;
|
|
259
|
+
|
|
260
|
+
// src/sharing/implementations/sharing.repository.ts
|
|
261
|
+
var SharingRepository = class extends BaseRepository {
|
|
262
|
+
constructor() {
|
|
263
|
+
super(SharingModel);
|
|
264
|
+
}
|
|
265
|
+
async getOne(assetId) {
|
|
266
|
+
const params = {
|
|
267
|
+
filters: [this.filter("asset_id", assetId)]
|
|
268
|
+
};
|
|
269
|
+
const response = await super.findItem(params);
|
|
270
|
+
return response;
|
|
271
|
+
}
|
|
272
|
+
async create(sharing) {
|
|
273
|
+
const response = await super.create(sharing);
|
|
274
|
+
return response;
|
|
275
|
+
}
|
|
276
|
+
async patch(assetId, sharing) {
|
|
277
|
+
await super.update([this.filter("asset_id", assetId)], sharing);
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
280
|
+
async delete(assetId) {
|
|
281
|
+
await super.remove([this.filter("asset_id", assetId)]);
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
// src/context.ts
|
|
287
|
+
container.register(
|
|
288
|
+
"SharingRepository",
|
|
289
|
+
SharingRepository
|
|
290
|
+
);
|
|
291
|
+
container.register(
|
|
292
|
+
"SharingDetailsRepository",
|
|
293
|
+
SharingDetailsRepository
|
|
294
|
+
);
|
|
295
|
+
var Context = container;
|
|
296
|
+
var SharingDetail = class _SharingDetail {
|
|
297
|
+
constructor(params) {
|
|
298
|
+
this.sharingDetailsId = params.sharingDetailsId;
|
|
299
|
+
this.assetId = params.assetId;
|
|
300
|
+
this.accessLevel = params.accessLevel;
|
|
301
|
+
this.accessLevelAsText = this.convertAccessLevelToText(
|
|
302
|
+
params.accessLevel
|
|
303
|
+
);
|
|
304
|
+
this.orgId = params.orgId;
|
|
305
|
+
this.sharedWith = params.sharedWith;
|
|
306
|
+
this.sharedType = params.sharedType;
|
|
307
|
+
this.sharedEmail = params.sharedEmail;
|
|
308
|
+
this.sharedOrigin = params.sharedOrigin;
|
|
309
|
+
this.createdAt = params.createdAt;
|
|
310
|
+
this.updatedAt = params.updatedAt;
|
|
311
|
+
this.deletedAt = params.deletedAt;
|
|
312
|
+
}
|
|
313
|
+
static create(params) {
|
|
314
|
+
var _a;
|
|
315
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
316
|
+
const obj = __spreadProps(__spreadValues({}, params), {
|
|
317
|
+
sharingDetailsId: (_a = params.sharedId) != null ? _a : getId(),
|
|
318
|
+
createdAt: now,
|
|
319
|
+
updatedAt: now
|
|
320
|
+
});
|
|
321
|
+
return new _SharingDetail(obj);
|
|
322
|
+
}
|
|
323
|
+
static parse(params) {
|
|
324
|
+
return new _SharingDetail({
|
|
325
|
+
sharingDetailsId: params.sharing_details_id,
|
|
326
|
+
assetId: params.asset_id,
|
|
327
|
+
accessLevel: params.access_level,
|
|
328
|
+
orgId: params.org_id,
|
|
329
|
+
sharedWith: params.shared_with,
|
|
330
|
+
sharedType: params.shared_type,
|
|
331
|
+
sharedEmail: params.shared_email,
|
|
332
|
+
sharedOrigin: params.share_origin,
|
|
333
|
+
createdAt: params.created_at,
|
|
334
|
+
updatedAt: params.updated_at,
|
|
335
|
+
deletedAt: params.deleted_at
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
update(params) {
|
|
339
|
+
if (params.accessLevel)
|
|
340
|
+
this.accessLevel = params.accessLevel;
|
|
341
|
+
if (params.sharedEmail)
|
|
342
|
+
this.sharedEmail = params.sharedEmail;
|
|
343
|
+
this.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
344
|
+
}
|
|
345
|
+
toTable() {
|
|
346
|
+
return {
|
|
347
|
+
sharing_details_id: this.sharingDetailsId,
|
|
348
|
+
asset_id: this.assetId,
|
|
349
|
+
access_level: this.accessLevel,
|
|
350
|
+
org_id: this.orgId,
|
|
351
|
+
shared_with: this.sharedWith,
|
|
352
|
+
shared_type: this.sharedType,
|
|
353
|
+
shared_email: this.sharedEmail,
|
|
354
|
+
share_origin: this.sharedOrigin,
|
|
355
|
+
created_at: this.createdAt,
|
|
356
|
+
updated_at: this.updatedAt,
|
|
357
|
+
deleted_at: this.deletedAt
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
toPlain() {
|
|
361
|
+
return {
|
|
362
|
+
sharingDetailsId: this.sharingDetailsId,
|
|
363
|
+
assetId: this.assetId,
|
|
364
|
+
accessLevel: this.accessLevel,
|
|
365
|
+
orgId: this.orgId,
|
|
366
|
+
sharedWith: this.sharedWith,
|
|
367
|
+
sharedType: this.sharedType,
|
|
368
|
+
sharedEmail: this.sharedEmail,
|
|
369
|
+
sharedOrigin: this.sharedOrigin,
|
|
370
|
+
createdAt: this.createdAt,
|
|
371
|
+
updatedAt: this.updatedAt,
|
|
372
|
+
deletedAt: this.deletedAt
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
toJSON() {
|
|
376
|
+
return {
|
|
377
|
+
sharedId: this.sharingDetailsId,
|
|
378
|
+
assetId: this.assetId,
|
|
379
|
+
accessLevel: this.accessLevel,
|
|
380
|
+
accessLevelAsText: this.accessLevelAsText,
|
|
381
|
+
orgId: this.orgId,
|
|
382
|
+
sharedWith: this.sharedWith,
|
|
383
|
+
sharedType: this.sharedType,
|
|
384
|
+
sharedEmail: this.sharedEmail,
|
|
385
|
+
sharedOrigin: this.sharedOrigin,
|
|
386
|
+
createdAt: this.createdAt,
|
|
387
|
+
updatedAt: this.updatedAt
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
get getSharingDetailsId() {
|
|
391
|
+
return this.sharingDetailsId;
|
|
392
|
+
}
|
|
393
|
+
get getAccessLevel() {
|
|
394
|
+
return this.accessLevel;
|
|
395
|
+
}
|
|
396
|
+
get getAccessLevelAsText() {
|
|
397
|
+
return this.accessLevelAsText;
|
|
398
|
+
}
|
|
399
|
+
convertAccessLevelToText(level) {
|
|
400
|
+
var _a;
|
|
401
|
+
return (_a = ACCESS_LEVEL[level]) != null ? _a : "UNKNOWN";
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
// src/sharing/services/checkUserAccessLevel.ts
|
|
406
|
+
var CheckUserAccessLevel = class {
|
|
407
|
+
constructor(detailsRepository) {
|
|
408
|
+
this.detailsRepository = detailsRepository;
|
|
409
|
+
}
|
|
410
|
+
async execute({
|
|
411
|
+
userId,
|
|
412
|
+
orgId,
|
|
413
|
+
assetId
|
|
414
|
+
}) {
|
|
415
|
+
const details = await this.detailsRepository.getList({
|
|
416
|
+
data: { assetId },
|
|
417
|
+
filters: [
|
|
418
|
+
{ column: "shared_with", value: userId },
|
|
419
|
+
{ column: "org_id", value: orgId }
|
|
420
|
+
],
|
|
421
|
+
sorting: [{ column: "access_level", direction: "DESC" }],
|
|
422
|
+
pagination: { limit: 1 }
|
|
423
|
+
});
|
|
424
|
+
if (details.items.length === 0)
|
|
425
|
+
return { level: 0 /* NONE */, levelAsText: "NONE" };
|
|
426
|
+
const currentDetail = SharingDetail.parse(details.items[0]);
|
|
427
|
+
return {
|
|
428
|
+
level: currentDetail.getAccessLevel,
|
|
429
|
+
levelAsText: currentDetail.getAccessLevelAsText
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
CheckUserAccessLevel = __decorateClass([
|
|
434
|
+
injectable(),
|
|
435
|
+
__decorateParam(0, inject("SharingDetailsRepository"))
|
|
436
|
+
], CheckUserAccessLevel);
|
|
437
|
+
var DeleteSharing = class {
|
|
438
|
+
constructor(sharingRepository) {
|
|
439
|
+
this.sharingRepository = sharingRepository;
|
|
440
|
+
}
|
|
441
|
+
async execute({ body }) {
|
|
442
|
+
const { assetId } = body;
|
|
443
|
+
const sharing = await this.sharingRepository.getOne(assetId);
|
|
444
|
+
if (!sharing)
|
|
445
|
+
return null;
|
|
446
|
+
const detailSharing = await this.sharingRepository.delete(assetId);
|
|
447
|
+
return detailSharing;
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
DeleteSharing = __decorateClass([
|
|
451
|
+
injectable(),
|
|
452
|
+
__decorateParam(0, inject("SharingRepository"))
|
|
453
|
+
], DeleteSharing);
|
|
454
|
+
var ListSharing = class {
|
|
455
|
+
constructor(sharingRepository, detailsRepository) {
|
|
456
|
+
this.sharingRepository = sharingRepository;
|
|
457
|
+
this.detailsRepository = detailsRepository;
|
|
458
|
+
}
|
|
459
|
+
async execute({
|
|
460
|
+
body
|
|
461
|
+
}) {
|
|
462
|
+
const {
|
|
463
|
+
data: { assetId },
|
|
464
|
+
pagination
|
|
465
|
+
} = body;
|
|
466
|
+
const sharing = await this.sharingRepository.getOne(assetId);
|
|
467
|
+
if (!sharing)
|
|
468
|
+
return null;
|
|
469
|
+
const detailSharing = await this.detailsRepository.getList({
|
|
470
|
+
data: { assetId },
|
|
471
|
+
pagination
|
|
472
|
+
});
|
|
473
|
+
const items = detailSharing.items.map(
|
|
474
|
+
(item) => SharingDetail.parse(item).toJSON()
|
|
475
|
+
);
|
|
476
|
+
return __spreadProps(__spreadValues({}, detailSharing), {
|
|
477
|
+
items
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
ListSharing = __decorateClass([
|
|
482
|
+
injectable(),
|
|
483
|
+
__decorateParam(0, inject("SharingRepository")),
|
|
484
|
+
__decorateParam(1, inject("SharingDetailsRepository"))
|
|
485
|
+
], ListSharing);
|
|
486
|
+
|
|
487
|
+
// src/sharing/entities/sharing.ts
|
|
488
|
+
var Sharing = class _Sharing {
|
|
489
|
+
constructor(params) {
|
|
490
|
+
this.assetId = params.assetId;
|
|
491
|
+
this.assetType = params.assetType;
|
|
492
|
+
this.createdAt = params.createdAt;
|
|
493
|
+
this.updatedAt = params.updatedAt;
|
|
494
|
+
this.deletedAt = params.deletedAt;
|
|
495
|
+
}
|
|
496
|
+
static create(params) {
|
|
497
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
498
|
+
const obj = __spreadProps(__spreadValues({}, params), {
|
|
499
|
+
createdAt: now,
|
|
500
|
+
updatedAt: now
|
|
501
|
+
});
|
|
502
|
+
return new _Sharing(obj);
|
|
503
|
+
}
|
|
504
|
+
static parse(params) {
|
|
505
|
+
return new _Sharing({
|
|
506
|
+
assetId: params.asset_id,
|
|
507
|
+
assetType: params.asset_type,
|
|
508
|
+
createdAt: params.created_at,
|
|
509
|
+
updatedAt: params.updated_at,
|
|
510
|
+
deletedAt: params.deleted_at
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
update() {
|
|
514
|
+
this.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
515
|
+
}
|
|
516
|
+
toTable() {
|
|
517
|
+
return {
|
|
518
|
+
asset_id: this.assetId,
|
|
519
|
+
asset_type: this.assetType,
|
|
520
|
+
created_at: this.createdAt,
|
|
521
|
+
updated_at: this.updatedAt,
|
|
522
|
+
deleted_at: this.deletedAt
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
toPlain() {
|
|
526
|
+
return {
|
|
527
|
+
assetId: this.assetId,
|
|
528
|
+
assetType: this.assetType,
|
|
529
|
+
createdAt: this.createdAt,
|
|
530
|
+
updatedAt: this.updatedAt,
|
|
531
|
+
deletedAt: this.deletedAt
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
toJSON() {
|
|
535
|
+
return {
|
|
536
|
+
assetId: this.assetId,
|
|
537
|
+
assetType: this.assetType,
|
|
538
|
+
createdAt: this.createdAt,
|
|
539
|
+
updatedAt: this.updatedAt
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
get getAssetId() {
|
|
543
|
+
return this.assetId;
|
|
544
|
+
}
|
|
545
|
+
get getAssetType() {
|
|
546
|
+
return this.assetType;
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
// src/sharing/services/upsert.ts
|
|
551
|
+
var UpsertSharing = class {
|
|
552
|
+
constructor(sharingRepository, detailsRepository) {
|
|
553
|
+
this.sharingRepository = sharingRepository;
|
|
554
|
+
this.detailsRepository = detailsRepository;
|
|
555
|
+
}
|
|
556
|
+
async execute({
|
|
557
|
+
body
|
|
558
|
+
}) {
|
|
559
|
+
const assetId = body.assetId;
|
|
560
|
+
const sharing = await this.sharingRepository.getOne(assetId);
|
|
561
|
+
let currentSharing;
|
|
562
|
+
if (sharing) {
|
|
563
|
+
currentSharing = Sharing.parse(sharing);
|
|
564
|
+
} else {
|
|
565
|
+
const createSharing = {
|
|
566
|
+
assetId: body.assetId,
|
|
567
|
+
assetType: body.assetType
|
|
568
|
+
};
|
|
569
|
+
currentSharing = Sharing.create(createSharing);
|
|
570
|
+
await this.sharingRepository.create(currentSharing.toTable());
|
|
571
|
+
}
|
|
572
|
+
let updatedList = [];
|
|
573
|
+
if (body.add)
|
|
574
|
+
updatedList = await this.addDetails(assetId, body.add);
|
|
575
|
+
if (body.remove)
|
|
576
|
+
await this.removeDetails(body.remove);
|
|
577
|
+
currentSharing.update();
|
|
578
|
+
await this.sharingRepository.patch(
|
|
579
|
+
currentSharing.getAssetId,
|
|
580
|
+
currentSharing.toTable()
|
|
581
|
+
);
|
|
582
|
+
return updatedList.map((detail) => detail.toJSON());
|
|
583
|
+
}
|
|
584
|
+
async addDetails(assetId, list) {
|
|
585
|
+
var _a;
|
|
586
|
+
const sharingList = [];
|
|
587
|
+
for (const detail of list) {
|
|
588
|
+
let currentDetail;
|
|
589
|
+
const sharingDetail = !detail.sharedId ? null : await this.detailsRepository.getOne(detail.sharedId);
|
|
590
|
+
if (sharingDetail) {
|
|
591
|
+
currentDetail = SharingDetail.parse(sharingDetail);
|
|
592
|
+
currentDetail.update(detail);
|
|
593
|
+
await this.detailsRepository.patch(
|
|
594
|
+
currentDetail.getSharingDetailsId,
|
|
595
|
+
currentDetail.toTable()
|
|
596
|
+
);
|
|
597
|
+
} else {
|
|
598
|
+
const createDetails = __spreadValues({
|
|
599
|
+
assetId,
|
|
600
|
+
orgId: (_a = detail.orgId) != null ? _a : ORGANIZATION_QRVEY
|
|
601
|
+
}, detail);
|
|
602
|
+
currentDetail = SharingDetail.create(createDetails);
|
|
603
|
+
await this.detailsRepository.create(currentDetail.toTable());
|
|
604
|
+
}
|
|
605
|
+
sharingList.push(currentDetail);
|
|
606
|
+
}
|
|
607
|
+
return sharingList;
|
|
608
|
+
}
|
|
609
|
+
async removeDetails(list) {
|
|
610
|
+
for (const detail of list) {
|
|
611
|
+
await this.detailsRepository.delete(detail.sharedId);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
UpsertSharing = __decorateClass([
|
|
616
|
+
injectable(),
|
|
617
|
+
__decorateParam(0, inject("SharingRepository")),
|
|
618
|
+
__decorateParam(1, inject("SharingDetailsRepository"))
|
|
619
|
+
], UpsertSharing);
|
|
620
|
+
|
|
621
|
+
// src/index.ts
|
|
622
|
+
var api = {
|
|
623
|
+
upsert: (...args) => Context.resolve(UpsertSharing).execute(...args),
|
|
624
|
+
list: (...args) => Context.resolve(ListSharing).execute(...args),
|
|
625
|
+
delete: (...args) => Context.resolve(DeleteSharing).execute(...args)
|
|
626
|
+
};
|
|
627
|
+
var checkUserAccessLevel = (...args) => Context.resolve(CheckUserAccessLevel).execute(...args);
|
|
628
|
+
|
|
629
|
+
export { ACCESS_LEVEL, ASSET_TYPE, ORGANIZATION_QRVEY, SHARED_ORIGIN, SHARE_TYPE, api, checkUserAccessLevel };
|
|
630
|
+
//# sourceMappingURL=out.js.map
|
|
631
|
+
//# sourceMappingURL=index.mjs.map
|