2 lines
3.5 KiB
JavaScript
2 lines
3.5 KiB
JavaScript
import{_ as p,$ as _,P as y,Z as M,O as f,Q as h,U as w}from"./index-1ba0f9ec.js";async function S(){return await _("matchs")}async function E(s,e){const t=await y("matchs",s,e);return Array.isArray(t)?t:[t]}async function v(s){const e=await M("matchs",s),t=await _("questions",{match_id:s});return{...e,questions:Array.isArray(t)?t:[]}}async function D(s){const e=await f("matchs",s.match);for(const t of s.questions)await f("questions",{match_id:e.id,question:t.question,options:t.options,correct_answer:t.correct_answer});return e}async function W(s,e){await y("matchs",s,e.match);const t=await _("questions",{match_id:s});for(const a of Array.isArray(t)?t:[])await h("questions",a.id);for(const a of e.questions)await f("questions",{match_id:s,question:a.question,options:a.options,correct_answer:a.correct_answer});return{id:s}}async function T(s){const e=await _("questions",{match_id:s});for(const t of Array.isArray(e)?e:[])await h("questions",t.id);await h("matchs",s)}async function k(s){const{TableEngineRequest:e}=await p(()=>import("./buildSupabaseQuery-2323f568.js"),["assets/buildSupabaseQuery-2323f568.js","assets/index-1ba0f9ec.js","assets/index-cb402307.css"]),t={...s};!t.sort&&!t.order&&(t.order="-id");const a=await e(t,"matchs");try{if(Array.isArray(a==null?void 0:a.rows)){const r=t.page||1,c=t.limit||200,u=(r-1)*c,d=a.rows.map((o,n)=>({id:o.id,title:o.title??"",description:o.description??"",created_at:o.created_at??"",index:u+n,...o}));return{...a,rows:d}}}catch(r){console.log("[getMatchTable] normalize error:",r)}return a}async function b(s){const{TableEngineRequest:e}=await p(()=>import("./buildSupabaseQuery-2323f568.js"),["assets/buildSupabaseQuery-2323f568.js","assets/index-1ba0f9ec.js","assets/index-cb402307.css"]),t={...s};return!t.sort&&!t.order&&(t.order="-created_at"),e(t,"competition_winners")}const g=1e3;async function P(s){var a;const e=[];let t=1;for(;;){const r=await b({page:t,limit:g,filters:[{field:"match_id",op:"eq",value:s,cr:"and",hidden:!1,type:"number"}]}),c=r.rows||[];if(!c.length)break;e.push(...c);const u=(a=r.query)==null?void 0:a.total;if(typeof u=="number"&&e.length>=u||c.length<g)break;t++}return e}async function x(s){const e=s.map(a=>{const r={match_id:a.match_id,rank:a.rank};return a.user_id!==void 0?r.user_id=a.user_id:a.winner_id!==void 0&&(r.user_id=a.winner_id),r}),t=await f("winners_match",e);return Array.isArray(t)?t:[t]}async function Q(s){const e=await _("winners_match",{match_id:s,order:"rank"});if(!Array.isArray(e)||!e.length)return[];const t=[...new Set(e.map(n=>n.user_id||n.winner_id).filter(Boolean))];if(!t.length)return[];const[a,r]=await Promise.all([w("users",{includeIn:{field:"id",values:t.map(String)},limit:t.length,page:1}),w("answers",{filters:[{field:"match_id",op:"eq",value:s}],includeIn:{field:"user_id",values:t.map(String)},limit:5e3,page:1,select:["user_id","score"]})]),c=a.rows||[],u=r.rows||[],d=new Map;c.forEach(n=>{d.set(n.id,n),d.set(String(n.id),n)});const o=new Map;return u.forEach(n=>{o.set(n.user_id,n.score||0),o.set(String(n.user_id),n.score||0)}),e.map(n=>{const m=n.user_id||n.winner_id,i=d.get(m)||d.get(String(m))||c.find(A=>String(A.id)===String(m))||{},q=o.get(m)||o.get(String(m))||0;let l="نامشخص";return i&&Object.keys(i).length>0&&(i.name?l=i.name:i.first_name||i.last_name?l=`${i.first_name||""} ${i.last_name||""}`.trim():i.phone?l=i.phone:i.email?l=i.email:i.username&&(l=i.username)),{...n,user_name:l,user_mobile:(i==null?void 0:i.phone)||"",user_email:(i==null?void 0:i.email)||"",score:Number(q)||0}})}export{D as a,v as b,E as c,T as d,b as e,S as f,k as g,P as h,Q as i,x as s,W as u};
|