@grouparoo/core
Version:
The Grouparoo Core
39 lines (38 loc) • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PropertyDestroy = void 0;
const clsTask_1 = require("../../classes/tasks/clsTask");
const Property_1 = require("../../models/Property");
class PropertyDestroy extends clsTask_1.CLSTask {
constructor() {
super(...arguments);
this.name = "property:destroy";
this.description = "wait for dependencies to finish being deleted, then delete the property";
this.frequency = 0;
this.queue = "properties";
this.inputs = {
propertyId: { required: true },
};
}
async runWithinTransaction({ propertyId }) {
const property = await Property_1.Property.scope(null).findOne({
where: { id: propertyId, state: "deleted" },
});
// the property may have been force-deleted
if (!property)
return;
// check if we're still being used by something
try {
await Property_1.Property.ensureNotInUse(property);
}
catch (error) {
if (error.message.match(/cannot delete property/)) {
return; // check back later
}
throw error;
}
// all things that depend on this property have been cleaned up
await property.destroy();
}
}
exports.PropertyDestroy = PropertyDestroy;