-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support for credit notes and allocations
- Loading branch information
Jordan Walsh
committed
Mar 22, 2017
1 parent
4075135
commit 0e3efa4
Showing
5 changed files
with
471 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,23 @@ | ||
var _ = require('lodash'), | ||
Entity = require('../entity'), | ||
logger = require('../../logger'), | ||
dateformat = require('dateformat'), | ||
fs = require('fs') | ||
TrackingOptionSchema = require('../shared').TrackingOptionSchema; | ||
|
||
var AttachmentSchema = new Entity.SchemaObject({ | ||
AttachmentID: { type: String, toObject: 'never' }, | ||
FileName: { type: String, toObject: 'always' }, | ||
Url: { type: String, toObject: 'always' }, | ||
MimeType: { type: String, toObject: 'always' }, | ||
ContentLength: { type: Number, toObject: 'always' } | ||
}); | ||
|
||
|
||
var Attachment = Entity.extend(AttachmentSchema, { | ||
var TrackingOption = Entity.extend(TrackingOptionSchema, { | ||
constructor: function(application, data, options) { | ||
logger.debug('Attachment::constructor'); | ||
logger.debug('TrackingOption::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
initialize: function(data, options) {}, | ||
getContent: function(ownerPath) { | ||
return this.application.core.attachments.getContent(ownerPath, this.FileName); | ||
changes: function(options) { | ||
return this._super(options); | ||
}, | ||
save: function(ownerPath, streamOrFilePath) { | ||
var self = this; | ||
var path = ownerPath + '/Attachments/' + this.FileName; | ||
|
||
var base64string = base64_encode(streamOrFilePath); | ||
console.log(base64string); | ||
console.log(path); | ||
|
||
return this.application.postEntity(path, base64string, { type: this.MimeType }) | ||
.then(function(ret) { | ||
console.log(ret); | ||
return ret.response.Attachments.Attachment; | ||
}) | ||
.catch(function(err) { | ||
console.log(err); | ||
}) | ||
|
||
function base64_encode(file) { | ||
// read binary data | ||
var bitmap = fs.readFileSync(file); | ||
// convert binary data to base64 encoded string | ||
return new Buffer(bitmap).toString('base64'); | ||
} | ||
_toObject: function(options) { | ||
return this._super(options); | ||
}, | ||
delete: function() { | ||
return this.deleteEntities({ id: this.TrackingOptionID }); | ||
} | ||
}); | ||
|
||
|
||
module.exports = Attachment; | ||
module.exports.AttachmentSchema = AttachmentSchema; | ||
module.exports = TrackingOption; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.