# All files / src/model transactions.coffee

100% Statements 7/7
100% Branches 0/0
100% Functions 0/0
100% Lines 7/7

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    721x
    1x
    1x
    1x

    1x

    1x

    1x
     mongoose = require "mongoose"
    server = require "../server"
    connectionDefault = server.connectionDefault
    Schema = mongoose.Schema

    # Request Schema definition
    RequestDef =
      "host":         String
      "port":         String
      "path" :        String
      "headers":      Object
      "querystring":  String
      "body":         String
      "method":       String
      "timestamp":    type: Date, required: true

    # Response Schema definition
    ResponseDef =
      "status" :    Number
      "headers":    Object
      "body":       String
      "timestamp":  Date

    ErrorDetailsDef =
      "message": String
      "stack":   String

    # OrchestrationMetadata Schema
    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
    RouteMetadataDef =
      "name" :          type: String, required: true
      "request":        RequestDef
      "response":       ResponseDef
      "orchestrations": [OrchestrationMetadataDef]
      "properties":     Object
      "error":          ErrorDetailsDef

    # Trasnaction schema
    TransactionSchema = new Schema
      "clientID":           Schema.Types.ObjectId
      "clientIP":           String
      "parentID":           Schema.Types.ObjectId
      "childIDs":           [Schema.Types.ObjectId]
      "channelID":          type: Schema.Types.ObjectId, index: true
      "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
        index:    true
        enum:     ['Processing', 'Failed', 'Completed', 'Successful', 'Completed with error(s)']

    TransactionSchema.index "request.timestamp"

    # Compile schema into Model
    exports.Transaction = connectionDefault.model 'Transaction', TransactionSchema