import AV from 'leanengine'
const hook = new HookFunction()
.connect(async ({ object: folder }) => {
const comments = await new AV.Query('File').equalTo('folder', folder).count()
if (comments.length > 0) throw 'Forbidden Delete. There are files in this folder'
})
.connect(async ({ object: folder }) => {
const handles = await new AV.Query('Handle').equalTo('folder', folder).count()
if (comments.length > 0) throw 'Forbidden Delete. There are handles open on this folder'
})
.connect(async ({ object: folder }) => {
const protection = await new AV.Query('Protection').equalTo('folder', folder).first()
if (protection) throw 'Forbidden Delete. This dir is under protection'
})
AV.Cloud.beforeDelete('Folder', hook.hook)