checkByFixedFields static method

bool checkByFixedFields(
  1. List<String> fields,
  2. Map<String, dynamic> resource,
  3. Map<String, dynamic> request
)

Only Use Update Operation

Implementation

static bool checkByFixedFields(List<String> fields,
    Map<String, dynamic> resource, Map<String, dynamic> request) {
  /// Request {
  ///     '$inc' :  {
  ///         'field.subfield1.subfield2...' : 2
  ///     }
  /// }
  for (var op in request.keys) {
    /// If update operation key not start update operations
    /// Request denied
    ///
    /// Mongo Db Update Operations Documentation :
    /// https://docs.mongodb.com/manual/reference/operator/update/
    ///
    if (op.startsWith('\$')) {
      // ignore: avoid_as
      var operation = request[op];

      Iterable<String> opFields = operation.keys;
      for (var operationFieldRaw in opFields) {
        /// If update operation field key contains fixed keys
        /// Request denied
        if (fields.contains(operationFieldRaw)) {
          return false;
        }
      }
    } else {
      return false;
    }
  }

  /// In Default return true

  return true;
}