call method

  1. @override
Future<Response> call(
  1. ModularArguments args,
  2. Config config
)
override

Implementation

@override
Future<Response> call(ModularArguments args, Config config) async {
  try {
    await config.initMongo();
    var mongo = config.mongo!.conn!;

    var entity = args.params["module"];

    var coll = mongo.collection(entity);

    var result = await coll.findOne();

    if (result != null) {
      await _createFile(result, entity);
      return HttpResponse.ok(jsonEncode(
          {"status": "success", "message": "File created successufully"}));
    }

    throw Exception(
        "Failed at find some data on collection, make sure your collection exists and has at least one document inserted");
  } catch (e) {
    throw HttpResponse.error(jsonEncode({"error": e.toString()}));
  } finally {
    await config.disconnectMongo();
  }
}