openhim-core
Version:
The OpenHIM core application that provides logging and routing of http requests
122 lines (110 loc) • 2.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TransactionModel = exports.TransactionModelAPI = void 0;
var _mongoose = require("mongoose");
var _config = require("../config");
const RequestDef = {
host: String,
port: String,
path: String,
headers: Object,
querystring: String,
body: String,
method: String,
timestamp: {
type: Date,
required: true
}
}; // Response Schema definition
const ResponseDef = {
status: Number,
headers: Object,
body: String,
timestamp: Date
};
const ErrorDetailsDef = {
message: String,
stack: String
}; // OrchestrationMetadata Schema
const OrchestrationMetadataDef = {
name: {
type: String,
required: true
},
group: String,
request: {
type: RequestDef,
required: false
},
// this is needed to prevent Validation error, see https://github.com/jembi/openhim-console/issues/356#issuecomment-188708443
response: ResponseDef,
error: ErrorDetailsDef
}; // Route Schema
const RouteMetadataDef = {
name: {
type: String,
required: true
},
request: RequestDef,
response: ResponseDef,
orchestrations: [OrchestrationMetadataDef],
properties: Object,
error: ErrorDetailsDef
}; // Trasnaction schema
const TransactionSchema = new _mongoose.Schema({
clientID: _mongoose.Schema.Types.ObjectId,
clientIP: String,
parentID: {
type: _mongoose.Schema.Types.ObjectId,
index: true
},
childIDs: [_mongoose.Schema.Types.ObjectId],
channelID: {
type: _mongoose.Schema.Types.ObjectId
},
request: RequestDef,
response: ResponseDef,
routes: [RouteMetadataDef],
orchestrations: [OrchestrationMetadataDef],
properties: Object,
canRerun: {
type: Boolean,
default: true
},
autoRetry: {
type: Boolean,
default: false
},
// auto rerun this transaction (e.g. if error'd)
autoRetryAttempt: Number,
wasRerun: {
type: Boolean,
default: false
},
error: ErrorDetailsDef,
status: {
type: String,
required: true,
enum: ['Processing', 'Failed', 'Completed', 'Successful', 'Completed with error(s)']
}
});
TransactionSchema.index('request.timestamp');
TransactionSchema.index({
channelID: 1,
'request.timestamp': -1
});
TransactionSchema.index({
status: 1,
'request.timestamp': -1
});
TransactionSchema.index({
childIDs: 1,
'request.timestamp': -1
}); // Compile schema into Model
const TransactionModelAPI = _config.connectionAPI.model('Transaction', TransactionSchema);
exports.TransactionModelAPI = TransactionModelAPI;
const TransactionModel = _config.connectionDefault.model('Transaction', TransactionSchema);
exports.TransactionModel = TransactionModel;
//# sourceMappingURL=transactions.js.map