gePromotions method

Future<PromotionModel> gePromotions(
  1. String typeId
)

Implementation

Future<PromotionModel> gePromotions(String typeId) async {
  var promotion;
  var packs;
  GraphQLClient _client = graphQLConfiguration.clientToQuery();

  var homePromotionGql = """
                query getSingleEnableProductPromotionWithPack(\$typeId: String) {
          getSingleEnableProductPromotionWithPack(id: \$typeId) {
                _id
                title
                description
                status
                packs {
                  _id
                  sortOrder
                  packId {
                    _id
                    packSKU
                    packName
                    packDescription
                    packImage
                    __typename
                  }
                  __typename
                }
                __typename
              }
            }
          """;

  final vble = {
    "typeId": typeId,
  };
  QueryResult result = await _client.query(QueryOptions(
    document: gql(homePromotionGql),
    variables: vble,
    fetchPolicy: FetchPolicy.networkOnly,
  ));

  if (!result.hasException) {
    var promotionAvailable =
        result.data!['getSingleEnableProductPromotionWithPack'];

    if (promotionAvailable != null && promotionAvailable.length > 0) {
      if (promotionAvailable['packs'] != null &&
          promotionAvailable['packs'].length > 0) {
        promotionAvailable['packs'].forEach((element) => {
              packs = new Packs(
                  element['_id'],
                  element['sortOrder'],
                  new Pack(
                    element['packId']['_id'],
                    element['packId']['packDescription'],
                    element['packId']['packImage'],
                    element['packId']['packName'],
                    element['packId']['packSKU'],
                  )),
              packList.add(packs)
            });
      }

      promotion = new PromotionModel(
          promotionAvailable['_id'],
          promotionAvailable['description'],
          promotionAvailable['title'],
          promotionAvailable['status'],
          packList);
    }
    return promotion;
  }
  return promotion;
}