CollectionReference<T extends Object?> constructor

CollectionReference<T extends Object?>(
  1. {required QueryHelper helper,
  2. required FusabaseOracledb oracledb,
  3. required String path,
  4. dynamic parent_}
)

Implementation

CollectionReference(
    {required QueryHelper helper,
    required FusabaseOracledb oracledb,
    required String path,
    dynamic parent_})
    : _id = "",
      super(
          helper: helper, oracledb: oracledb, path: path, parent: parent_) {
  path = path.toString().trim();
  List<String> tokens = path.split('/');

  _id = tokens.removeAt(tokens.length - 1);
  type = "collection";

  // if (_id == "") {
  //   throw Utils.oracledbErrorHandler(
  //       400, OracledbErrorMessages.incorrectDocumentId, null);
  // }
  if (parent_ != null) {
    _parent = parent_;
  } else {
    if (tokens.isEmpty) {
      _parent = null;
    } else {
      _parent = oracledb.doc(tokens.join('/'));
    }
  }
  _path = (_parent != null) ? [..._parent._path] : [];
  _path.add(_id);

  if (_path.length % 2 == 0) {
    throw Utils.oracledbErrorHandler(
        400, OracledbErrorMessages.incorrectCollectionPath, null);
  }

  if (_parent is CollectionReference) {
    throw Utils.oracledbErrorHandler(
        400, OracledbErrorMessages.notCollectionReference, null);
  }
}