Start Monetary Implementation (RIS)
This commit is contained in:
84
src/server/models/movement.js
Executable file
84
src/server/models/movement.js
Executable file
@@ -0,0 +1,84 @@
|
||||
const mongoose = require('mongoose').set('debug', false);
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = 'F';
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true;
|
||||
});
|
||||
|
||||
const MovementSchema = new Schema({
|
||||
_id: {
|
||||
type: Number,
|
||||
},
|
||||
transactionDate: {
|
||||
type: Date
|
||||
},
|
||||
accountFromId: {
|
||||
type: Number,
|
||||
},
|
||||
accountToId: {
|
||||
type: Number,
|
||||
},
|
||||
amount: {
|
||||
type: Number,
|
||||
},
|
||||
causal: {
|
||||
type: String,
|
||||
},
|
||||
residual: {
|
||||
type: Number,
|
||||
},
|
||||
expiringDate: {
|
||||
type: Date
|
||||
},
|
||||
});
|
||||
|
||||
MovementSchema.statics.findAllIdApp = async function(idapp) {
|
||||
const MyMovement = this;
|
||||
|
||||
const myfind = {idapp};
|
||||
|
||||
return MyMovement.find(myfind, (err, arrrec) => {
|
||||
return arrrec;
|
||||
});
|
||||
};
|
||||
|
||||
MovementSchema.pre('save', async function(next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await Movement.findOne().limit(1).sort({_id: -1});
|
||||
if (!!myrec) {
|
||||
if (myrec._doc._id === 0)
|
||||
this._id = 1;
|
||||
else
|
||||
this._id = myrec._doc._id + 1;
|
||||
|
||||
} else {
|
||||
this._id = 1;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
MovementSchema.statics.getFieldsForSearch = function() {
|
||||
return [
|
||||
{field: 'nome_conto', type: tools.FieldType.string},
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
MovementSchema.statics.executeQueryTable = function(idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
};
|
||||
|
||||
const Movement = mongoose.model('Movement', MovementSchema);
|
||||
|
||||
module.exports = {Movement};
|
||||
Reference in New Issue
Block a user