@fayz-ai/plugin-tables 0.14.16 → 0.14.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data/core-supabase.d.ts.map +1 -1
- package/dist/index.js +21 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-supabase.d.ts","sourceRoot":"","sources":["../../src/data/core-supabase.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AA2FjD,MAAM,WAAW,sBAAsB;IACrC,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,MAAM,GAAG,SAAS,GAAG,IAAI,CAAA;IACzC;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,EAAE;QACV,YAAY,EAAE,MAAM,CAAA;QACpB,uEAAuE;QACvE,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,mDAAmD;QACnD,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,yCAAyC;QACzC,GAAG,CAAC,EAAE,MAAM,CAAA;KACb,CAAA;CACF;AAED,MAAM,WAAW,yBAAyB;IACxC,8EAA8E;IAC9E,MAAM,CAAC,EAAE,sBAAsB,CAAA;CAChC;AAID,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,kBAAkB,
|
|
1
|
+
{"version":3,"file":"core-supabase.d.ts","sourceRoot":"","sources":["../../src/data/core-supabase.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AA2FjD,MAAM,WAAW,sBAAsB;IACrC,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,MAAM,GAAG,SAAS,GAAG,IAAI,CAAA;IACzC;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,EAAE;QACV,YAAY,EAAE,MAAM,CAAA;QACpB,uEAAuE;QACvE,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,mDAAmD;QACnD,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,yCAAyC;QACzC,GAAG,CAAC,EAAE,MAAM,CAAA;KACb,CAAA;CACF;AAED,MAAM,WAAW,yBAAyB;IACxC,8EAA8E;IAC9E,MAAM,CAAC,EAAE,sBAAsB,CAAA;CAChC;AAID,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,kBAAkB,CA6iGhG"}
|
package/dist/index.js
CHANGED
|
@@ -1548,6 +1548,18 @@ function createCoreTablesProvider(options) {
|
|
|
1548
1548
|
function shortRef(orderId) {
|
|
1549
1549
|
return orderId ? `#${String(orderId).slice(0, 8)}` : void 0;
|
|
1550
1550
|
}
|
|
1551
|
+
async function shopOrderNumbers(orderIds) {
|
|
1552
|
+
const numbers = /* @__PURE__ */ new Map();
|
|
1553
|
+
if (orderIds.length === 0) return numbers;
|
|
1554
|
+
try {
|
|
1555
|
+
const { data } = await db().from("plg_shop_order_extensions").select("order_id, order_number").in("order_id", orderIds);
|
|
1556
|
+
for (const n of data ?? []) {
|
|
1557
|
+
if (n.order_number != null && String(n.order_number).trim()) numbers.set(n.order_id, String(n.order_number));
|
|
1558
|
+
}
|
|
1559
|
+
} catch {
|
|
1560
|
+
}
|
|
1561
|
+
return numbers;
|
|
1562
|
+
}
|
|
1551
1563
|
function assertTocou(linhas, oQue) {
|
|
1552
1564
|
if (!Array.isArray(linhas) || linhas.length === 0) {
|
|
1553
1565
|
throw new Error(`Nenhuma linha foi atualizada ao gravar ${oQue}. Verifique as permiss\xF5es.`);
|
|
@@ -1750,7 +1762,9 @@ function createCoreTablesProvider(options) {
|
|
|
1750
1762
|
);
|
|
1751
1763
|
return {
|
|
1752
1764
|
id: order.id,
|
|
1753
|
-
|
|
1765
|
+
// A storefront order's number is the shop's (`shopOrderNumbers`):
|
|
1766
|
+
// the printed bill must carry the «#253» the card and the customer use.
|
|
1767
|
+
reference: order.reference_number ?? (order.channel === "shop" ? (await shopOrderNumbers([order.id])).get(order.id) : void 0) ?? shortRef(order.id),
|
|
1754
1768
|
status: order.status,
|
|
1755
1769
|
guests: row.guests ?? 0,
|
|
1756
1770
|
seatedAt: row.seated_at,
|
|
@@ -2128,14 +2142,14 @@ function createCoreTablesProvider(options) {
|
|
|
2128
2142
|
* o dinheiro existia e ninguém alcançava para fechar.
|
|
2129
2143
|
*/
|
|
2130
2144
|
async getOrderById(orderId) {
|
|
2131
|
-
const { data, error } = await db().from(ORDER_EXT).select("order_id, guests, seated_at, service_charge_percent, orders!inner(id, reference_number, status, notes, assignee_id, party_id, subtotal, discount, tax, total, currency)").eq("order_id", orderId).not("orders.status", "in", '("completed","cancelled")').limit(1);
|
|
2145
|
+
const { data, error } = await db().from(ORDER_EXT).select("order_id, guests, seated_at, service_charge_percent, orders!inner(id, reference_number, channel, status, notes, assignee_id, party_id, subtotal, discount, tax, total, currency)").eq("order_id", orderId).not("orders.status", "in", '("completed","cancelled")').limit(1);
|
|
2132
2146
|
if (error) throw new Error(error.message);
|
|
2133
2147
|
const row = (data ?? [])[0];
|
|
2134
2148
|
if (!row) return null;
|
|
2135
2149
|
return carregarComanda(row, Array.isArray(row.orders) ? row.orders[0] : row.orders);
|
|
2136
2150
|
},
|
|
2137
2151
|
async getTableOrder(tableId) {
|
|
2138
|
-
const { data, error } = await db().from(ORDER_EXT).select("order_id, guests, seated_at, service_charge_percent, orders!inner(id, reference_number, status, notes, assignee_id, party_id, subtotal, discount, tax, total, currency)").eq("table_id", tableId).not("orders.status", "in", '("completed","cancelled")').order("seated_at", { ascending: false }).limit(1);
|
|
2152
|
+
const { data, error } = await db().from(ORDER_EXT).select("order_id, guests, seated_at, service_charge_percent, orders!inner(id, reference_number, channel, status, notes, assignee_id, party_id, subtotal, discount, tax, total, currency)").eq("table_id", tableId).not("orders.status", "in", '("completed","cancelled")').order("seated_at", { ascending: false }).limit(1);
|
|
2139
2153
|
if (error) throw new Error(error.message);
|
|
2140
2154
|
const row = (data ?? [])[0];
|
|
2141
2155
|
if (!row) return null;
|
|
@@ -2666,6 +2680,9 @@ function createCoreTablesProvider(options) {
|
|
|
2666
2680
|
q = especie ? q.or(`channel.eq.${channel},and(channel.is.null,kind.eq.${especie}),${site}`) : q.or(`channel.eq.${channel},${site}`);
|
|
2667
2681
|
const { data, error } = await q;
|
|
2668
2682
|
if (error) throw new Error(error.message);
|
|
2683
|
+
const shopNumber = await shopOrderNumbers(
|
|
2684
|
+
(data ?? []).filter((r) => r.channel === "shop" && !r.reference_number).map((r) => r.id)
|
|
2685
|
+
);
|
|
2669
2686
|
return (data ?? []).map((r) => {
|
|
2670
2687
|
const site2 = r.site ?? null;
|
|
2671
2688
|
const ext = Array.isArray(r[ORDER_EXT]) ? r[ORDER_EXT][0] : r[ORDER_EXT];
|
|
@@ -2673,7 +2690,7 @@ function createCoreTablesProvider(options) {
|
|
|
2673
2690
|
id: r.id,
|
|
2674
2691
|
// O NÚMERO da comanda: é o que o V1 escreve no cartão do delivery
|
|
2675
2692
|
// (`#{order.number}`) e na ficha do dock («Balcão #1234»).
|
|
2676
|
-
reference: r.reference_number ?? null,
|
|
2693
|
+
reference: r.reference_number ?? shopNumber.get(r.id) ?? null,
|
|
2677
2694
|
// De ONDE veio: o cartão do V1 mostra isto logo abaixo do número.
|
|
2678
2695
|
source: ext?.delivery_source ?? null,
|
|
2679
2696
|
channel: r.channel ?? channel,
|