purchaseCodeActions.js 2.5 KB
'use strict';

import ReactNative from 'react-native';
import PurchaseCodeService from '../../services/PurchaseCodeService';

const {

	GET_MINE_LIMIT_PURCHASE_LIST_REQUEST,
	GET_MINE_LIMIT_PURCHASE_LIST_SUCCESS,
	GET_MINE_LIMIT_PURCHASE_LIST_FAILURE,

	DELETE_MINE_LIMIT_PURCHASE_REQUEST,
	DELETE_MINE_LIMIT_PURCHASE_SUCCESS,
	DELETE_MINE_LIMIT_PURCHASE_FAILURE,

} = require('../../constants/actionTypes').default;

export function MineLimitPurchaseListRequest() {
    return {
        type: GET_MINE_LIMIT_PURCHASE_LIST_REQUEST,
    };
}

export function MineLimitPurchaseListSuccess(json) {
    return {
        type: GET_MINE_LIMIT_PURCHASE_LIST_SUCCESS,
        payload: json
    }
}

export function MineLimitPurchaseListFailure(error) {
    return {
        type: GET_MINE_LIMIT_PURCHASE_LIST_FAILURE,
        payload: error
    }
}

export function getMineLimitPurchaseList() {
	return (dispatch, getState) => {
		let {app, purchaseCode} = getState();

		let fetchMineLimitPurchaseList = (uid) => {
			dispatch(MineLimitPurchaseListRequest());
			return new PurchaseCodeService(app.host).getMineLimitPurchaseList(uid)
			.then(json => {
				dispatch(MineLimitPurchaseListSuccess(json));
			})
			.catch(error => {
				dispatch(MineLimitPurchaseListFailure(error));
			});
		}

		ReactNative.NativeModules.YH_CommonHelper.uid()
		.then(uid => {
			fetchMineLimitPurchaseList(uid);
		})
		.catch(error => {
		});
	};
}

export function fetchDeleteMinePurchaseCodeLimitCode() {
    return {
        type: DELETE_MINE_LIMIT_PURCHASE_REQUEST,
    };
}

export function DeleteMinePurchaseCodeLimitCodeSuccess(json) {
    return {
        type: DELETE_MINE_LIMIT_PURCHASE_SUCCESS,
        payload: json
    }
}

export function DeleteMinePurchaseCodeLimitCodeFailure(error) {
    return {
        type: DELETE_MINE_LIMIT_PURCHASE_FAILURE,
        payload: error
    }
}

export function deleteMinePurchaseCodeLimitCode(data) {
	return (dispatch, getState) => {
		let {app, purchaseCode} = getState();
		let limitCode = data.limitCode;
		let fetchDeleteMinePurchaseCodeLimitCode = (uid) => {
			dispatch(MineLimitPurchaseListRequest());
			return new PurchaseCodeService(app.host).DeleteMinePurchaseCodeLimitCode(uid,limitCode)
			.then(json => {
				dispatch(DeleteMinePurchaseCodeLimitCodeSuccess(json));
			})
			.catch(error => {
				dispatch(DeleteMinePurchaseCodeLimitCodeFailure(error));
			});
		}

		ReactNative.NativeModules.YH_CommonHelper.uid()
		.then(uid => {
			fetchDeleteMinePurchaseCodeLimitCode(uid);
		})
		.catch(error => {
		});
	};
}