2 lines
3.0 KiB
JavaScript
2 lines
3.0 KiB
JavaScript
import{H as h,W as b}from"./index-b43045cf.js";import{t as f,g as x,b as S}from"./supabaseTableQuery-95762ff3.js";const y={storys:["title","sub_title"],challenge:["title","description"],step_challenges:["title"],matchs:["title","description"],competition:["title","description"],users:["name","email","phone"],videos:["title","description"],customers:["name","email","phone"],daily_questions:["question_text","option1_text","option2_text","designer_name"],books:["title","sub_title"],images_book:["title","description"],subscription_plans:["title","description"],products:["title_fa","title","code","sku","description"],brands:["title","description"],collections:["title","description"],discounts:["title","code"],orders:["note","address"],competition_winners:["match_title","match_description","user_name","user_mobile"],choir_registrations:["first_name","last_name","phone","province"],music_macharta_audios:["title","sub_title"],music_macharta_videos:["title"],channel_message:["text"]};function d(t,n,i){const r=i.trim();if(!r)return t;if(n==="comments"||n==="channel_message")return t.ilike("text",f(r));const s=y[n]??["title","description"];return t.or(x(s,r))}function g(t,n){return n!=null&&n.length&&n.forEach(i=>{i.hidden||!i.field||(t=S(t,i))}),t}function _(t,n){const{limit:i,page:r,sort:s,order:l}=n;if(i&&r){const c=(r-1)*i,o=c+i-1;t=t.range(c,o)}if(s!=null&&s.key)t=t.order(s.key,{ascending:s.order==="asc"}),s.key==="sort_order"&&(t=t.order("id",{ascending:!1}));else if(l){const c=l.split(",").map(o=>o.trim()).filter(Boolean);for(const o of c){const a=!o.startsWith("-"),e=o.replace(/^[-+]/,"");t=t.order(e,{ascending:a})}}return t}async function k(t,n){const{limit:i,filters:r,page:s,sort:l,order:c,select:o,search:a}=t;let e=h.from(n);o!=null&&o.length?e=e.select(o.join(","),{count:"exact"}):e=e.select("*",{count:"exact"}),a!=null&&a.trim()&&(e=d(e,n,a.trim())),e=g(e,r),e=_(e,{limit:i,page:s,sort:l,order:c});const{data:u,error:p,count:m}=await e;return p?(console.error("Supabase query error:",p),null):{data:u,count:m}}async function w(t,n){const{limit:i,filters:r,page:s,sort:l,order:c,select:o,search:a}=t;let e=b.from(n);o!=null&&o.length?e=e.select(o.join(","),{count:"exact"}):e=e.select("*",{count:"exact"}),a!=null&&a.trim()&&(e=d(e,n,a.trim())),e=g(e,r),e=_(e,{limit:i,page:s,sort:l,order:c});const{data:u,error:p,count:m}=await e;return p?(console.error("Supabase query error:",p),null):{data:u,count:m}}async function A(t,n="users"){const i=await k(t,n);if(!i)return{query:{...t,limit:t.limit||10,page:t.page||1,total:0},rows:[]};const r=((t.page||1)-1)*(t.limit||10),s=(i.data||[]).map((l,c)=>({...l,index:r+c}));return{query:{...t,limit:t.limit||10,page:t.page||1,total:i.count},rows:s}}async function F(t,n="users"){const i=await w(t,n);if(!i)return{query:{...t,limit:t.limit||10,page:t.page||1,total:0},rows:[]};const r=t.page||1,s=t.limit||10,l=(r-1)*s,c=(i.data||[]).map((o,a)=>({...o,index:l+a}));return{query:{...t,limit:s,page:r,total:i.count},rows:c}}export{A as TableEngineRequest,F as TableEngineShopRequest,k as buildSupabaseQuery,w as buildSupabaseShopQuery};
|