@colijnit/mainapi 259.1.1 → 259.1.3

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.
@@ -74,10 +74,13 @@ export declare class MainPublic extends MainApiConnection {
74
74
  getInternalDefaultValue(param: InternalDefault): Promise<DataServiceResponseData>;
75
75
  emailActivity(request: EmailActivityRequest, showLoader?: boolean): Promise<DataServiceResponseData>;
76
76
  selectMultiple(moduleName: ModuleName, objectName: string, operationName?: string, parameterValues?: any, showLoader?: boolean): Promise<DataServiceResponseData>;
77
- getSingleImage(nodeId: number | string, publication?: number, includeMimetype?: boolean, thumb?: boolean): Promise<DataServiceResponseData>;
77
+ getSingleImage(nodeId: number | string, publication?: number, includeMimetype?: boolean, thumb?: boolean, tableName?: TableName): Promise<DataServiceResponseData>;
78
78
  getImage(key: number | string, publication?: number, includeMimetype?: boolean, thumb?: boolean): Promise<DataServiceResponseData>;
79
79
  getImageForCoDocument(document: CoDocument, thumb?: boolean): Promise<DataServiceResponseData>;
80
80
  private createServiceRequestData;
81
81
  private _call;
82
82
  private _callAjaxService;
83
+ private _handleDocumentBody;
84
+ private _handleDocumentUrl;
85
+ private _handleCoDocumentRequest;
83
86
  }
