@universis/evaluations 1.0.2 → 1.0.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.
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";var _data = require("@themost/data");
|
|
2
2
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
3
|
-
var _contentService = require("../../../../server/services/content-service");
|
|
4
3
|
var _path = _interopRequireDefault(require("path"));
|
|
5
4
|
var _utils = require("@themost/common/utils");
|
|
6
|
-
var _errors = require("@themost/common/errors");
|
|
7
|
-
var _enableAttachmentModel = require("../../../../server/models/enable-attachment-model");var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2;function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {var desc = {};Object.keys(descriptor).forEach(function (key) {desc[key] = descriptor[key];});desc.enumerable = !!desc.enumerable;desc.configurable = !!desc.configurable;if ('value' in desc || desc.initializer) {desc.writable = true;}desc = decorators.slice().reverse().reduce(function (desc, decorator) {return decorator(target, property, desc) || desc;}, desc);if (context && desc.initializer !== void 0) {desc.value = desc.initializer ? desc.initializer.call(context) : void 0;desc.initializer = undefined;}if (desc.initializer === void 0) {Object.defineProperty(target, property, desc);desc = null;}return desc;}
|
|
5
|
+
var _errors = require("@themost/common/errors");var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2;function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {var desc = {};Object.keys(descriptor).forEach(function (key) {desc[key] = descriptor[key];});desc.enumerable = !!desc.enumerable;desc.configurable = !!desc.configurable;if ('value' in desc || desc.initializer) {desc.writable = true;}desc = decorators.slice().reverse().reduce(function (desc, decorator) {return decorator(target, property, desc) || desc;}, desc);if (context && desc.initializer !== void 0) {desc.value = desc.initializer ? desc.initializer.call(context) : void 0;desc.initializer = undefined;}if (desc.initializer === void 0) {Object.defineProperty(target, property, desc);desc = null;}return desc;}
|
|
8
6
|
/**
|
|
9
7
|
* @class
|
|
10
8
|
* @property {number} id
|
|
@@ -65,7 +63,7 @@ _data.EdmMapping.action('RemoveAttachment', 'EvaluationDocument'), _dec(_class =
|
|
|
65
63
|
}
|
|
66
64
|
const mime = file.mimetype || file.contentType;
|
|
67
65
|
if (_lodash.default.isNil(mime)) {
|
|
68
|
-
return reject(new
|
|
66
|
+
return reject(new Error('The specified file type is not supported by the system.'));
|
|
69
67
|
}
|
|
70
68
|
const addAttributes = {};
|
|
71
69
|
_lodash.default.forEach(context.model('EvaluationDocument').attributeNames, (attribute) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/models/evaluation-document-model.js"],"names":["EvaluationDocument","EdmMapping","entityType","param","EdmType","EdmStream","action","DataObject","constructor","next","context","Promise","resolve","reject","db","nextIdentity","err","value","add","file","extraAttributes","attachment","Object","assign","name","contentFileName","_addAttachment","removeAttachment","_removeAttachment","id","finalResult","executeInTransaction","callback","originalname","replace","x","toLowerCase","mime","mimetype","contentType","_","isNil","MimeTypeError","addAttributes","forEach","model","attributeNames","attribute","prototype","hasOwnProperty","call","newAttachment","svc","getApplication","getService","PrivateContentService","filePath","destination","filename","path","additionalType","copyFrom","TraceUtils","error","HttpServerError","resolveUrl","url","result","where","equal","getItem","then","self","property","remove","silent","catch","DataNotFoundError","module","exports"],"mappings":"aAAA;AACA;AACA;AACA;AACA;AACA;AACA,0F;AACA;AACA;AACA;AACA;AACA,G;;AAEMA,kB,WADLC,iBAAWC,UAAX,CAAsB,oBAAtB,C;;;;;;;;;;;;;;;;;;;;;;;;AAyBID,iBAAWE,KAAX,CAAiB,iBAAjB,EAAoC,QAApC,EAA8C,IAA9C,EAAoD,IAApD,C;AACAF,iBAAWE,KAAX,CAAiB,MAAjB,EAAyBC,cAAQC,SAAjC,EAA4C,KAA5C,C;AACAJ,iBAAWK,MAAX,CAAkB,KA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AX,CAAgC,CAACC,QAAD,KAAa;AACzC;AACA,eAAOtB,OAAO,CAACmC,KAAR,CAAc,YAAd,EAA4BuB,KAA5B,CAAkC,IAAlC,EAAwCC,KAAxC,CAA8CxC,EAA9C,EAAkDyC,OAAlD,GAA4DC,IAA5D,CAAiE,CAAClD,UAAD,KAAe;AACnF,cAAIA,UAAJ,EAAgB;AACZ;AACA,mBAAOmD,IAAI,CAACC,QAAL,CAAc,aAAd,EAA6BC,MAA7B,CAAoCrD,UAApC,EAA+C,CAACL,GAAD,KAAQ;AAC1D;AACA,kBAAIA,GAAJ,EAAS;AACL,uBAAOgB,QAAQ,CAAChB,GAAD,CAAf;AACH;AACD,qBAAON,OAAO,CAACmC,KAAR,CAAc,YAAd,EAA4B8B,MAA5B,GAAqCD,MAArC,CAA4CrD,UAA5C,EAAwDkD,IAAxD,CAA6D,MAAK;AACrEJ,gBAAAA,MAAM,GAAG9C,UAAT;AACA,uBAAOW,QAAQ,EAAf;AACH,eAHM,EAGJ4C,KAHI,CAGE,CAAC5D,GAAD,KAAQ;AACb,uBAAOgB,QAAQ,CAAChB,GAAD,CAAf;AACH,eALM,CAAP;AAMH,aAXM,CAAP;AAYH;AACD,iBAAOgB,QAAQ,CAAC,IAAI6C,yBAAJ,EAAD,CAAf;AACH,SAjBM,EAiBJD,KAjBI,CAiBE,CAAC5D,GAAD,KAAQ;AACb,iBAAOgB,QAAQ,CAAChB,GAAD,CAAf;AACH,SAnBM,CAAP;AAoBH,OAtBD,EAsBG,CAACA,GAAD,KAAQ;AACP,YAAIA,GAAJ,EAAS;AACL,iBAAOH,MAAM,CAACG,GAAD,CAAb;AACH;AACD,eAAOJ,OAAO,CAACuD,MAAD,CAAd;AACH,OA3BD;AA4BH,KA7BM,CAAP;AA8BH,GApIuC,C;;;AAuI5CW,MAAM,CAACC,OAAP,GAAiB/E,kBAAjB","sourcesContent":["import {DataObject, EdmMapping, EdmType} from '@themost/data';\nimport _ from \"lodash\";\nimport {PrivateContentService} from \"../../../../server/services/content-service\";\nimport path from \"path\";\nimport {TraceUtils} from \"@themost/common/utils\";\nimport {DataNotFoundError, HttpServerError} from \"@themost/common/errors\";\nimport {MimeTypeError} from \"../../../../server/models/enable-attachment-model\";\n/**\n * @class\n * @property {number} id\n * @augments {DataObject}\n */\n@EdmMapping.entityType('EvaluationDocument')\nclass EvaluationDocument extends DataObject {\n /**\n * @constructor\n */\n constructor() {\n super();\n }\n\n static async next(context) {\n return await new Promise((resolve, reject) => {\n context.db.nextIdentity('EvaluationDocument', 'documentNumber', (err, value) => {\n if (err) {\n return reject(err);\n }\n return resolve(value);\n });\n });\n }\n\n /**\n * Adds an attachment\n * @param {*} file\n * @param {*=} extraAttributes\n */\n @EdmMapping.param('extraAttributes', 'Object', true, true)\n @EdmMapping.param('file', EdmType.EdmStream, false)\n @EdmMapping.action('Add', 'EvaluationDocument')\n static async add(context, file, extraAttributes) {\n const attachment = Object.assign({\n name: file.contentFileName\n }, file, extraAttributes);\n return await EvaluationDocument._addAttachment(context, attachment);\n }\n /**\n * Removes an attachment\n * @param {*} attachment\n */\n @EdmMapping.param('attachment', 'EvaluationDocument', true, true)\n @EdmMapping.action('RemoveAttachment', 'EvaluationDocument')\n static async removeAttachment(context, attachment) {\n return await EvaluationDocument._removeAttachment(context,attachment.id);\n }\n\n static _addAttachment(context, file) {\n let finalResult;\n return new Promise((resolve, reject)=> {\n context.db.executeInTransaction((callback)=> {\n if (typeof file.originalname === 'string') {\n file.name = file.originalname.replace(/\\.[A-Z0-9]+$/ig, function (x) {\n return x.toLowerCase();\n });\n }\n const mime = file.mimetype || file.contentType;\n if (_.isNil(mime)) {\n return reject(new MimeTypeError('The specified file type is not supported by the system.'))\n }\n const addAttributes = {};\n _.forEach(context.model('EvaluationDocument').attributeNames, (attribute) => {\n if (Object.prototype.hasOwnProperty.call(file, attribute)) {\n addAttributes[attribute] = file[attribute];\n }\n });\n const newAttachment = _.assign(addAttributes, {contentType: mime});\n const svc = context.getApplication().getService(function PrivateContentService(){});\n //add attachment to attachments\n let filePath;\n if (file.destination && file.filename) {\n filePath = path.resolve(file.destination, file.filename);\n } else {\n filePath = file.path;\n }\n newAttachment.additionalType = 'EvaluationDocument';\n svc.copyFrom(context, filePath, newAttachment, function (err) {\n if (err) {\n TraceUtils.error(err);\n return callback(new HttpServerError());\n }\n svc.resolveUrl(context, newAttachment, function (err, url) {\n if (err) {\n return callback(err);\n } else {\n finalResult = _.assign({}, newAttachment, {\n url: url,\n name: newAttachment.filename\n });\n return callback();\n }\n });\n\n });\n }, (err)=> {\n if (err) {\n return reject(err);\n }\n return resolve(finalResult);\n });\n })\n\n }\n\n removeAttachment(context, id) {\n let result;\n return new Promise((resolve, reject)=> {\n context.db.executeInTransaction((callback)=> {\n //get attachment\n return context.model('Attachment').where('id').equal(id).getItem().then((attachment)=> {\n if (attachment) {\n //remove attachment connection\n return self.property('attachments').remove(attachment,(err)=> {\n //remove attachment\n if (err) {\n return callback(err);\n }\n return context.model('Attachment').silent().remove(attachment).then(()=> {\n result = attachment;\n return callback();\n }).catch((err)=> {\n return callback(err);\n });\n });\n }\n return callback(new DataNotFoundError());\n }).catch((err)=> {\n return callback(err);\n });\n }, (err)=> {\n if (err) {\n return reject(err);\n }\n return resolve(result);\n });\n });\n }\n\n}\nmodule.exports = EvaluationDocument;\n"],"file":"evaluation-document-model.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/models/evaluation-document-model.js"],"names":["EvaluationDocument","EdmMapping","entityType","param","EdmType","EdmStream","action","DataObject","constructor","next","context","Promise","resolve","reject","db","nextIdentity","err","value","add","file","extraAttributes","attachment","Object","assign","name","contentFileName","_addAttachment","removeAttachment","_removeAttachment","id","finalResult","executeInTransaction","callback","originalname","replace","x","toLowerCase","mime","mimetype","contentType","_","isNil","Error","addAttributes","forEach","model","attributeNames","attribute","prototype","hasOwnProperty","call","newAttachment","svc","getApplication","getService","PrivateContentService","filePath","destination","filename","path","additionalType","copyFrom","TraceUtils","error","HttpServerError","resolveUrl","url","result","where","equal","getItem","then","self","property","remove","silent","catch","DataNotFoundError","module","exports"],"mappings":"aAAA;AACA;AACA;AACA;AACA,gD;AACA;AACA;AACA;AACA;AACA,G;;AAEMA,kB,WADLC,iBAAWC,UAAX,CAAsB,oBAAtB,C;;;;;;;;;;;;;;;;;;;;;;;;AAyBID,iBAAWE,KAAX,CAAiB,iBAAjB,EAAoC,QAApC,EAA8C,IAA9C,EAAoD,IAApD,C;AACAF,iBAAWE,KAAX,CAAiB,MAAjB,EAAyBC,cAAQC,SAAjC,EAA4C,KAA5C,C;AACAJ,iBAAWK,MAAX,CAAkB,KAAlB,EAAyB,oBAAzB,C;;;;;;;;;;;AAWAL,iBAAWE,KAAX,CAAiB,YAAjB,EAA+B,oBAA/B,EAAqD,IAArD,EAA2D,IAA3D,C;AACAF,iBAAWK,MAAX,CAAkB,kBAAlB,EAAsC,oBAAtC,C,2BAvCL,MACMN,kBADN,SACiCO,gBADjC,CAC4C,CACxC;AACJ;AACA,KACIC,WAAW,GAAG,CACV,QACH,CAEgB,aAAJC,IAAI,CAACC,OAAD,EAAU,CACvB,OAAO,MAAM,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB,CAC1CH,OAAO,CAACI,EAAR,CAAWC,YAAX,CAAwB,oBAAxB,EAA8C,gBAA9C,EAAgE,CAACC,GAAD,EAAMC,KAAN,KAAgB,CAC5E,IAAID,GAAJ,EAAS,CACL,OAAOH,MAAM,CAACG,GAAD,CAAb,CACH,CACD,OAAOJ,OAAO,CAACK,KAAD,CAAd,CACH,CALD,EAMH,CAPY,CAAb,CAQH,CAjBuC,CAmBxC;AACJ;AACA;AACA;AACA,KAIoB,aAAHC,GAAG,CAACR,OAAD,EAAUS,IAAV,EAAgBC,eAAhB,EAAiC,CAC7C,MAAMC,UAAU,GAAGC,MAAM,CAACC,MAAP,CAAc,EAC7BC,IAAI,EAAEL,IAAI,CAACM,eADkB,EAAd,EAEhBN,IAFgB,EAEVC,eAFU,CAAnB,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AOgB,QAAQ,CAAChB,GAAD,CAAf;AACH,SAnBM,CAAP;AAoBH,OAtBD,EAsBG,CAACA,GAAD,KAAQ;AACP,YAAIA,GAAJ,EAAS;AACL,iBAAOH,MAAM,CAACG,GAAD,CAAb;AACH;AACD,eAAOJ,OAAO,CAACuD,MAAD,CAAd;AACH,OA3BD;AA4BH,KA7BM,CAAP;AA8BH,GApIuC,C;;;AAuI5CW,MAAM,CAACC,OAAP,GAAiB/E,kBAAjB","sourcesContent":["import {DataObject, EdmMapping, EdmType} from '@themost/data';\nimport _ from \"lodash\";\nimport path from \"path\";\nimport {TraceUtils} from \"@themost/common/utils\";\nimport {DataNotFoundError, HttpServerError} from \"@themost/common/errors\";\n/**\n * @class\n * @property {number} id\n * @augments {DataObject}\n */\n@EdmMapping.entityType('EvaluationDocument')\nclass EvaluationDocument extends DataObject {\n /**\n * @constructor\n */\n constructor() {\n super();\n }\n\n static async next(context) {\n return await new Promise((resolve, reject) => {\n context.db.nextIdentity('EvaluationDocument', 'documentNumber', (err, value) => {\n if (err) {\n return reject(err);\n }\n return resolve(value);\n });\n });\n }\n\n /**\n * Adds an attachment\n * @param {*} file\n * @param {*=} extraAttributes\n */\n @EdmMapping.param('extraAttributes', 'Object', true, true)\n @EdmMapping.param('file', EdmType.EdmStream, false)\n @EdmMapping.action('Add', 'EvaluationDocument')\n static async add(context, file, extraAttributes) {\n const attachment = Object.assign({\n name: file.contentFileName\n }, file, extraAttributes);\n return await EvaluationDocument._addAttachment(context, attachment);\n }\n /**\n * Removes an attachment\n * @param {*} attachment\n */\n @EdmMapping.param('attachment', 'EvaluationDocument', true, true)\n @EdmMapping.action('RemoveAttachment', 'EvaluationDocument')\n static async removeAttachment(context, attachment) {\n return await EvaluationDocument._removeAttachment(context,attachment.id);\n }\n\n static _addAttachment(context, file) {\n let finalResult;\n return new Promise((resolve, reject)=> {\n context.db.executeInTransaction((callback)=> {\n if (typeof file.originalname === 'string') {\n file.name = file.originalname.replace(/\\.[A-Z0-9]+$/ig, function (x) {\n return x.toLowerCase();\n });\n }\n const mime = file.mimetype || file.contentType;\n if (_.isNil(mime)) {\n return reject(new Error('The specified file type is not supported by the system.'))\n }\n const addAttributes = {};\n _.forEach(context.model('EvaluationDocument').attributeNames, (attribute) => {\n if (Object.prototype.hasOwnProperty.call(file, attribute)) {\n addAttributes[attribute] = file[attribute];\n }\n });\n const newAttachment = _.assign(addAttributes, {contentType: mime});\n const svc = context.getApplication().getService(function PrivateContentService(){});\n //add attachment to attachments\n let filePath;\n if (file.destination && file.filename) {\n filePath = path.resolve(file.destination, file.filename);\n } else {\n filePath = file.path;\n }\n newAttachment.additionalType = 'EvaluationDocument';\n svc.copyFrom(context, filePath, newAttachment, function (err) {\n if (err) {\n TraceUtils.error(err);\n return callback(new HttpServerError());\n }\n svc.resolveUrl(context, newAttachment, function (err, url) {\n if (err) {\n return callback(err);\n } else {\n finalResult = _.assign({}, newAttachment, {\n url: url,\n name: newAttachment.filename\n });\n return callback();\n }\n });\n\n });\n }, (err)=> {\n if (err) {\n return reject(err);\n }\n return resolve(finalResult);\n });\n })\n\n }\n\n removeAttachment(context, id) {\n let result;\n return new Promise((resolve, reject)=> {\n context.db.executeInTransaction((callback)=> {\n //get attachment\n return context.model('Attachment').where('id').equal(id).getItem().then((attachment)=> {\n if (attachment) {\n //remove attachment connection\n return self.property('attachments').remove(attachment,(err)=> {\n //remove attachment\n if (err) {\n return callback(err);\n }\n return context.model('Attachment').silent().remove(attachment).then(()=> {\n result = attachment;\n return callback();\n }).catch((err)=> {\n return callback(err);\n });\n });\n }\n return callback(new DataNotFoundError());\n }).catch((err)=> {\n return callback(err);\n });\n }, (err)=> {\n if (err) {\n return reject(err);\n }\n return resolve(result);\n });\n });\n }\n\n}\nmodule.exports = EvaluationDocument;\n"],"file":"evaluation-document-model.js"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import {DataObject, EdmMapping, EdmType} from '@themost/data';
|
|
2
2
|
import _ from "lodash";
|
|
3
|
-
import {PrivateContentService} from "../../../../server/services/content-service";
|
|
4
3
|
import path from "path";
|
|
5
4
|
import {TraceUtils} from "@themost/common/utils";
|
|
6
5
|
import {DataNotFoundError, HttpServerError} from "@themost/common/errors";
|
|
7
|
-
import {MimeTypeError} from "../../../../server/models/enable-attachment-model";
|
|
8
6
|
/**
|
|
9
7
|
* @class
|
|
10
8
|
* @property {number} id
|
|
@@ -65,7 +63,7 @@ class EvaluationDocument extends DataObject {
|
|
|
65
63
|
}
|
|
66
64
|
const mime = file.mimetype || file.contentType;
|
|
67
65
|
if (_.isNil(mime)) {
|
|
68
|
-
return reject(new
|
|
66
|
+
return reject(new Error('The specified file type is not supported by the system.'))
|
|
69
67
|
}
|
|
70
68
|
const addAttributes = {};
|
|
71
69
|
_.forEach(context.model('EvaluationDocument').attributeNames, (attribute) => {
|