@rss/common
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -19,2 +19,3 @@ 'use strict'; | ||
this.attachments = []; | ||
this.comment = null; | ||
this.isRequired = false; | ||
@@ -24,2 +25,3 @@ this.isMovable = false; | ||
this.allowAttachments = true; | ||
this.allowComment = false; | ||
@@ -48,2 +50,4 @@ if (opt) { | ||
} | ||
this.allowComment = opt.allowComment !== null && opt.allowComment !== undefined ? opt.allowComment : this.allowComment; | ||
this.comment = opt.comment !== null && opt.comment !== undefined ? opt.comment : this.comment; | ||
} | ||
@@ -66,6 +70,8 @@ }, { | ||
attachments: { type: 'array', items: { $ref: 'file-reference.schema.json' } }, | ||
comment: { type: ['string', 'null'] }, | ||
isRequired: { type: 'boolean' }, | ||
isMovable: { type: 'boolean' }, | ||
isEditable: { type: 'boolean' }, | ||
allowAttachments: { type: 'boolean' } | ||
allowAttachments: { type: 'boolean' }, | ||
allowComment: { type: 'boolean' } | ||
}, | ||
@@ -72,0 +78,0 @@ required: Object.keys(this) |
@@ -142,2 +142,22 @@ 'use strict'; | ||
}, { | ||
key: 'cloneWithCommentsAllowed', | ||
value: function cloneWithCommentsAllowed(document, properties) { | ||
var copy = Document.clone(document, properties); | ||
copy.title = '' + document.title; | ||
copy.sections = copy.sections.map(function (section) { | ||
return _extends({}, section, { | ||
allowableCards: section.allowableCards.map(function (allowableCard) { | ||
return _extends({}, allowableCard, { allowComment: true }); | ||
}), | ||
cards: section.cards.map(function (card) { | ||
return _extends({}, card, { | ||
allowComment: true | ||
}); | ||
}) | ||
}); | ||
}); | ||
return new this(copy); | ||
} | ||
}, { | ||
key: 'clone', | ||
@@ -144,0 +164,0 @@ value: function clone(document, properties) { |
{ | ||
"name": "@rss/common", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "common constant, classes, & helper", | ||
@@ -5,0 +5,0 @@ "author": "Risk & Safety Solution", |
@@ -11,2 +11,3 @@ const ObjectId = require('bson').ObjectID; | ||
this.attachments = []; | ||
this.comment = null; | ||
this.isRequired = false; | ||
@@ -16,2 +17,3 @@ this.isMovable = false; | ||
this.allowAttachments = true; | ||
this.allowComment = false; | ||
@@ -37,2 +39,4 @@ if (opt) { | ||
} | ||
this.allowComment = opt.allowComment !== null && opt.allowComment !== undefined ? opt.allowComment : this.allowComment; | ||
this.comment = opt.comment !== null && opt.comment !== undefined ? opt.comment : this.comment; | ||
} | ||
@@ -53,2 +57,3 @@ | ||
attachments: { type: 'array', items: { $ref: 'file-reference.schema.json' } }, | ||
comment: { type: ['string', 'null'] }, | ||
isRequired: { type: 'boolean' }, | ||
@@ -58,2 +63,3 @@ isMovable: { type: 'boolean' }, | ||
allowAttachments: { type: 'boolean' }, | ||
allowComment: { type: 'boolean' }, | ||
}, | ||
@@ -60,0 +66,0 @@ required: Object.keys(this), |
@@ -104,2 +104,17 @@ const ObjectId = require('bson').ObjectID; | ||
static cloneWithCommentsAllowed(document, properties) { | ||
const copy = Document.clone(document, properties); | ||
copy.title = `${document.title}`; | ||
copy.sections = copy.sections.map((section) => ({ | ||
...section, | ||
allowableCards: section.allowableCards.map((allowableCard) => ({ ...allowableCard, allowComment: true })), | ||
cards: section.cards.map((card) => ({ | ||
...card, | ||
allowComment: true, | ||
})), | ||
})); | ||
return new this(copy); | ||
} | ||
static clone(document, properties) { | ||
@@ -156,3 +171,2 @@ const copy = Object.assign( | ||
const sections = template.sectionDefinitions.map((sectionDefinition) => | ||
Object.assign( | ||
@@ -159,0 +173,0 @@ {}, |
@@ -346,2 +346,62 @@ const Document = require('./document'); | ||
}); | ||
it('should clone a document and add allowComment', () => { | ||
const document = new Document({ | ||
_id: '5808fa7fae73b626daa89492', | ||
template: { | ||
_id: '5ba138e9b9c140b9844abe64', | ||
types: ['AGENDA'], | ||
maxExpirationDays: 365, | ||
tenantCode: ['UC'], | ||
campusCode: ['03'], | ||
}, | ||
title: 'Title', | ||
description: 'this is a description', | ||
access: [], | ||
sections: [ | ||
{ | ||
id: '5c0ef394a31255000085e861', | ||
allowableCards: [ | ||
{ | ||
allowAttachments: false, | ||
type: 'BUA', | ||
}, | ||
], | ||
cards: [ | ||
{ | ||
id: '5c0ef394a31255000085e86a', | ||
type: 'BUA', | ||
attachments: [], | ||
comment: '', | ||
isRequired: false, | ||
isMovable: false, | ||
isEditable: true, | ||
allowAttachments: false, | ||
allowComment: false, | ||
details: { | ||
buaId: null, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
createdBy: { firstName: 'Saurit' }, | ||
createdDate: new Date('2018-12-10T23:15:32.289Z'), | ||
lastModifiedBy: { firstName: 'Saurit' }, | ||
lastModifiedDate: new Date('2018-12-10T23:15:32.289Z'), | ||
}); | ||
const clonedDocument = Document.cloneWithCommentsAllowed(document, { | ||
title: document.title, | ||
description: document.title, | ||
}); | ||
expect(clonedDocument._id.toString()).not.toEqual('5808fa7fae73b626daa89492'); | ||
expect(clonedDocument.sections[0].id.toString()).not.toEqual('5c0ef394a31255000085e861'); | ||
expect(clonedDocument.sections[0].cards[0].id.toString()).not.toEqual('5c0ef394a31255000085e86a'); | ||
expect(clonedDocument.createdBy).toBeNull(); | ||
expect(clonedDocument.lastModifiedBy).toBeNull(); | ||
expect(clonedDocument.template).toEqual(document.template); | ||
expect(clonedDocument.title).toEqual(document.title); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
890010
16147