@@ -15,6 +15,10 @@ const end_point_enum_1 = require("@colijnit/ioneconnector/build/enum/end-point.e
15
15
  const public_service_method_1 = require("./enum/public-service-method");
16
16
  const data_service_response_data_1 = require("@colijnit/ioneconnector/build/model/data-service-response-data");
17
17
  const backend_service_name_enum_1 = require("./enum/backend-service-name.enum");
18
+ const table_name_enum_1 = require("./enum/table-name.enum");
19
+ const co_document_type_enum_1 = require("./enum/co-document-type.enum");
20
+ const image_content_bo_1 = require("./model/image-content.bo");
21
+ const file_utils_1 = require("./utils/file-utils");
18
22
  class MainPublic extends main_api_connection_1.MainApiConnection {
19
23
  constructor() {
20
24
  super(...arguments);
@@ -297,19 +301,41 @@ class MainPublic extends main_api_connection_1.MainApiConnection {
297
301
  console.warn('getOrderLineSetCategories not implemented');
298
302
  return Promise.resolve(new data_service_response_data_1.DataServiceResponseData());
299
303
  }
300
- getSingleImage(nodeId, publication = 4, includeMimetype = false, thumb = true) {
301
- console.warn('getSingleImage not implemented');
302
- return Promise.resolve(new data_service_response_data_1.DataServiceResponseData());
304
+ getSingleImage(nodeId, publication = 4, includeMimetype = false, thumb = true, tableName = table_name_enum_1.TableName.Goods) {
305
+ if (!nodeId) {
306
+ return;
307
+ }
308
+ const params = {
309
+ table: tableName,
310
+ key: nodeId.toString(),
311
+ includeBody: thumb === undefined || thumb === false,
312
+ includeThumbnail: thumb === true,
313
+ publication: publication
314
+ };
315
+ const data = Object.assign(Object.assign({}, this.createServiceRequestData()), { parameterValues: params });
316
+ return this._call(public_service_method_1.PublicServiceMethod.GetSingleImage, data);
303
317
  }
304
318
  getImage(key, publication = 4, includeMimetype = false, thumb = true) {
305
319
  return __awaiter(this, void 0, void 0, function* () {
306
- console.warn('getImage not implemented');
307
- return Promise.resolve(new data_service_response_data_1.DataServiceResponseData());
320
+ const getImageObject = yield this.getSingleImage(key, publication, includeMimetype, thumb, table_name_enum_1.TableName.Goods);
321
+ if (getImageObject.validationResult && getImageObject.validationResult.success) {
322
+ if (getImageObject.resultObject) {
323
+ const document = getImageObject.resultObject;
324
+ const type = document.documentType;
325
+ const fileType = document.fileType;
326
+ const hasPublicAccess = document.hasPublicAccess;
327
+ return this._handleCoDocumentRequest(type, fileType, hasPublicAccess, document.documentId, document.mimeTypeInternal, thumb, document.filePath);
328
+ }
329
+ }
308
330
  });
309
331
  }
310
332
  getImageForCoDocument(document, thumb = false) {
311
- console.warn('getImageForCoDocument not implemented');
312
- return Promise.resolve(new data_service_response_data_1.DataServiceResponseData());
333
+ if (document) {
334
+ const type = document.documentType;
335
+ const fileType = document.fileType;
336
+ const hasPublicAccess = document.hasPublicAccess;
337
+ return this._handleCoDocumentRequest(type, fileType, hasPublicAccess, document.documentId, document.mimeTypeInternal, thumb, document.filePath);
338
+ }
313
339
  }
314
340
  createServiceRequestData() {
315
341
  const data = { languageCode: this.languageCode };
@@ -325,5 +351,62 @@ class MainPublic extends main_api_connection_1.MainApiConnection {
325
351
  return this.connector.call(method, data, showLoader, service, end_point_enum_1.EndPoint.AjaxService, ownMessage);
326
352
  });
327
353
  }
354
+ _handleDocumentBody(documentId, mimeType, thumb, fileType) {
355
+ return __awaiter(this, void 0, void 0, function* () {
356
+ const returnObject = new data_service_response_data_1.DataServiceResponseData();
357
+ const documentBody = yield this.getDocumentContent(documentId, thumb);
358
+ const imageObject = new image_content_bo_1.ImageContent();
359
+ if (mimeType === undefined) {
360
+ mimeType = 'image/jpeg';
361
+ }
362
+ imageObject.mimeType = mimeType;
363
+ imageObject.fileType = fileType;
364
+ if (documentBody && documentBody.validationResult.success) {
365
+ returnObject.validationResult.success = true;
366
+ imageObject.image = file_utils_1.FileUtils.DocumentBodyToDataUri(documentBody.resultObject.documentContent, mimeType);
367
+ returnObject.resultObject = imageObject;
368
+ }
369
+ else {
370
+ returnObject.validationResult.success = false;
371
+ imageObject.image = null;
372
+ returnObject.resultObject = imageObject;
373
+ }
374
+ return returnObject;
375
+ });
376
+ }
377
+ _handleDocumentUrl(url, fileType) {
378
+ return __awaiter(this, void 0, void 0, function* () {
379
+ const returnObject = new data_service_response_data_1.DataServiceResponseData();
380
+ const imageObject = new image_content_bo_1.ImageContent();
381
+ imageObject.fileType = fileType;
382
+ if (url) {
383
+ returnObject.validationResult.success = true;
384
+ imageObject.image = url;
385
+ returnObject.resultObject = imageObject;
386
+ }
387
+ else {
388
+ returnObject.validationResult.success = false;
389
+ imageObject.image = null;
390
+ returnObject.resultObject = imageObject;
391
+ }
392
+ return returnObject;
393
+ });
394
+ }
395
+ _handleCoDocumentRequest(type, fileType, hasPublicAccess, documentId, mimeType, thumb, filePath) {
396
+ if (type === co_document_type_enum_1.CoDocumentType.SaveAsDocument) {
397
+ return this._handleDocumentBody(documentId, mimeType, thumb, fileType);
398
+ }
399
+ else if (type === co_document_type_enum_1.CoDocumentType.SaveAsLinkOnRandomLocation) {
400
+ return this._handleDocumentUrl(filePath, fileType);
401
+ }
402
+ else if (type === co_document_type_enum_1.CoDocumentType.SaveAsLinkOnDefaultLocation) {
403
+ }
404
+ else if (type === co_document_type_enum_1.CoDocumentType.SaveAsLinkOnCdnServerLocation && hasPublicAccess === 'T') {
405
+ return this._handleDocumentUrl(filePath, fileType);
406
+ }
407
+ else if (type === co_document_type_enum_1.CoDocumentType.SaveAsLinkOnCdnServerLocation && hasPublicAccess === 'F') {
408
+ return this._handleDocumentBody(documentId, mimeType, thumb, fileType);
409
+ }
410
+ }
328
411
  }
329
412
  exports.MainPublic = MainPublic;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colijnit/mainapi",
3
- "version": "259.1.1",
3
+ "version": "259.1.3",
4
4
  "scripts": {
5
5
  "build": "grunt clean && tsc",
6
6
  "browserify": "browserify build/connector.js --s colijn -o dist/out-tsc/bundle.js",