Skip to content

Parse Dashboard randomly triggering afterSave(); on page refresh.  #775

@alexrmacleod

Description

@alexrmacleod

I was just browsing my parse-dash npm -g running locally. I went into the "Treatment" class and refreshed the page or something, really just harmlessly clicking around. Then boom! afterSave('Treatment', was triggered.

How to stop this from happening.

The function in my main.js cloud code

`

   Parse.Cloud.afterSave('Treatment', function (request, response) {
var treatment = request.object;
var first_name = treatment.get('first_name');
var last_name = treatment.get('last_name');
var email = treatment.get('email');
var address = treatment.get('address');
var country = treatment.get('country');
var phone = treatment.get('phone');
var token = treatment.get('token');
var customer_id = treatment.get('customer_id');
var location = treatment.get('location');
var type = treatment.get('type');

if (type === 'one-time') {

	// Charge that tasty stripe customer
	charge(1470000, "hkd", "Treatment", treatment.id, first_name, last_name, address, country, email, customer_id, function (bool) {
		if (bool === true) {
			response.success();
			// Send email that customer just bought something, id determins which email is sent
			notification(7, "[email protected]", email, { "FIRSTNAME": first_name, "LASTNAME": last_name, "EMAIL": email, "PHONE": phone, "ADDRESS": address, "COUNTRY": country, "ORDERID": treatment.id, "TYPE": type });
		} else {
			response.error();
			// Send error email to hello@xxxx so I will know before the customer gets too angry
		}
	});

	// Update stripe customer status
	update(customer_id, "Treatment " + type + " purchased", treatment.id, first_name, last_name, phone, address, country);

} else {

	// Make that tasty stripe customer a subscription
	subscription(customer_id, treatment.id, first_name, last_name, phone, address, country, 1, function (bool) {
		if (bool === true) {
			response.success();
			// Send email that customer just bought something, id determins which email is sent
			notification(7, "[email protected]", email, { "FIRSTNAME": first_name, "LASTNAME": last_name, "EMAIL": email, "PHONE": phone, "ADDRESS": address, "COUNTRY": country, "ORDERID": treatment.id, "TYPE": type });
		} else {
			response.error();
			// Send error email to hello@xxxx so I will know before the customer gets too angry
		}
	});

	// Update stripe customer status
	update(customer_id, "Treatment " + type + " purchased", treatment.id, first_name, last_name, phone, address, country);
}
    });

`

Could this be the problem?

Alexs-MacBook-Air:~ alex$ npm -v parse-dashboard
3.10.10

in package.json
"parse": "~1.8.0",
"parse-server": "^2.2.16",

Alexs-MacBook-Air:~ alex$ node --version
v6.10.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    state:wont-fixWon’t be fixed with a clearly stated reason

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions