Merge branch 'master' into 'dev'
# Conflicts: # src/lib/core/handlers/messageHandler.ts # src/lib/core/services/sheetService.ts
This commit is contained in:
commit
98d9a279d7
14 changed files with 265 additions and 98 deletions
|
|
@ -11,21 +11,21 @@ import {
|
|||
} from '../stores/sheetStore';
|
||||
import { setGenLayoutGenerating } from '../stores/genLayoutStore';
|
||||
|
||||
export function requestCatalogs(country: string): boolean {
|
||||
return sendCommandRequest('sheet', {
|
||||
export async function requestCatalogs(country: string): Promise<boolean> {
|
||||
return await sendCommandRequest('sheet', {
|
||||
country: country,
|
||||
param: 'catalogs'
|
||||
});
|
||||
}
|
||||
|
||||
export function requestPriceSlots(country: string): boolean {
|
||||
return sendCommandRequest('sheet', {
|
||||
export async function requestPriceSlots(country: string): Promise<boolean> {
|
||||
return await sendCommandRequest('sheet', {
|
||||
country: country,
|
||||
param: 'priceslot'
|
||||
});
|
||||
}
|
||||
|
||||
export function updatePriceSlot(
|
||||
export async function updatePriceSlot(
|
||||
country: string,
|
||||
content: {
|
||||
slot: number;
|
||||
|
|
@ -33,48 +33,52 @@ export function updatePriceSlot(
|
|||
description: string;
|
||||
products: { product_code: string; price: number | null; row_index?: number }[];
|
||||
}
|
||||
): boolean {
|
||||
return sendCommandRequest('sheet', {
|
||||
): Promise<boolean> {
|
||||
return await sendCommandRequest('sheet', {
|
||||
country: country,
|
||||
content: content,
|
||||
param: 'update/priceslot'
|
||||
});
|
||||
}
|
||||
|
||||
export function enterRoom(country: string, catalog: string): boolean {
|
||||
return sendCommandRequest('sheet', {
|
||||
export async function enterRoom(country: string, catalog: string): Promise<boolean> {
|
||||
return await sendCommandRequest('sheet', {
|
||||
country: country,
|
||||
catalog: catalog,
|
||||
param: 'enter'
|
||||
});
|
||||
}
|
||||
|
||||
export function sendHeartbeat(country: string, catalog: string): boolean {
|
||||
return sendCommandRequest('sheet', {
|
||||
export async function sendHeartbeat(country: string, catalog: string): Promise<boolean> {
|
||||
return await sendCommandRequest('sheet', {
|
||||
country: country,
|
||||
catalog: catalog,
|
||||
param: 'heartbeat'
|
||||
});
|
||||
}
|
||||
|
||||
export function exitRoom(country: string, catalog: string): boolean {
|
||||
return sendCommandRequest('sheet', {
|
||||
export async function exitRoom(country: string, catalog: string): Promise<boolean> {
|
||||
return await sendCommandRequest('sheet', {
|
||||
country: country,
|
||||
catalog: catalog,
|
||||
param: 'exit'
|
||||
});
|
||||
}
|
||||
|
||||
export function requestCatalogMenu(country: string, catalog: string): boolean {
|
||||
return sendCommandRequest('sheet', {
|
||||
export async function requestCatalogMenu(country: string, catalog: string): Promise<boolean> {
|
||||
return await sendCommandRequest('sheet', {
|
||||
country: country,
|
||||
catalog: catalog,
|
||||
param: 'catalog/menu'
|
||||
});
|
||||
}
|
||||
|
||||
export function updateMenu(country: string, catalog: string, content: any[]): boolean {
|
||||
return sendCommandRequest('sheet', {
|
||||
export async function updateMenu(
|
||||
country: string,
|
||||
catalog: string,
|
||||
content: any[]
|
||||
): Promise<boolean> {
|
||||
return await sendCommandRequest('sheet', {
|
||||
country: country,
|
||||
catalog: catalog,
|
||||
content: content,
|
||||
|
|
@ -82,9 +86,9 @@ export function updateMenu(country: string, catalog: string, content: any[]): bo
|
|||
});
|
||||
}
|
||||
|
||||
export function addMenu(country: string, catalog: string, content: any[]): boolean {
|
||||
export async function addMenu(country: string, catalog: string, content: any[]): Promise<boolean> {
|
||||
console.log('[sheetService] Adding menu:', { country, catalog, content });
|
||||
const sent = sendCommandRequest('sheet', {
|
||||
const sent = await sendCommandRequest('sheet', {
|
||||
country: country,
|
||||
catalog: catalog,
|
||||
content: content,
|
||||
|
|
@ -94,9 +98,13 @@ export function addMenu(country: string, catalog: string, content: any[]): boole
|
|||
return sent;
|
||||
}
|
||||
|
||||
export function deleteMenu(country: string, catalog: string, targetIds: number[]): boolean {
|
||||
export async function deleteMenu(
|
||||
country: string,
|
||||
catalog: string,
|
||||
targetIds: number[]
|
||||
): Promise<boolean> {
|
||||
const content = targetIds.map((id) => ({ target_id: id }));
|
||||
return sendCommandRequest('sheet', {
|
||||
return await sendCommandRequest('sheet', {
|
||||
country: country,
|
||||
catalog: catalog,
|
||||
content: content,
|
||||
|
|
@ -104,12 +112,12 @@ export function deleteMenu(country: string, catalog: string, targetIds: number[]
|
|||
});
|
||||
}
|
||||
|
||||
export function swapMenu(
|
||||
export async function swapMenu(
|
||||
country: string,
|
||||
catalog: string,
|
||||
swaps: { source_id: number; target_id: number }[]
|
||||
): boolean {
|
||||
return sendCommandRequest('sheet', {
|
||||
): Promise<boolean> {
|
||||
return await sendCommandRequest('sheet', {
|
||||
country: country,
|
||||
catalog: catalog,
|
||||
content: swaps,
|
||||
|
|
@ -117,7 +125,7 @@ export function swapMenu(
|
|||
});
|
||||
}
|
||||
|
||||
export function requestListMenu(country: string, boxid?: string): boolean {
|
||||
export async function requestListMenu(country: string, boxid?: string): Promise<boolean> {
|
||||
const curr_user = get(auth);
|
||||
|
||||
let user_info: any = {};
|
||||
|
|
@ -134,7 +142,7 @@ export function requestListMenu(country: string, boxid?: string): boolean {
|
|||
|
||||
console.log('[sheetService] Sending list_menu request for country:', country, 'boxid:', boxid);
|
||||
|
||||
return sendMessage({
|
||||
return await sendMessage({
|
||||
type: 'list_menu',
|
||||
payload: {
|
||||
user_info,
|
||||
|
|
@ -144,7 +152,7 @@ export function requestListMenu(country: string, boxid?: string): boolean {
|
|||
});
|
||||
}
|
||||
|
||||
export function requestGenLayout(country: string): boolean {
|
||||
export async function requestGenLayout(country: string): Promise<boolean> {
|
||||
const curr_user = get(auth);
|
||||
|
||||
let user_info: any = {};
|
||||
|
|
@ -160,7 +168,7 @@ export function requestGenLayout(country: string): boolean {
|
|||
|
||||
console.log('[sheetService] Sending gen-layout request for country:', country);
|
||||
|
||||
return sendMessage({
|
||||
return await sendMessage({
|
||||
type: 'command',
|
||||
payload: {
|
||||
user_info,
|
||||
|
|
@ -179,7 +187,7 @@ export function requestGenLayout(country: string): boolean {
|
|||
* Request price data from sheet for specific product codes
|
||||
* NOTE: Can only send once per type (price). Use hasSheetPriceBeenSent to check.
|
||||
*/
|
||||
export function requestSheetPrice(country: string, productCodes: string[]): boolean {
|
||||
export async function requestSheetPrice(country: string, productCodes: string[]): Promise<boolean> {
|
||||
// Check if already sent
|
||||
if (hasSheetPriceBeenSent('price')) {
|
||||
console.warn('[sheetService] Price request already sent, skipping');
|
||||
|
|
@ -210,9 +218,16 @@ export function requestSheetPrice(country: string, productCodes: string[]): bool
|
|||
// Convert to array of objects (backend expects objects, not strings)
|
||||
const content = productCodes.map((code) => ({ product_code: code }));
|
||||
|
||||
console.log('[sheetService] Sending sheet price request for country:', country, 'codes:', productCodes.length, 'request_id:', request_id);
|
||||
console.log(
|
||||
'[sheetService] Sending sheet price request for country:',
|
||||
country,
|
||||
'codes:',
|
||||
productCodes.length,
|
||||
'request_id:',
|
||||
request_id
|
||||
);
|
||||
|
||||
const sent = sendCommandRequest('sheet', {
|
||||
const sent = await sendCommandRequest('sheet', {
|
||||
country: country,
|
||||
content: content,
|
||||
param: 'price',
|
||||
|
|
@ -233,18 +248,23 @@ export function requestSheetPrice(country: string, productCodes: string[]): bool
|
|||
* Update price data in sheet
|
||||
* content: [{ row_index: number, cells: [{ value: string, coord: { row: number, col: number } }] }]
|
||||
*/
|
||||
export function updateSheetPrice(
|
||||
export async function updateSheetPrice(
|
||||
country: string,
|
||||
content: { row_index: number; cells: { value: string; coord: { row: number; col: number } }[] }[]
|
||||
): boolean {
|
||||
): Promise<boolean> {
|
||||
if (!content || content.length === 0) {
|
||||
console.warn('[sheetService] No content to update');
|
||||
return false;
|
||||
}
|
||||
|
||||
console.log('[sheetService] Updating sheet price for country:', country, 'items:', content.length);
|
||||
console.log(
|
||||
'[sheetService] Updating sheet price for country:',
|
||||
country,
|
||||
'items:',
|
||||
content.length
|
||||
);
|
||||
|
||||
return sendCommandRequest('sheet', {
|
||||
return await sendCommandRequest('sheet', {
|
||||
country: country,
|
||||
content: content,
|
||||
param: 'update/price'
|
||||
|
|
@ -255,18 +275,24 @@ export function updateSheetPrice(
|
|||
* Add new price rows to sheet (for product codes that don't exist in price sheet)
|
||||
* content: [{ cells: [product_code, name_en, name_th, ..., price, ...] }]
|
||||
*/
|
||||
export function addSheetPrice(
|
||||
export async function addSheetPrice(
|
||||
country: string,
|
||||
content: { cells: string[] }[]
|
||||
): boolean {
|
||||
): Promise<boolean> {
|
||||
if (!content || content.length === 0) {
|
||||
console.warn('[sheetService] No content to add');
|
||||
return false;
|
||||
}
|
||||
|
||||
console.log('[sheetService] Adding price rows for country:', country, 'items:', content.length, content);
|
||||
console.log(
|
||||
'[sheetService] Adding price rows for country:',
|
||||
country,
|
||||
'items:',
|
||||
content.length,
|
||||
content
|
||||
);
|
||||
|
||||
return sendCommandRequest('sheet', {
|
||||
return await sendCommandRequest('sheet', {
|
||||
country: country,
|
||||
content: content,
|
||||
param: 'add/price'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue