# HG changeset patch # User bsw # Date 1634045848 -7200 # Node ID ddbd46a34b6a689a0447b57e731fa4ccb62b1f95 # Parent d15767492064e011dcda10911c31c6f925bb6b74 Allow API lookup of member profile fields diff -r d15767492064 -r ddbd46a34b6a app/main/api/member.lua --- a/app/main/api/member.lua Mon Oct 11 11:03:04 2021 +0200 +++ b/app/main/api/member.lua Tue Oct 12 15:37:28 2021 +0200 @@ -54,6 +54,23 @@ selector:add_where{ "name ILIKE ? OR identification ILIKE ?", search, search } end +if app.scopes.read_profiles then + local profile_lookups = false + for i, field in ipairs(config.member_profile_fields) do + if field.api_lookup then + local value = param.get("profile_" .. field.id) + if value then + selector:add_where{ "member_profile.profile->>? = ?", field.id, value } + profile_lookups = true + end + end + end + if profile_lookups then + selector:join("member_profile", nil, "member_profile.member_id = member.id") + end +end + + local members = selector:exec() local r = json.object() r.result = execute.chunk{ module = "api", chunk = "_member", params = {