leanengine-extend
v0.1.0
Published
Add some useful methods to leanengine AV Object
Downloads
4
Readme
Helper functions to leancloud sdk
Client
toObject (avObject)
const member = new AV.Member({
team: new AV.Team(),
nickname
})
toObject(member).id === member.id
toObject(member).createdAt === member.createdAt
toObject(member).updatedAt === member.updatedAt
toObject(member).team === member.team
toObject(member).nickname === member.nickname
cors(req, res, next)
import AV from 'leanengine'
import express from 'express'
const app = express()
// Use cors middleware to fix leanengine 1.0.0-rc.1 cors header mismatch with client sdk error
app.use(cors)
app.use(AV.express())
proxy(protocol = 'https', host = 'api.leanengine.cn')
import AV from 'leanengine'
import express from 'express'
const app = express()
// Use proxy method before AV.express() to proxy non-cloud-function requests to
// lean cloud, and handle cloud function local.
app.use(proxy())
app.use(AV.express())
class HookFunction
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)