|
| 1 | +/* |
| 2 | + Copyright [2016] [Relevance Lab] |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +const logger = require('_pr/logger')(module); |
| 18 | +const mongoose = require('mongoose'); |
| 19 | +const Schema = mongoose.Schema; |
| 20 | + |
| 21 | +const botHistoryAuditTrailSchema = new Schema ({ |
| 22 | + botId: { |
| 23 | + type: String |
| 24 | + }, |
| 25 | + actionLogId: { |
| 26 | + type: String, |
| 27 | + required: true |
| 28 | + }, |
| 29 | + botRunId: { |
| 30 | + type: String, |
| 31 | + required: true |
| 32 | + }, |
| 33 | + botExecutorName: { |
| 34 | + type: String |
| 35 | + }, |
| 36 | + input: { |
| 37 | + type : Schema.Types.Mixed, |
| 38 | + default : null |
| 39 | + }, |
| 40 | + output: { |
| 41 | + type : Schema.Types.Mixed, |
| 42 | + default : null |
| 43 | + }, |
| 44 | + createdOn: { |
| 45 | + type: Number, |
| 46 | + required: true, |
| 47 | + default: Date.now() |
| 48 | + }, |
| 49 | + lastUpdateOn: { |
| 50 | + type: Number, |
| 51 | + required: true, |
| 52 | + default: Date.now() |
| 53 | + } |
| 54 | +}) |
| 55 | + |
| 56 | +botHistoryAuditTrailSchema.index({ actionLogId: 1, createdOn:1 }, { unique: true }); |
| 57 | + |
| 58 | +botHistoryAuditTrailSchema.statics.addBotHistoryAudit = function (auditObj, callback) { |
| 59 | + let audit = new this(auditObj); |
| 60 | + audit.save(callback); |
| 61 | +}; |
| 62 | + |
| 63 | +botHistoryAuditTrailSchema.statics.insertBotHistoryAudit = function (auditList, callback) { |
| 64 | + let auditListDB = auditList.map((auditObj) => { |
| 65 | + let audit = new this(auditObj); |
| 66 | + audit.createdOn = Date.now(); |
| 67 | + audit.lastUpdateOn = Date.now(); |
| 68 | + return audit; |
| 69 | + }); |
| 70 | + this.insertMany(auditListDB, callback); |
| 71 | +}; |
| 72 | + |
| 73 | +botHistoryAuditTrailSchema.statics.findByQuery = function (query, project, options, callback) { |
| 74 | + return this.find(query, project, options, callback); |
| 75 | +}; |
| 76 | + |
| 77 | +botHistoryAuditTrailSchema.statics.findOneByQuery = function (query, project, options, callback) { |
| 78 | + return this.findOne(query, project, options, callback); |
| 79 | +}; |
| 80 | + |
| 81 | +const botHistoryAuditTrail = mongoose.model('botHistoryAuditTrail', botHistoryAuditTrailSchema); |
| 82 | +module.exports = botHistoryAuditTrail; |
0 commit comments