mock events saved to db
This commit is contained in:
@@ -1,17 +1,16 @@
|
|||||||
BEGIN;
|
BEGIN;
|
||||||
|
|
||||||
|
|
||||||
-- raw store events
|
-- raw shop events
|
||||||
|
|
||||||
CREATE TABLE mock.raw_shop_events (
|
CREATE TABLE mock.raw_shop_events (
|
||||||
platform TEXT NOT NULL,
|
platform TEXT NOT NULL,
|
||||||
store_id TEXT NOT NULL,
|
shop_id TEXT NOT NULL,
|
||||||
event_timestamp TIMESTAMPTZ NOT NULL,
|
event_timestamp TIMESTAMPTZ NOT NULL,
|
||||||
event_id TEXT NOT NULL,
|
event_id TEXT NOT NULL,
|
||||||
raw_payload JSONB NOT NULL,
|
raw_payload JSONB NOT NULL,
|
||||||
parsed BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
|
|
||||||
PRIMARY KEY (platform, store_id, event_id, event_timestamp)
|
PRIMARY KEY (platform, shop_id, event_id, event_timestamp)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@@ -19,132 +18,132 @@ CREATE TABLE mock.raw_shop_events (
|
|||||||
|
|
||||||
CREATE TABLE mock.shop_amazon_events (
|
CREATE TABLE mock.shop_amazon_events (
|
||||||
platform TEXT NOT NULL DEFAULT 'amazon' CHECK (platform = 'amazon'),
|
platform TEXT NOT NULL DEFAULT 'amazon' CHECK (platform = 'amazon'),
|
||||||
store_id TEXT NOT NULL,
|
shop_id TEXT NOT NULL,
|
||||||
event_timestamp TIMESTAMPTZ NOT NULL,
|
event_timestamp TIMESTAMPTZ NOT NULL,
|
||||||
event_id TEXT NOT NULL,
|
event_id TEXT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (store_id, event_id, event_timestamp),
|
PRIMARY KEY (shop_id, event_id, event_timestamp),
|
||||||
FOREIGN KEY (platform, store_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
FOREIGN KEY (platform, shop_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE mock.shop_big_cartel_events (
|
CREATE TABLE mock.shop_big_cartel_events (
|
||||||
platform TEXT NOT NULL DEFAULT 'big_cartel' CHECK (platform = 'big_cartel'),
|
platform TEXT NOT NULL DEFAULT 'big_cartel' CHECK (platform = 'big_cartel'),
|
||||||
store_id TEXT NOT NULL,
|
shop_id TEXT NOT NULL,
|
||||||
event_timestamp TIMESTAMPTZ NOT NULL,
|
event_timestamp TIMESTAMPTZ NOT NULL,
|
||||||
event_id TEXT NOT NULL,
|
event_id TEXT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (store_id, event_id, event_timestamp),
|
PRIMARY KEY (shop_id, event_id, event_timestamp),
|
||||||
FOREIGN KEY (platform, store_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
FOREIGN KEY (platform, shop_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE mock.shop_ebay_events (
|
CREATE TABLE mock.shop_ebay_events (
|
||||||
platform TEXT NOT NULL DEFAULT 'ebay' CHECK (platform = 'ebay'),
|
platform TEXT NOT NULL DEFAULT 'ebay' CHECK (platform = 'ebay'),
|
||||||
store_id TEXT NOT NULL,
|
shop_id TEXT NOT NULL,
|
||||||
event_timestamp TIMESTAMPTZ NOT NULL,
|
event_timestamp TIMESTAMPTZ NOT NULL,
|
||||||
event_id TEXT NOT NULL,
|
event_id TEXT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (store_id, event_id, event_timestamp),
|
PRIMARY KEY (shop_id, event_id, event_timestamp),
|
||||||
FOREIGN KEY (platform, store_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
FOREIGN KEY (platform, shop_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE mock.shop_ecwid_events (
|
CREATE TABLE mock.shop_ecwid_events (
|
||||||
platform TEXT NOT NULL DEFAULT 'ecwid' CHECK (platform = 'ecwid'),
|
platform TEXT NOT NULL DEFAULT 'ecwid' CHECK (platform = 'ecwid'),
|
||||||
store_id TEXT NOT NULL,
|
shop_id TEXT NOT NULL,
|
||||||
event_timestamp TIMESTAMPTZ NOT NULL,
|
event_timestamp TIMESTAMPTZ NOT NULL,
|
||||||
event_id TEXT NOT NULL,
|
event_id TEXT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (store_id, event_id, event_timestamp),
|
PRIMARY KEY (shop_id, event_id, event_timestamp),
|
||||||
FOREIGN KEY (platform, store_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
FOREIGN KEY (platform, shop_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE mock.shop_etsy_events (
|
CREATE TABLE mock.shop_etsy_events (
|
||||||
platform TEXT NOT NULL DEFAULT 'etsy' CHECK (platform = 'etsy'),
|
platform TEXT NOT NULL DEFAULT 'etsy' CHECK (platform = 'etsy'),
|
||||||
store_id TEXT NOT NULL,
|
shop_id TEXT NOT NULL,
|
||||||
event_timestamp TIMESTAMPTZ NOT NULL,
|
event_timestamp TIMESTAMPTZ NOT NULL,
|
||||||
event_id TEXT NOT NULL,
|
event_id TEXT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (store_id, event_id, event_timestamp),
|
PRIMARY KEY (shop_id, event_id, event_timestamp),
|
||||||
FOREIGN KEY (platform, store_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
FOREIGN KEY (platform, shop_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE mock.shop_shopify_events (
|
CREATE TABLE mock.shop_shopify_events (
|
||||||
platform TEXT NOT NULL DEFAULT 'shopify' CHECK (platform = 'shopify'),
|
platform TEXT NOT NULL DEFAULT 'shopify' CHECK (platform = 'shopify'),
|
||||||
store_id TEXT NOT NULL,
|
shop_id TEXT NOT NULL,
|
||||||
event_timestamp TIMESTAMPTZ NOT NULL,
|
event_timestamp TIMESTAMPTZ NOT NULL,
|
||||||
event_id TEXT NOT NULL,
|
event_id TEXT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (store_id, event_id, event_timestamp),
|
PRIMARY KEY (shop_id, event_id, event_timestamp),
|
||||||
FOREIGN KEY (platform, store_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
FOREIGN KEY (platform, shop_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE mock.shop_square_online_events (
|
CREATE TABLE mock.shop_square_online_events (
|
||||||
platform TEXT NOT NULL DEFAULT 'square_online' CHECK (platform = 'square_online'),
|
platform TEXT NOT NULL DEFAULT 'square_online' CHECK (platform = 'square_online'),
|
||||||
store_id TEXT NOT NULL,
|
shop_id TEXT NOT NULL,
|
||||||
event_timestamp TIMESTAMPTZ NOT NULL,
|
event_timestamp TIMESTAMPTZ NOT NULL,
|
||||||
event_id TEXT NOT NULL,
|
event_id TEXT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (store_id, event_id, event_timestamp),
|
PRIMARY KEY (shop_id, event_id, event_timestamp),
|
||||||
FOREIGN KEY (platform, store_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
FOREIGN KEY (platform, shop_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE mock.shop_squarespace_events (
|
CREATE TABLE mock.shop_squarespace_events (
|
||||||
platform TEXT NOT NULL DEFAULT 'squarespace' CHECK (platform = 'squarespace'),
|
platform TEXT NOT NULL DEFAULT 'squarespace' CHECK (platform = 'squarespace'),
|
||||||
store_id TEXT NOT NULL,
|
shop_id TEXT NOT NULL,
|
||||||
event_timestamp TIMESTAMPTZ NOT NULL,
|
event_timestamp TIMESTAMPTZ NOT NULL,
|
||||||
event_id TEXT NOT NULL,
|
event_id TEXT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (store_id, event_id, event_timestamp),
|
PRIMARY KEY (shop_id, event_id, event_timestamp),
|
||||||
FOREIGN KEY (platform, store_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
FOREIGN KEY (platform, shop_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE mock.shop_tiktok_events (
|
CREATE TABLE mock.shop_tiktok_events (
|
||||||
platform TEXT NOT NULL DEFAULT 'tiktok' CHECK (platform = 'tiktok'),
|
platform TEXT NOT NULL DEFAULT 'tiktok' CHECK (platform = 'tiktok'),
|
||||||
store_id TEXT NOT NULL,
|
shop_id TEXT NOT NULL,
|
||||||
event_timestamp TIMESTAMPTZ NOT NULL,
|
event_timestamp TIMESTAMPTZ NOT NULL,
|
||||||
event_id TEXT NOT NULL,
|
event_id TEXT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (store_id, event_id, event_timestamp),
|
PRIMARY KEY (shop_id, event_id, event_timestamp),
|
||||||
FOREIGN KEY (platform, store_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
FOREIGN KEY (platform, shop_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE mock.shop_walmart_marketplace_events (
|
CREATE TABLE mock.shop_walmart_marketplace_events (
|
||||||
platform TEXT NOT NULL DEFAULT 'walmart_marketplace' CHECK (platform = 'walmart_marketplace'),
|
platform TEXT NOT NULL DEFAULT 'walmart_marketplace' CHECK (platform = 'walmart_marketplace'),
|
||||||
store_id TEXT NOT NULL,
|
shop_id TEXT NOT NULL,
|
||||||
event_timestamp TIMESTAMPTZ NOT NULL,
|
event_timestamp TIMESTAMPTZ NOT NULL,
|
||||||
event_id TEXT NOT NULL,
|
event_id TEXT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (store_id, event_id, event_timestamp),
|
PRIMARY KEY (shop_id, event_id, event_timestamp),
|
||||||
FOREIGN KEY (platform, store_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
FOREIGN KEY (platform, shop_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE mock.shop_wix_events (
|
CREATE TABLE mock.shop_wix_events (
|
||||||
platform TEXT NOT NULL DEFAULT 'wix' CHECK (platform = 'wix'),
|
platform TEXT NOT NULL DEFAULT 'wix' CHECK (platform = 'wix'),
|
||||||
store_id TEXT NOT NULL,
|
shop_id TEXT NOT NULL,
|
||||||
event_timestamp TIMESTAMPTZ NOT NULL,
|
event_timestamp TIMESTAMPTZ NOT NULL,
|
||||||
event_id TEXT NOT NULL,
|
event_id TEXT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (store_id, event_id, event_timestamp),
|
PRIMARY KEY (shop_id, event_id, event_timestamp),
|
||||||
FOREIGN KEY (platform, store_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
FOREIGN KEY (platform, shop_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE mock.shop_woo_commerce_events (
|
CREATE TABLE mock.shop_woo_commerce_events (
|
||||||
platform TEXT NOT NULL DEFAULT 'woo_commerce' CHECK (platform = 'woo_commerce'),
|
platform TEXT NOT NULL DEFAULT 'woo_commerce' CHECK (platform = 'woo_commerce'),
|
||||||
store_id TEXT NOT NULL,
|
shop_id TEXT NOT NULL,
|
||||||
event_timestamp TIMESTAMPTZ NOT NULL,
|
event_timestamp TIMESTAMPTZ NOT NULL,
|
||||||
event_id TEXT NOT NULL,
|
event_id TEXT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (store_id, event_id, event_timestamp),
|
PRIMARY KEY (shop_id, event_id, event_timestamp),
|
||||||
FOREIGN KEY (platform, store_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
FOREIGN KEY (platform, shop_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE mock.shop_zoho_events (
|
CREATE TABLE mock.shop_zoho_events (
|
||||||
platform TEXT NOT NULL DEFAULT 'zoho' CHECK (platform = 'zoho'),
|
platform TEXT NOT NULL DEFAULT 'zoho' CHECK (platform = 'zoho'),
|
||||||
store_id TEXT NOT NULL,
|
shop_id TEXT NOT NULL,
|
||||||
event_timestamp TIMESTAMPTZ NOT NULL,
|
event_timestamp TIMESTAMPTZ NOT NULL,
|
||||||
event_id TEXT NOT NULL,
|
event_id TEXT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (store_id, event_id, event_timestamp),
|
PRIMARY KEY (shop_id, event_id, event_timestamp),
|
||||||
FOREIGN KEY (platform, store_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
FOREIGN KEY (platform, shop_id, event_id, event_timestamp) REFERENCES mock.raw_shop_events
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@@ -154,13 +153,13 @@ CREATE OR REPLACE FUNCTION mock.process_raw_amazon_event() RETURNS TRIGGER AS $p
|
|||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO mock.shop_amazon_events (
|
INSERT INTO mock.shop_amazon_events (
|
||||||
platform,
|
platform,
|
||||||
store_id,
|
shop_id,
|
||||||
event_timestamp,
|
event_timestamp,
|
||||||
event_id
|
event_id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
NEW.platform,
|
NEW.platform,
|
||||||
NEW.store_id,
|
NEW.shop_id,
|
||||||
NEW.event_timestamp,
|
NEW.event_timestamp,
|
||||||
NEW.event_id;
|
NEW.event_id;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@@ -178,13 +177,13 @@ CREATE OR REPLACE FUNCTION mock.process_raw_big_cartel_event() RETURNS TRIGGER A
|
|||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO mock.shop_big_cartel_events (
|
INSERT INTO mock.shop_big_cartel_events (
|
||||||
platform,
|
platform,
|
||||||
store_id,
|
shop_id,
|
||||||
event_timestamp,
|
event_timestamp,
|
||||||
event_id
|
event_id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
NEW.platform,
|
NEW.platform,
|
||||||
NEW.store_id,
|
NEW.shop_id,
|
||||||
NEW.event_timestamp,
|
NEW.event_timestamp,
|
||||||
NEW.event_id;
|
NEW.event_id;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@@ -202,13 +201,13 @@ CREATE OR REPLACE FUNCTION mock.process_raw_ebay_event() RETURNS TRIGGER AS $pro
|
|||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO mock.shop_ebay_events (
|
INSERT INTO mock.shop_ebay_events (
|
||||||
platform,
|
platform,
|
||||||
store_id,
|
shop_id,
|
||||||
event_timestamp,
|
event_timestamp,
|
||||||
event_id
|
event_id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
NEW.platform,
|
NEW.platform,
|
||||||
NEW.store_id,
|
NEW.shop_id,
|
||||||
NEW.event_timestamp,
|
NEW.event_timestamp,
|
||||||
NEW.event_id;
|
NEW.event_id;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@@ -226,13 +225,13 @@ CREATE OR REPLACE FUNCTION mock.process_raw_ecwid_event() RETURNS TRIGGER AS $pr
|
|||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO mock.shop_ecwid_events (
|
INSERT INTO mock.shop_ecwid_events (
|
||||||
platform,
|
platform,
|
||||||
store_id,
|
shop_id,
|
||||||
event_timestamp,
|
event_timestamp,
|
||||||
event_id
|
event_id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
NEW.platform,
|
NEW.platform,
|
||||||
NEW.store_id,
|
NEW.shop_id,
|
||||||
NEW.event_timestamp,
|
NEW.event_timestamp,
|
||||||
NEW.event_id;
|
NEW.event_id;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@@ -250,13 +249,13 @@ CREATE OR REPLACE FUNCTION mock.process_raw_etsy_event() RETURNS TRIGGER AS $pro
|
|||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO mock.shop_etsy_events (
|
INSERT INTO mock.shop_etsy_events (
|
||||||
platform,
|
platform,
|
||||||
store_id,
|
shop_id,
|
||||||
event_timestamp,
|
event_timestamp,
|
||||||
event_id
|
event_id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
NEW.platform,
|
NEW.platform,
|
||||||
NEW.store_id,
|
NEW.shop_id,
|
||||||
NEW.event_timestamp,
|
NEW.event_timestamp,
|
||||||
NEW.event_id;
|
NEW.event_id;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@@ -274,13 +273,13 @@ CREATE OR REPLACE FUNCTION mock.process_raw_shopify_event() RETURNS TRIGGER AS $
|
|||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO mock.shop_shopify_events (
|
INSERT INTO mock.shop_shopify_events (
|
||||||
platform,
|
platform,
|
||||||
store_id,
|
shop_id,
|
||||||
event_timestamp,
|
event_timestamp,
|
||||||
event_id
|
event_id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
NEW.platform,
|
NEW.platform,
|
||||||
NEW.store_id,
|
NEW.shop_id,
|
||||||
NEW.event_timestamp,
|
NEW.event_timestamp,
|
||||||
NEW.event_id;
|
NEW.event_id;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@@ -298,13 +297,13 @@ CREATE OR REPLACE FUNCTION mock.process_raw_square_online_event() RETURNS TRIGGE
|
|||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO mock.shop_square_online_events (
|
INSERT INTO mock.shop_square_online_events (
|
||||||
platform,
|
platform,
|
||||||
store_id,
|
shop_id,
|
||||||
event_timestamp,
|
event_timestamp,
|
||||||
event_id
|
event_id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
NEW.platform,
|
NEW.platform,
|
||||||
NEW.store_id,
|
NEW.shop_id,
|
||||||
NEW.event_timestamp,
|
NEW.event_timestamp,
|
||||||
NEW.event_id;
|
NEW.event_id;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@@ -322,13 +321,13 @@ CREATE OR REPLACE FUNCTION mock.process_raw_squarespace_event() RETURNS TRIGGER
|
|||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO mock.shop_squarespace_events (
|
INSERT INTO mock.shop_squarespace_events (
|
||||||
platform,
|
platform,
|
||||||
store_id,
|
shop_id,
|
||||||
event_timestamp,
|
event_timestamp,
|
||||||
event_id
|
event_id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
NEW.platform,
|
NEW.platform,
|
||||||
NEW.store_id,
|
NEW.shop_id,
|
||||||
NEW.event_timestamp,
|
NEW.event_timestamp,
|
||||||
NEW.event_id;
|
NEW.event_id;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@@ -346,13 +345,13 @@ CREATE OR REPLACE FUNCTION mock.process_raw_tiktok_event() RETURNS TRIGGER AS $p
|
|||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO mock.shop_tiktok_events (
|
INSERT INTO mock.shop_tiktok_events (
|
||||||
platform,
|
platform,
|
||||||
store_id,
|
shop_id,
|
||||||
event_timestamp,
|
event_timestamp,
|
||||||
event_id
|
event_id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
NEW.platform,
|
NEW.platform,
|
||||||
NEW.store_id,
|
NEW.shop_id,
|
||||||
NEW.event_timestamp,
|
NEW.event_timestamp,
|
||||||
NEW.event_id;
|
NEW.event_id;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@@ -370,13 +369,13 @@ CREATE OR REPLACE FUNCTION mock.process_raw_walmart_marketplace_event() RETURNS
|
|||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO mock.shop_walmart_marketplace_events (
|
INSERT INTO mock.shop_walmart_marketplace_events (
|
||||||
platform,
|
platform,
|
||||||
store_id,
|
shop_id,
|
||||||
event_timestamp,
|
event_timestamp,
|
||||||
event_id
|
event_id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
NEW.platform,
|
NEW.platform,
|
||||||
NEW.store_id,
|
NEW.shop_id,
|
||||||
NEW.event_timestamp,
|
NEW.event_timestamp,
|
||||||
NEW.event_id;
|
NEW.event_id;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@@ -394,13 +393,13 @@ CREATE OR REPLACE FUNCTION mock.process_raw_wix_event() RETURNS TRIGGER AS $proc
|
|||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO mock.shop_wix_events (
|
INSERT INTO mock.shop_wix_events (
|
||||||
platform,
|
platform,
|
||||||
store_id,
|
shop_id,
|
||||||
event_timestamp,
|
event_timestamp,
|
||||||
event_id
|
event_id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
NEW.platform,
|
NEW.platform,
|
||||||
NEW.store_id,
|
NEW.shop_id,
|
||||||
NEW.event_timestamp,
|
NEW.event_timestamp,
|
||||||
NEW.event_id;
|
NEW.event_id;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@@ -418,13 +417,13 @@ CREATE OR REPLACE FUNCTION mock.process_raw_woo_commerce_event() RETURNS TRIGGER
|
|||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO mock.shop_woo_commerce_events (
|
INSERT INTO mock.shop_woo_commerce_events (
|
||||||
platform,
|
platform,
|
||||||
store_id,
|
shop_id,
|
||||||
event_timestamp,
|
event_timestamp,
|
||||||
event_id
|
event_id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
NEW.platform,
|
NEW.platform,
|
||||||
NEW.store_id,
|
NEW.shop_id,
|
||||||
NEW.event_timestamp,
|
NEW.event_timestamp,
|
||||||
NEW.event_id;
|
NEW.event_id;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@@ -442,13 +441,13 @@ CREATE OR REPLACE FUNCTION mock.process_raw_zoho_event() RETURNS TRIGGER AS $pro
|
|||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO mock.shop_zoho_events (
|
INSERT INTO mock.shop_zoho_events (
|
||||||
platform,
|
platform,
|
||||||
store_id,
|
shop_id,
|
||||||
event_timestamp,
|
event_timestamp,
|
||||||
event_id
|
event_id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
NEW.platform,
|
NEW.platform,
|
||||||
NEW.store_id,
|
NEW.shop_id,
|
||||||
NEW.event_timestamp,
|
NEW.event_timestamp,
|
||||||
NEW.event_id;
|
NEW.event_id;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
|
||||||
|
DROP TABLE mock.sale_form_shop_selection;
|
||||||
|
DROP TABLE mock.refund_form_shop_selection;
|
||||||
|
DROP TABLE mock.count_form_shop_selection;
|
||||||
|
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE mock.sale_form_shop_selection (
|
||||||
|
account_id INTEGER PRIMARY KEY,
|
||||||
|
platform PLATFORM NOT NULL,
|
||||||
|
shop_id TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE mock.refund_form_shop_selection (
|
||||||
|
account_id INTEGER PRIMARY KEY,
|
||||||
|
platform PLATFORM NOT NULL,
|
||||||
|
shop_id TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE mock.count_form_shop_selection (
|
||||||
|
account_id INTEGER PRIMARY KEY,
|
||||||
|
platform PLATFORM NOT NULL,
|
||||||
|
shop_id TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
@@ -5,11 +5,13 @@ package accounts
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/jackc/pgx/v5/pgtype"
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
"github.com/jackc/pgx/v5/pgxpool"
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
@@ -1461,6 +1463,290 @@ func (db *Store) DeleteListingInListingInMockSyncGroupBeingEdited(ctx context.Co
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if err := s.accts.SetShopInMockSaleForm(c, acctID, platform, shopID); err != nil {
|
||||||
|
|
||||||
|
func (db *Store) SetShopInMockSaleForm(ctx context.Context, acctID int64, platform Platform, shopID string) error {
|
||||||
|
_, err := db.db.Exec(
|
||||||
|
ctx,
|
||||||
|
`
|
||||||
|
INSERT INTO
|
||||||
|
mock.sale_form_shop_selection (
|
||||||
|
account_id,
|
||||||
|
platform,
|
||||||
|
shop_id
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
@account_id,
|
||||||
|
@platform,
|
||||||
|
@shop_id
|
||||||
|
)
|
||||||
|
ON CONFLICT (account_id) DO UPDATE
|
||||||
|
SET platform = EXCLUDED.platform,
|
||||||
|
shop_id = EXCLUDED.shop_id
|
||||||
|
`,
|
||||||
|
pgx.NamedArgs{
|
||||||
|
"account_id": acctID,
|
||||||
|
"platform": platform,
|
||||||
|
"shop_id": shopID,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to perform query: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *Store) SetShopInMockRefundForm(ctx context.Context, acctID int64, platform Platform, shopID string) error {
|
||||||
|
_, err := db.db.Exec(
|
||||||
|
ctx,
|
||||||
|
`
|
||||||
|
INSERT INTO
|
||||||
|
mock.refund_form_shop_selection (
|
||||||
|
account_id,
|
||||||
|
platform,
|
||||||
|
shop_id
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
@account_id,
|
||||||
|
@platform,
|
||||||
|
@shop_id
|
||||||
|
)
|
||||||
|
ON CONFLICT (account_id) DO UPDATE
|
||||||
|
SET platform = EXCLUDED.platform,
|
||||||
|
shop_id = EXCLUDED.shop_id
|
||||||
|
`,
|
||||||
|
pgx.NamedArgs{
|
||||||
|
"account_id": acctID,
|
||||||
|
"platform": platform,
|
||||||
|
"shop_id": shopID,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to perform query: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *Store) SetShopInMockCountForm(ctx context.Context, acctID int64, platform Platform, shopID string) error {
|
||||||
|
_, err := db.db.Exec(
|
||||||
|
ctx,
|
||||||
|
`
|
||||||
|
INSERT INTO
|
||||||
|
mock.count_form_shop_selection (
|
||||||
|
account_id,
|
||||||
|
platform,
|
||||||
|
shop_id
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
@account_id,
|
||||||
|
@platform,
|
||||||
|
@shop_id
|
||||||
|
)
|
||||||
|
ON CONFLICT (account_id) DO UPDATE
|
||||||
|
SET platform = EXCLUDED.platform,
|
||||||
|
shop_id = EXCLUDED.shop_id
|
||||||
|
`,
|
||||||
|
pgx.NamedArgs{
|
||||||
|
"account_id": acctID,
|
||||||
|
"platform": platform,
|
||||||
|
"shop_id": shopID,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to perform query: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type MockEventFormValues struct {
|
||||||
|
SaleShopID string
|
||||||
|
SalePlatform Platform
|
||||||
|
RefundShopID string
|
||||||
|
RefundPlatform Platform
|
||||||
|
CountShopID string
|
||||||
|
CountPlatform Platform
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *Store) GetMockEventFormValues(ctx context.Context, acctID int64) (*MockEventFormValues, error) {
|
||||||
|
rows, err := db.db.Query(
|
||||||
|
ctx,
|
||||||
|
`
|
||||||
|
SELECT
|
||||||
|
sf.platform AS sale_platform,
|
||||||
|
sf.shop_id AS sale_shop_id,
|
||||||
|
rf.platform AS refund_platform,
|
||||||
|
rf.shop_id AS refund_shop_id,
|
||||||
|
cf.platform AS count_platform,
|
||||||
|
cf.shop_id AS count_shop_id
|
||||||
|
FROM
|
||||||
|
mock.sale_form_shop_selection AS sf
|
||||||
|
FULL OUTER JOIN
|
||||||
|
mock.refund_form_shop_selection AS rf
|
||||||
|
USING
|
||||||
|
(account_id)
|
||||||
|
FULL OUTER JOIN
|
||||||
|
mock.count_form_shop_selection AS cf
|
||||||
|
USING
|
||||||
|
(account_id)
|
||||||
|
WHERE
|
||||||
|
sf.account_id = @account_id
|
||||||
|
`,
|
||||||
|
pgx.NamedArgs{
|
||||||
|
"account_id": acctID,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to perform query: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
v, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByNameLax[struct {
|
||||||
|
Sale_shop_id pgtype.Text
|
||||||
|
Sale_platform *Platform
|
||||||
|
Refund_shop_id pgtype.Text
|
||||||
|
Refund_platform *Platform
|
||||||
|
Count_shop_id pgtype.Text
|
||||||
|
Count_platform *Platform
|
||||||
|
}])
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, pgx.ErrNoRows) {
|
||||||
|
return &MockEventFormValues{}, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("failed to scan rows: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &MockEventFormValues{
|
||||||
|
SaleShopID: v.Sale_shop_id.String,
|
||||||
|
SalePlatform: deref(v.Sale_platform),
|
||||||
|
RefundShopID: v.Refund_shop_id.String,
|
||||||
|
RefundPlatform: deref(v.Refund_platform),
|
||||||
|
CountShopID: v.Count_shop_id.String,
|
||||||
|
CountPlatform: deref(v.Count_platform),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *Store) SaveNewMockSale(ctx context.Context, acctID int64, platform Platform, shopID, listingID string, count int) (uuid.UUID, error) {
|
||||||
|
eventID := uuid.New()
|
||||||
|
|
||||||
|
_, err := db.db.Exec(
|
||||||
|
ctx,
|
||||||
|
`
|
||||||
|
INSERT INTO
|
||||||
|
mock.raw_shop_events (
|
||||||
|
platform,
|
||||||
|
shop_id,
|
||||||
|
event_timestamp,
|
||||||
|
event_id,
|
||||||
|
raw_payload
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
@platform,
|
||||||
|
@shop_id,
|
||||||
|
NOW(),
|
||||||
|
@event_id,
|
||||||
|
@raw_payload
|
||||||
|
)
|
||||||
|
`,
|
||||||
|
pgx.NamedArgs{
|
||||||
|
"platform": platform,
|
||||||
|
"shop_id": shopID,
|
||||||
|
"event_id": eventID,
|
||||||
|
"raw_payload": json.RawMessage(fmt.Sprintf(`{
|
||||||
|
"type": "sale",
|
||||||
|
"listingID": %q,
|
||||||
|
"count": %d
|
||||||
|
}`, listingID, count)),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return uuid.Nil, fmt.Errorf("failed to perform query: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return eventID, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *Store) SaveNewMockRefund(ctx context.Context, acctID int64, platform Platform, shopID, listingID string, count int) (uuid.UUID, error) {
|
||||||
|
eventID := uuid.New()
|
||||||
|
|
||||||
|
_, err := db.db.Exec(
|
||||||
|
ctx,
|
||||||
|
`
|
||||||
|
INSERT INTO
|
||||||
|
mock.raw_shop_events (
|
||||||
|
platform,
|
||||||
|
shop_id,
|
||||||
|
event_timestamp,
|
||||||
|
event_id,
|
||||||
|
raw_payload
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
@platform,
|
||||||
|
@shop_id,
|
||||||
|
NOW(),
|
||||||
|
@event_id,
|
||||||
|
@raw_payload
|
||||||
|
)
|
||||||
|
`,
|
||||||
|
pgx.NamedArgs{
|
||||||
|
"platform": platform,
|
||||||
|
"shop_id": shopID,
|
||||||
|
"event_id": eventID,
|
||||||
|
"raw_payload": json.RawMessage(fmt.Sprintf(`{
|
||||||
|
"type": "refund",
|
||||||
|
"listingID": %q,
|
||||||
|
"count": %d
|
||||||
|
}`, listingID, count)),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return uuid.Nil, fmt.Errorf("failed to perform query: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return eventID, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *Store) SaveNewMockInventoryReset(ctx context.Context, acctID int64, platform Platform, shopID, listingID string, count int) (uuid.UUID, error) {
|
||||||
|
eventID := uuid.New()
|
||||||
|
|
||||||
|
_, err := db.db.Exec(
|
||||||
|
ctx,
|
||||||
|
`
|
||||||
|
INSERT INTO
|
||||||
|
mock.raw_shop_events (
|
||||||
|
platform,
|
||||||
|
shop_id,
|
||||||
|
event_timestamp,
|
||||||
|
event_id,
|
||||||
|
raw_payload
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
@platform,
|
||||||
|
@shop_id,
|
||||||
|
NOW(),
|
||||||
|
@event_id,
|
||||||
|
@raw_payload
|
||||||
|
)
|
||||||
|
`,
|
||||||
|
pgx.NamedArgs{
|
||||||
|
"platform": platform,
|
||||||
|
"shop_id": shopID,
|
||||||
|
"event_id": eventID,
|
||||||
|
"raw_payload": json.RawMessage(fmt.Sprintf(`{
|
||||||
|
"type": "inventory-reset",
|
||||||
|
"listingID": %q,
|
||||||
|
"count": %d
|
||||||
|
}`, listingID, count)),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return uuid.Nil, fmt.Errorf("failed to perform query: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return eventID, nil
|
||||||
|
}
|
||||||
|
|
||||||
// additional context
|
// additional context
|
||||||
|
|
||||||
func (db *Store) GetAccountPointerByUserID(ctx context.Context, userID string) (*Account, error) {
|
func (db *Store) GetAccountPointerByUserID(ctx context.Context, userID string) (*Account, error) {
|
||||||
@@ -1481,3 +1767,11 @@ func (db *Store) beginReadonlyTxn(ctx context.Context, cb func(pgx.Tx) error) er
|
|||||||
func (db *Store) beginTxn(ctx context.Context, cb func(pgx.Tx) error) error {
|
func (db *Store) beginTxn(ctx context.Context, cb func(pgx.Tx) error) error {
|
||||||
return pgx.BeginFunc(ctx, db.db, cb)
|
return pgx.BeginFunc(ctx, db.db, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deref[T any](ptr *T) T {
|
||||||
|
if ptr != nil {
|
||||||
|
return *ptr
|
||||||
|
}
|
||||||
|
var zero T
|
||||||
|
return zero
|
||||||
|
}
|
||||||
|
|||||||
@@ -105,6 +105,22 @@ func (v_ctx *StoreWithContext) DeleteListingInListingInMockSyncGroupBeingEdited(
|
|||||||
return v_ctx.Store.DeleteListingInListingInMockSyncGroupBeingEdited(v_ctx.ctx, acctID, orderIndex)
|
return v_ctx.Store.DeleteListingInListingInMockSyncGroupBeingEdited(v_ctx.ctx, acctID, orderIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v_ctx *StoreWithContext) SetShopInMockSaleForm(acctID int64, platform Platform, shopID string) error {
|
||||||
|
return v_ctx.Store.SetShopInMockSaleForm(v_ctx.ctx, acctID, platform, shopID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v_ctx *StoreWithContext) SetShopInMockRefundForm(acctID int64, platform Platform, shopID string) error {
|
||||||
|
return v_ctx.Store.SetShopInMockRefundForm(v_ctx.ctx, acctID, platform, shopID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v_ctx *StoreWithContext) SetShopInMockCountForm(acctID int64, platform Platform, shopID string) error {
|
||||||
|
return v_ctx.Store.SetShopInMockCountForm(v_ctx.ctx, acctID, platform, shopID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v_ctx *StoreWithContext) GetMockEventFormValues(acctID int64) (*MockEventFormValues, error) {
|
||||||
|
return v_ctx.Store.GetMockEventFormValues(v_ctx.ctx, acctID)
|
||||||
|
}
|
||||||
|
|
||||||
func (v_ctx *StoreWithContext) GetAccountPointerByUserID(userID string) (*Account, error) {
|
func (v_ctx *StoreWithContext) GetAccountPointerByUserID(userID string) (*Account, error) {
|
||||||
return v_ctx.Store.GetAccountPointerByUserID(v_ctx.ctx, userID)
|
return v_ctx.Store.GetAccountPointerByUserID(v_ctx.ctx, userID)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1235,11 +1235,3 @@ func (db *Store) listMockSyncGroupListings(ctx context.Context, tx pgx.Tx, acctI
|
|||||||
|
|
||||||
return listings, nil
|
return listings, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func deref[T any](ptr *T) T {
|
|
||||||
if ptr == nil {
|
|
||||||
var zero T
|
|
||||||
return zero
|
|
||||||
}
|
|
||||||
return *ptr
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -79,10 +79,13 @@ func Routes(
|
|||||||
mockSyncGroupBeingEdited.PUT("/listings/:orderIndex/listing", response.Handler(as.setListingInListingInMockSyncGroupBeingEdited))
|
mockSyncGroupBeingEdited.PUT("/listings/:orderIndex/listing", response.Handler(as.setListingInListingInMockSyncGroupBeingEdited))
|
||||||
mockSyncGroupBeingEdited.DELETE("/listings/:orderIndex", response.Handler(as.deleteListingInListingInMockSyncGroupBeingEdited))
|
mockSyncGroupBeingEdited.DELETE("/listings/:orderIndex", response.Handler(as.deleteListingInListingInMockSyncGroupBeingEdited))
|
||||||
|
|
||||||
simulations := r.Group("/:acctID/simulations")
|
simulations := r.Group("/:acctID/simulations", pub.Publish("/:acctID/simulations"))
|
||||||
simulations.POST("/sale", response.Handler(as.postNewSale))
|
simulations.PUT("/sale/form/shop", response.Handler(as.setShopInMockSaleForm))
|
||||||
simulations.POST("/refund", response.Handler(as.postNewRefund))
|
simulations.POST("/sale", response.Handler(as.postNewMockSale))
|
||||||
simulations.PUT("/shops/:shopID/listings/:listingID/count", response.Handler(as.setListingCount))
|
simulations.PUT("/refund/form/shop", response.Handler(as.setShopInMockRefundForm))
|
||||||
|
simulations.POST("/refund", response.Handler(as.postNewMockRefund))
|
||||||
|
simulations.PUT("/count/form/shop", response.Handler(as.setShopInMockCountForm))
|
||||||
|
simulations.PUT("/shops/:shopID/listings/:listingID/count", response.Handler(as.setMockListingCount))
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST /
|
// POST /
|
||||||
@@ -741,80 +744,146 @@ func (s *accountSubrouter) deleteListingInListingInMockSyncGroupBeingEdited(c *g
|
|||||||
return response.StatusOK(), nil
|
return response.StatusOK(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST /:acctID/simulations/sale
|
// PUT /:acctID/simulations/sale/form/shop
|
||||||
func (s *accountSubrouter) postNewSale(c *gin.Context) (response.Response, error) {
|
func (s *accountSubrouter) setShopInMockSaleForm(c *gin.Context) (response.Response, error) {
|
||||||
acctID := auth.GetIdentity(c).Account.AccountID
|
acctID := auth.GetIdentity(c).Account.AccountID
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
platform accounts.Platform
|
||||||
|
shopID string
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := param.Form("platform", param.Platform(&platform)).
|
||||||
|
Form("shop-id", param.Text(&shopID)).
|
||||||
|
Unmarshal(c); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := s.accts.SetShopInMockSaleForm(c, acctID, platform, shopID); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to set shop in mock sale form: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.StatusOK(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST /:acctID/simulations/sale
|
||||||
|
func (s *accountSubrouter) postNewMockSale(c *gin.Context) (response.Response, error) {
|
||||||
|
acctID := auth.GetIdentity(c).Account.AccountID
|
||||||
|
|
||||||
|
var (
|
||||||
|
platform accounts.Platform
|
||||||
shopID string
|
shopID string
|
||||||
listingID string
|
listingID string
|
||||||
count int
|
count int
|
||||||
)
|
)
|
||||||
|
|
||||||
if err := param.Form("shop-id", param.Text(&shopID)).
|
if err := param.Form("platform", param.Platform(&platform)).
|
||||||
|
Form("shop-id", param.Text(&shopID)).
|
||||||
Form("listing-id", param.Text(&listingID)).
|
Form("listing-id", param.Text(&listingID)).
|
||||||
Form("count", param.Int(&count)).
|
Form("count", param.Int(&count)).
|
||||||
Unmarshal(c); err != nil {
|
Unmarshal(c); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
s.log.Debugf("sale posted:")
|
if _, err := s.accts.SaveNewMockSale(c, acctID, platform, shopID, listingID, count); err != nil {
|
||||||
s.log.Debugf(" account: %d", acctID)
|
return nil, fmt.Errorf("failed to save new mock sale: %w", err)
|
||||||
s.log.Debugf(" shop: %s", shopID)
|
}
|
||||||
s.log.Debugf(" listing: %s", listingID)
|
|
||||||
s.log.Debugf(" count: %d", count)
|
|
||||||
|
|
||||||
return response.StatusCreated(), nil
|
return response.StatusCreated(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PUT /:acctID/simulations/refund/form/shop
|
||||||
|
func (s *accountSubrouter) setShopInMockRefundForm(c *gin.Context) (response.Response, error) {
|
||||||
|
acctID := auth.GetIdentity(c).Account.AccountID
|
||||||
|
|
||||||
|
var (
|
||||||
|
platform accounts.Platform
|
||||||
|
shopID string
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := param.Form("platform", param.Platform(&platform)).
|
||||||
|
Form("shop-id", param.Text(&shopID)).
|
||||||
|
Unmarshal(c); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := s.accts.SetShopInMockRefundForm(c, acctID, platform, shopID); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to set shop in mock refund form: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.StatusOK(), nil
|
||||||
|
}
|
||||||
|
|
||||||
// POST /:acctID/simulations/refund
|
// POST /:acctID/simulations/refund
|
||||||
func (s *accountSubrouter) postNewRefund(c *gin.Context) (response.Response, error) {
|
func (s *accountSubrouter) postNewMockRefund(c *gin.Context) (response.Response, error) {
|
||||||
acctID := auth.GetIdentity(c).Account.AccountID
|
acctID := auth.GetIdentity(c).Account.AccountID
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
platform accounts.Platform
|
||||||
shopID string
|
shopID string
|
||||||
listingID string
|
listingID string
|
||||||
count int
|
count int
|
||||||
)
|
)
|
||||||
|
|
||||||
if err := param.Form("shop-id", param.Text(&shopID)).
|
if err := param.Form("platform", param.Platform(&platform)).
|
||||||
|
Form("shop-id", param.Text(&shopID)).
|
||||||
Form("listing-id", param.Text(&listingID)).
|
Form("listing-id", param.Text(&listingID)).
|
||||||
Form("count", param.Int(&count)).
|
Form("count", param.Int(&count)).
|
||||||
Unmarshal(c); err != nil {
|
Unmarshal(c); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
s.log.Debugf("refund posted:")
|
if _, err := s.accts.SaveNewMockRefund(c, acctID, platform, shopID, listingID, count); err != nil {
|
||||||
s.log.Debugf(" account: %d", acctID)
|
return nil, fmt.Errorf("failed to save new mock refund: %w", err)
|
||||||
s.log.Debugf(" shop: %s", shopID)
|
}
|
||||||
s.log.Debugf(" listing: %s", listingID)
|
|
||||||
s.log.Debugf(" count: %d", count)
|
|
||||||
|
|
||||||
return response.StatusCreated(), nil
|
return response.StatusCreated(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT /:acctID/simulations/shops/:shopID/listings/:listingID/count
|
// PUT /:acctID/simulations/count/form/shop
|
||||||
func (s *accountSubrouter) setListingCount(c *gin.Context) (response.Response, error) {
|
func (s *accountSubrouter) setShopInMockCountForm(c *gin.Context) (response.Response, error) {
|
||||||
acctID := auth.GetIdentity(c).Account.AccountID
|
acctID := auth.GetIdentity(c).Account.AccountID
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
platform accounts.Platform
|
||||||
|
shopID string
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := param.Form("platform", param.Platform(&platform)).
|
||||||
|
Form("shop-id", param.Text(&shopID)).
|
||||||
|
Unmarshal(c); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := s.accts.SetShopInMockCountForm(c, acctID, platform, shopID); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to set shop in mock count form: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.StatusOK(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// PUT /:acctID/simulations/shops/:shopID/listings/:listingID/count
|
||||||
|
func (s *accountSubrouter) setMockListingCount(c *gin.Context) (response.Response, error) {
|
||||||
|
acctID := auth.GetIdentity(c).Account.AccountID
|
||||||
|
|
||||||
|
var (
|
||||||
|
platform accounts.Platform
|
||||||
shopID string
|
shopID string
|
||||||
listingID string
|
listingID string
|
||||||
count int
|
count int
|
||||||
)
|
)
|
||||||
|
|
||||||
if err := param.Path("shopID", param.Text(&shopID)).
|
if err := param.Form("platform", param.Platform(&platform)).
|
||||||
|
Path("shopID", param.Text(&shopID)).
|
||||||
Path("listingID", param.Text(&listingID)).
|
Path("listingID", param.Text(&listingID)).
|
||||||
Form("count", param.Int(&count)).
|
Form("count", param.Int(&count)).
|
||||||
Unmarshal(c); err != nil {
|
Unmarshal(c); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
s.log.Debugf("listing inventory set:")
|
if _, err := s.accts.SaveNewMockInventoryReset(c, acctID, platform, shopID, listingID, count); err != nil {
|
||||||
s.log.Debugf(" account: %d", acctID)
|
return nil, fmt.Errorf("failed to save new mock inventory reset: %w", err)
|
||||||
s.log.Debugf(" shop: %s", shopID)
|
}
|
||||||
s.log.Debugf(" listing: %s", listingID)
|
|
||||||
s.log.Debugf(" count: %d", count)
|
|
||||||
|
|
||||||
return response.StatusOK(), nil
|
return response.StatusOK(), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -906,6 +906,26 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.active\:bg-accent {
|
||||||
|
&:active {
|
||||||
|
background-color: var(--accent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.active\:bg-accent-secondary {
|
||||||
|
&:active {
|
||||||
|
background-color: var(--accent-secondary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.active\:bg-muted {
|
||||||
|
&:active {
|
||||||
|
background-color: var(--muted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.active\:bg-secondary {
|
||||||
|
&:active {
|
||||||
|
background-color: var(--secondary);
|
||||||
|
}
|
||||||
|
}
|
||||||
.disabled\:cursor-not-allowed {
|
.disabled\:cursor-not-allowed {
|
||||||
&:disabled {
|
&:disabled {
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
|
|||||||
@@ -0,0 +1,136 @@
|
|||||||
|
{{/* [ .Shops, .SelectedPlatform, .SelectedShopID, .Listings ] */}}
|
||||||
|
|
||||||
|
{{- $acctID := .Identity.Account.AccountID -}}
|
||||||
|
{{- $shops := .Shops }}
|
||||||
|
{{- if not $shops }}
|
||||||
|
{{- $shops = .Accounts.GetMockShops $acctID -}}
|
||||||
|
{{- end }}
|
||||||
|
{{- $selectedPlatform := .SelectedPlatform }}
|
||||||
|
{{- $selectedShopID := .SelectedShopID }}
|
||||||
|
{{- if not $selectedPlatform | or (not $selectedShopID) }}
|
||||||
|
{{- $formSelections := .Accounts.GetMockEventFormValues $acctID }}
|
||||||
|
{{- $selectedPlatform = $formSelections.RefundPlatform }}
|
||||||
|
{{- $selectedShopID = $formSelections.RefundShopID }}
|
||||||
|
{{- end }}
|
||||||
|
{{- $listings := .Listings }}
|
||||||
|
{{- if $selectedShopID }}
|
||||||
|
{{ $listings = .Accounts.GetMockListingsForShop $acctID $selectedPlatform $selectedShopID }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{{/* REFUNDS */}}
|
||||||
|
{{- define "refund-accordion-header" }}
|
||||||
|
<h2 class="inline-block">
|
||||||
|
Refund
|
||||||
|
</h2>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{- define "refund-accordion-body" }}
|
||||||
|
{{ $acctID := .Identity.Account.AccountID }}
|
||||||
|
{{ $selectedPlatform := .SelectedPlatform }}
|
||||||
|
{{ $selectedShopID := .SelectedShopID }}
|
||||||
|
{{ $listings := .Listings }}
|
||||||
|
|
||||||
|
{{/* form updater*/}}
|
||||||
|
<div
|
||||||
|
hidden
|
||||||
|
hx-trigger="sse:accounts_{{$acctID}}_simulations_refund"
|
||||||
|
hx-get="/ui/accounts/{{$acctID}}/simulations/refund-form"
|
||||||
|
hx-select="#refund-form"
|
||||||
|
hx-target="#refund-form"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form
|
||||||
|
id="refund-form"
|
||||||
|
class="flex flex-col items-center gap-[0.75em]"
|
||||||
|
hx-post="/api/accounts/{{$acctID}}/simulations/refund"
|
||||||
|
hx-swap="none"
|
||||||
|
hx-vals='js:{
|
||||||
|
"platform": {{printf "%q" $selectedPlatform}},
|
||||||
|
"shop-id": {{printf "%q" $selectedShopID}},
|
||||||
|
}'
|
||||||
|
>
|
||||||
|
<select
|
||||||
|
name="shop-id"
|
||||||
|
class="bg-background"
|
||||||
|
required
|
||||||
|
hx-put="/api/accounts/{{$acctID}}/simulations/refund/form/shop"
|
||||||
|
hx-vals='js:{
|
||||||
|
platform: event.target.value.replace(/-[^ ]*/, ""),
|
||||||
|
"shop-id": event.target.value.replace(/[^ -]*-/, "")
|
||||||
|
}'
|
||||||
|
>
|
||||||
|
<option disabled selected>
|
||||||
|
- Select A Shop -
|
||||||
|
</option>
|
||||||
|
{{- range $shop := .Shops }}
|
||||||
|
<option
|
||||||
|
value="{{$shop.Platform}}-{{$shop.ShopID}}"
|
||||||
|
{{- if and
|
||||||
|
(eq $shop.Platform $selectedPlatform)
|
||||||
|
(eq $shop.ShopID $selectedShopID)
|
||||||
|
}}
|
||||||
|
selected
|
||||||
|
{{- end }}
|
||||||
|
>
|
||||||
|
{{ $shop.Name }}
|
||||||
|
</option>
|
||||||
|
{{- end }}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select
|
||||||
|
name="listing-id"
|
||||||
|
class="bg-background"
|
||||||
|
required
|
||||||
|
>
|
||||||
|
{{- if $listings }}
|
||||||
|
<option disabled selected>
|
||||||
|
- Select A Listing -
|
||||||
|
</option>
|
||||||
|
{{- range $listing := $listings }}
|
||||||
|
<option value="{{$listing.ListingID}}">
|
||||||
|
{{ $listing.Name }} - {{ $listing.SKU }}
|
||||||
|
</option>
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
<option disabled selected>
|
||||||
|
- No Listings Found -
|
||||||
|
</option>
|
||||||
|
{{- end }}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<input
|
||||||
|
class="p-[0.5em] border-medium border-border rounded-lg bg-background"
|
||||||
|
type="number"
|
||||||
|
min="1"
|
||||||
|
max="1000000000"
|
||||||
|
name="count"
|
||||||
|
value="0"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{{ component "button"
|
||||||
|
"Text" "Submit"
|
||||||
|
"Background" true
|
||||||
|
"Class" "m-0"
|
||||||
|
}}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ component "accordion"
|
||||||
|
"Name" "simulate"
|
||||||
|
"Shops" $shops
|
||||||
|
"SelectedPlatform" $selectedPlatform
|
||||||
|
"SelectedShopID" $selectedShopID
|
||||||
|
"Listings" $listings
|
||||||
|
"Class" `
|
||||||
|
mx-[1em]
|
||||||
|
mb-[1em]
|
||||||
|
`
|
||||||
|
"#accordion-header" "refund-accordion-header"
|
||||||
|
"#accordion-body" "refund-accordion-body"
|
||||||
|
}}
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
{{/* [ .Shops, .SelectedPlatform, .SelectedShopID, .Listings ] */}}
|
||||||
|
|
||||||
|
{{- $acctID := .Identity.Account.AccountID -}}
|
||||||
|
{{- $shops := .Shops }}
|
||||||
|
{{- if not $shops }}
|
||||||
|
{{- $shops = .Accounts.GetMockShops $acctID -}}
|
||||||
|
{{- end }}
|
||||||
|
{{- $selectedPlatform := .SelectedPlatform }}
|
||||||
|
{{- $selectedShopID := .SelectedShopID }}
|
||||||
|
{{- if not $selectedPlatform | or (not $selectedShopID) }}
|
||||||
|
{{- $formSelections := .Accounts.GetMockEventFormValues $acctID }}
|
||||||
|
{{- $selectedPlatform = $formSelections.SalePlatform }}
|
||||||
|
{{- $selectedShopID = $formSelections.SaleShopID }}
|
||||||
|
{{- end }}
|
||||||
|
{{- $listings := .Listings }}
|
||||||
|
{{- if $selectedShopID }}
|
||||||
|
{{ $listings = .Accounts.GetMockListingsForShop $acctID $selectedPlatform $selectedShopID }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{{/* SALES */}}
|
||||||
|
{{- define "sale-accordion-header" }}
|
||||||
|
<h2 class="inline-block">
|
||||||
|
Sale
|
||||||
|
</h2>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{- define "sale-accordion-body" }}
|
||||||
|
{{ $acctID := .Identity.Account.AccountID }}
|
||||||
|
{{ $selectedPlatform := .SelectedPlatform }}
|
||||||
|
{{ $selectedShopID := .SelectedShopID }}
|
||||||
|
{{ $listings := .Listings }}
|
||||||
|
|
||||||
|
{{/* form updater*/}}
|
||||||
|
<div
|
||||||
|
hidden
|
||||||
|
hx-trigger="sse:accounts_{{$acctID}}_simulations_sale"
|
||||||
|
hx-get="/ui/accounts/{{$acctID}}/simulations/sales-form"
|
||||||
|
hx-select="#sales-form"
|
||||||
|
hx-target="#sales-form"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form
|
||||||
|
id="sales-form"
|
||||||
|
class="flex flex-col items-center gap-[0.75em]"
|
||||||
|
hx-post="/api/accounts/{{$acctID}}/simulations/sale"
|
||||||
|
hx-swap="none"
|
||||||
|
hx-vals='js:{
|
||||||
|
"platform": {{printf "%q" $selectedPlatform}},
|
||||||
|
"shop-id": {{printf "%q" $selectedShopID}},
|
||||||
|
}'
|
||||||
|
>
|
||||||
|
<select
|
||||||
|
name="shop-id"
|
||||||
|
class="bg-background"
|
||||||
|
required
|
||||||
|
hx-put="/api/accounts/{{$acctID}}/simulations/sale/form/shop"
|
||||||
|
hx-vals='js:{
|
||||||
|
platform: event.target.value.replace(/-[^ ]*/, ""),
|
||||||
|
"shop-id": event.target.value.replace(/[^ -]*-/, "")
|
||||||
|
}'
|
||||||
|
>
|
||||||
|
<option disabled selected>
|
||||||
|
- Select A Shop -
|
||||||
|
</option>
|
||||||
|
{{- range $shop := .Shops }}
|
||||||
|
<option
|
||||||
|
value="{{$shop.Platform}}-{{$shop.ShopID}}"
|
||||||
|
{{- if and
|
||||||
|
(eq $shop.Platform $selectedPlatform)
|
||||||
|
(eq $shop.ShopID $selectedShopID)
|
||||||
|
}}
|
||||||
|
selected
|
||||||
|
{{- end }}
|
||||||
|
>
|
||||||
|
{{ $shop.Name }}
|
||||||
|
</option>
|
||||||
|
{{- end }}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select
|
||||||
|
name="listing-id"
|
||||||
|
class="bg-background"
|
||||||
|
required
|
||||||
|
>
|
||||||
|
{{- if $listings }}
|
||||||
|
<option disabled selected>
|
||||||
|
- Select A Listing -
|
||||||
|
</option>
|
||||||
|
{{- range $listing := $listings }}
|
||||||
|
<option value="{{$listing.ListingID}}">
|
||||||
|
{{ $listing.Name }} - {{ $listing.SKU }}
|
||||||
|
</option>
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
<option disabled selected>
|
||||||
|
- No Listings Found -
|
||||||
|
</option>
|
||||||
|
{{- end }}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<input
|
||||||
|
class="p-[0.5em] border-medium border-border rounded-lg bg-background"
|
||||||
|
type="number"
|
||||||
|
min="1"
|
||||||
|
max="1000000000"
|
||||||
|
name="count"
|
||||||
|
value="0"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{{ component "button"
|
||||||
|
"Text" "Submit"
|
||||||
|
"Background" true
|
||||||
|
"Class" "m-0"
|
||||||
|
}}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ component "accordion"
|
||||||
|
"Name" "simulate"
|
||||||
|
"Shops" $shops
|
||||||
|
"SelectedPlatform" $selectedPlatform
|
||||||
|
"SelectedShopID" $selectedShopID
|
||||||
|
"Listings" $listings
|
||||||
|
"Class" `
|
||||||
|
mx-[1em]
|
||||||
|
mb-[1em]
|
||||||
|
`
|
||||||
|
"#accordion-header" "sale-accordion-header"
|
||||||
|
"#accordion-body" "sale-accordion-body"
|
||||||
|
}}
|
||||||
+136
@@ -0,0 +1,136 @@
|
|||||||
|
{{/* [ .Shops, .SelectedPlatform, .SelectedShopID, .Listings ] */}}
|
||||||
|
|
||||||
|
{{- $acctID := .Identity.Account.AccountID -}}
|
||||||
|
{{- $shops := .Shops }}
|
||||||
|
{{- if not $shops }}
|
||||||
|
{{- $shops = .Accounts.GetMockShops $acctID -}}
|
||||||
|
{{- end }}
|
||||||
|
{{- $selectedPlatform := .SelectedPlatform }}
|
||||||
|
{{- $selectedShopID := .SelectedShopID }}
|
||||||
|
{{- if not $selectedPlatform | or (not $selectedShopID) }}
|
||||||
|
{{- $formSelections := .Accounts.GetMockEventFormValues $acctID }}
|
||||||
|
{{- $selectedPlatform = $formSelections.CountPlatform }}
|
||||||
|
{{- $selectedShopID = $formSelections.CountShopID }}
|
||||||
|
{{- end }}
|
||||||
|
{{- $listings := .Listings }}
|
||||||
|
{{- if $selectedShopID }}
|
||||||
|
{{ $listings = .Accounts.GetMockListingsForShop $acctID $selectedPlatform $selectedShopID }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{{/* SET INVENTORY */}}
|
||||||
|
{{- define "set-inventory-accordion-header" }}
|
||||||
|
<h2 class="inline-block">
|
||||||
|
Set Inventory
|
||||||
|
</h2>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{- define "set-inventory-accordion-body" }}
|
||||||
|
{{ $acctID := .Identity.Account.AccountID }}
|
||||||
|
{{ $selectedPlatform := .SelectedPlatform }}
|
||||||
|
{{ $selectedShopID := .SelectedShopID }}
|
||||||
|
{{ $listings := .Listings }}
|
||||||
|
|
||||||
|
{{/* form updater*/}}
|
||||||
|
<div
|
||||||
|
hidden
|
||||||
|
hx-trigger="sse:accounts_{{$acctID}}_simulations_shops"
|
||||||
|
hx-get="/ui/accounts/{{$acctID}}/simulations/set-inventory-form"
|
||||||
|
hx-select="#set-inventory-form"
|
||||||
|
hx-target="#set-inventory-form"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form
|
||||||
|
id="set-inventory-form"
|
||||||
|
class="flex flex-col items-center gap-[0.75em]"
|
||||||
|
hx-put="/api/accounts/{{$acctID}}/simulations/shops/{shop-id}/listings/{listing-id}/count"
|
||||||
|
hx-swap="none"
|
||||||
|
hx-vals='js:{
|
||||||
|
"platform": {{printf "%q" $selectedPlatform}},
|
||||||
|
"shop-id": {{printf "%q" $selectedShopID}},
|
||||||
|
}'
|
||||||
|
>
|
||||||
|
<select
|
||||||
|
name="shop-id"
|
||||||
|
class="bg-background"
|
||||||
|
required
|
||||||
|
hx-put="/api/accounts/{{$acctID}}/simulations/count/form/shop"
|
||||||
|
hx-vals='js:{
|
||||||
|
platform: event.target.value.replace(/-[^ ]*/, ""),
|
||||||
|
"shop-id": event.target.value.replace(/[^ -]*-/, "")
|
||||||
|
}'
|
||||||
|
>
|
||||||
|
<option disabled selected>
|
||||||
|
- Select A Shop -
|
||||||
|
</option>
|
||||||
|
{{- range $shop := .Shops }}
|
||||||
|
<option
|
||||||
|
value="{{$shop.Platform}}-{{$shop.ShopID}}"
|
||||||
|
{{- if and
|
||||||
|
(eq $shop.Platform $selectedPlatform)
|
||||||
|
(eq $shop.ShopID $selectedShopID)
|
||||||
|
}}
|
||||||
|
selected
|
||||||
|
{{- end }}
|
||||||
|
>
|
||||||
|
{{ $shop.Name }}
|
||||||
|
</option>
|
||||||
|
{{- end }}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select
|
||||||
|
name="listing-id"
|
||||||
|
class="bg-background"
|
||||||
|
required
|
||||||
|
>
|
||||||
|
{{- if $listings }}
|
||||||
|
<option disabled selected>
|
||||||
|
- Select A Listing -
|
||||||
|
</option>
|
||||||
|
{{- range $listing := $listings }}
|
||||||
|
<option value="{{$listing.ListingID}}">
|
||||||
|
{{ $listing.Name }} - {{ $listing.SKU }}
|
||||||
|
</option>
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
<option disabled selected>
|
||||||
|
- No Listings Found -
|
||||||
|
</option>
|
||||||
|
{{- end }}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<input
|
||||||
|
class="p-[0.5em] border-medium border-border rounded-lg bg-background"
|
||||||
|
type="number"
|
||||||
|
min="1"
|
||||||
|
max="1000000000"
|
||||||
|
name="count"
|
||||||
|
value="0"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{{ component "button"
|
||||||
|
"Text" "Submit"
|
||||||
|
"Background" true
|
||||||
|
"Class" "m-0"
|
||||||
|
}}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ component "accordion"
|
||||||
|
"Name" "simulate"
|
||||||
|
"Shops" $shops
|
||||||
|
"SelectedPlatform" $selectedPlatform
|
||||||
|
"SelectedShopID" $selectedShopID
|
||||||
|
"Listings" $listings
|
||||||
|
"Class" `
|
||||||
|
mx-[1em]
|
||||||
|
mb-[1em]
|
||||||
|
`
|
||||||
|
"#accordion-header" "set-inventory-accordion-header"
|
||||||
|
"#accordion-body" "set-inventory-accordion-body"
|
||||||
|
}}
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
cursor-pointer
|
cursor-pointer
|
||||||
hover:underline
|
hover:underline
|
||||||
hover:bg-accent
|
hover:bg-accent
|
||||||
|
active:bg-accent-secondary
|
||||||
disabled:bg-accent-secondary
|
disabled:bg-accent-secondary
|
||||||
disabled:cursor-not-allowed
|
disabled:cursor-not-allowed
|
||||||
disabled:no-underline
|
disabled:no-underline
|
||||||
|
|||||||
@@ -1,275 +1,48 @@
|
|||||||
<h1 class="text-center">
|
{{- $acctID := .Identity.Account.AccountID -}}
|
||||||
Simulations
|
{{- $shops := .Accounts.GetMockShops $acctID -}}
|
||||||
|
{{- $formSelections := .Accounts.GetMockEventFormValues $acctID -}}
|
||||||
|
|
||||||
|
{{- $saleShopListings := "" }}
|
||||||
|
{{- if $formSelections.SaleShopID }}
|
||||||
|
{{ $saleShopListings = .Accounts.GetMockListingsForShop $acctID $formSelections.SalePlatform $formSelections.SaleShopID }}
|
||||||
|
{{- end }}
|
||||||
|
{{- $refundShopListings := "" }}
|
||||||
|
{{- if $formSelections.RefundShopID }}
|
||||||
|
{{ $refundShopListings = .Accounts.GetMockListingsForShop $acctID $formSelections.SalePlatform $formSelections.RefundShopID }}
|
||||||
|
{{- end }}
|
||||||
|
{{- $setInventoryShopListings := "" }}
|
||||||
|
{{- if $formSelections.CountShopID }}
|
||||||
|
{{ $setInventoryShopListings = .Accounts.GetMockListingsForShop $acctID $formSelections.SalePlatform $formSelections.CountShopID }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
|
||||||
|
<h1 class="text-center my-[0.5em]">
|
||||||
|
Simulate
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
|
|
||||||
{{/* SALES */}}
|
{{/* SALES */}}
|
||||||
{{- define "sale-accordion-header" }}
|
{{ component (printf "/accounts/%d/simulations/sales-form" $acctID)
|
||||||
<h2 class="inline-block">
|
"Shops" $shops
|
||||||
Sale
|
"SelectedPlatform" $formSelections.SalePlatform
|
||||||
</h2>
|
"SelectedShopID" $formSelections.SaleShopID
|
||||||
{{ end }}
|
"Listings" $saleShopListings
|
||||||
|
|
||||||
{{- define "sale-accordion-body" }}
|
|
||||||
{{ $acctID := .Identity.Account.AccountID }}
|
|
||||||
<form
|
|
||||||
class="flex flex-col items-center gap-[0.75em]"
|
|
||||||
hx-post="/api/accounts/{{$acctID}}/simulations/sale"
|
|
||||||
hx-swap="none"
|
|
||||||
>
|
|
||||||
<select
|
|
||||||
name="shop-id"
|
|
||||||
class="bg-background"
|
|
||||||
required
|
|
||||||
>
|
|
||||||
<option value="shop-1">
|
|
||||||
Shop 1
|
|
||||||
</option>
|
|
||||||
<option value="shop-2">
|
|
||||||
Shop 2
|
|
||||||
</option>
|
|
||||||
<option value="shop-3">
|
|
||||||
Shop 3
|
|
||||||
</option>
|
|
||||||
<option value="shop-4">
|
|
||||||
Shop 4
|
|
||||||
</option>
|
|
||||||
<option value="shop-5">
|
|
||||||
Shop 5
|
|
||||||
</option>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select
|
|
||||||
name="listing-id"
|
|
||||||
class="bg-background"
|
|
||||||
required
|
|
||||||
>
|
|
||||||
<option value="listing-1">
|
|
||||||
Listing 1
|
|
||||||
</option>
|
|
||||||
<option value="listing-2">
|
|
||||||
Listing 2
|
|
||||||
</option>
|
|
||||||
<option value="listing-3">
|
|
||||||
Listing 3
|
|
||||||
</option>
|
|
||||||
<option value="listing-4">
|
|
||||||
Listing 4
|
|
||||||
</option>
|
|
||||||
<option value="listing-5">
|
|
||||||
Listing 5
|
|
||||||
</option>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<input
|
|
||||||
class="p-[0.5em] border-medium border-border rounded-lg bg-background"
|
|
||||||
type="number"
|
|
||||||
min="1"
|
|
||||||
max="1000000000"
|
|
||||||
name="count"
|
|
||||||
value="0"
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
{{ component "button"
|
|
||||||
"Text" "Submit"
|
|
||||||
"Background" true
|
|
||||||
"Class" "m-0"
|
|
||||||
}}
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
{{ component "accordion"
|
|
||||||
"Name" "simulate"
|
|
||||||
"Open" true
|
|
||||||
"Class" `
|
|
||||||
mx-[1em]
|
|
||||||
mb-[1em]
|
|
||||||
`
|
|
||||||
"#accordion-header" "sale-accordion-header"
|
|
||||||
"#accordion-body" "sale-accordion-body"
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
||||||
{{/* REFUNDS */}}
|
{{/* REFUNDS */}}
|
||||||
{{- define "refund-accordion-header" }}
|
{{ component (printf "/accounts/%d/simulations/refund-form" $acctID)
|
||||||
<h2 class="inline-block">
|
"Shops" $shops
|
||||||
Refund
|
"SelectedPlatform" $formSelections.RefundPlatform
|
||||||
</h2>
|
"SelectedShopID" $formSelections.RefundShopID
|
||||||
{{ end }}
|
"Listings" $refundShopListings
|
||||||
|
|
||||||
{{- define "refund-accordion-body" }}
|
|
||||||
{{ $acctID := .Identity.Account.AccountID }}
|
|
||||||
<form
|
|
||||||
class="flex flex-col items-center gap-[0.75em]"
|
|
||||||
hx-post="/api/accounts/{{$acctID}}/simulations/refund"
|
|
||||||
hx-swap="none"
|
|
||||||
>
|
|
||||||
<select
|
|
||||||
name="shop-id"
|
|
||||||
class="bg-background"
|
|
||||||
required
|
|
||||||
>
|
|
||||||
<option value="shop-1">
|
|
||||||
Shop 1
|
|
||||||
</option>
|
|
||||||
<option value="shop-2">
|
|
||||||
Shop 2
|
|
||||||
</option>
|
|
||||||
<option value="shop-3">
|
|
||||||
Shop 3
|
|
||||||
</option>
|
|
||||||
<option value="shop-4">
|
|
||||||
Shop 4
|
|
||||||
</option>
|
|
||||||
<option value="shop-5">
|
|
||||||
Shop 5
|
|
||||||
</option>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select
|
|
||||||
name="listing-id"
|
|
||||||
class="bg-background"
|
|
||||||
required
|
|
||||||
>
|
|
||||||
<option value="listing-1">
|
|
||||||
Listing 1
|
|
||||||
</option>
|
|
||||||
<option value="listing-2">
|
|
||||||
Listing 2
|
|
||||||
</option>
|
|
||||||
<option value="listing-3">
|
|
||||||
Listing 3
|
|
||||||
</option>
|
|
||||||
<option value="listing-4">
|
|
||||||
Listing 4
|
|
||||||
</option>
|
|
||||||
<option value="listing-5">
|
|
||||||
Listing 5
|
|
||||||
</option>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<input
|
|
||||||
class="p-[0.5em] border-medium border-border rounded-lg bg-background"
|
|
||||||
type="number"
|
|
||||||
min="1"
|
|
||||||
max="1000000000"
|
|
||||||
name="count"
|
|
||||||
value="0"
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
{{ component "button"
|
|
||||||
"Text" "Submit"
|
|
||||||
"Background" true
|
|
||||||
"Class" "m-0"
|
|
||||||
}}
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
{{ component "accordion"
|
|
||||||
"Name" "simulate"
|
|
||||||
"Class" `
|
|
||||||
mx-[1em]
|
|
||||||
mb-[1em]
|
|
||||||
`
|
|
||||||
"#accordion-header" "refund-accordion-header"
|
|
||||||
"#accordion-body" "refund-accordion-body"
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
||||||
{{/* SET INVENTORY */}}
|
{{/* SET INVENTORY */}}
|
||||||
{{- define "set-inventory-accordion-header" }}
|
{{ component (printf "/accounts/%d/simulations/set-inventory-form" $acctID)
|
||||||
<h2 class="inline-block">
|
"Shops" $shops
|
||||||
Set Inventory
|
"SelectedPlatform" $formSelections.CountPlatform
|
||||||
</h2>
|
"SelectedShopID" $formSelections.CountShopID
|
||||||
{{ end }}
|
"Listings" $setInventoryShopListings
|
||||||
|
|
||||||
{{- define "set-inventory-accordion-body" }}
|
|
||||||
{{ $acctID := .Identity.Account.AccountID }}
|
|
||||||
<form
|
|
||||||
class="flex flex-col items-center gap-[0.75em]"
|
|
||||||
hx-put="/api/accounts/{{$acctID}}/simulations/shops/{shopID}/listings/{listingID}/count"
|
|
||||||
hx-vals='js:{
|
|
||||||
shopID: event.target.children.namedItem("shop-id").value,
|
|
||||||
listingID: event.target.children.namedItem("listing-id").value
|
|
||||||
}'
|
|
||||||
hx-swap="none"
|
|
||||||
>
|
|
||||||
<select
|
|
||||||
name="shop-id"
|
|
||||||
class="bg-background"
|
|
||||||
required
|
|
||||||
>
|
|
||||||
<option value="shop-1">
|
|
||||||
Shop 1
|
|
||||||
</option>
|
|
||||||
<option value="shop-2">
|
|
||||||
Shop 2
|
|
||||||
</option>
|
|
||||||
<option value="shop-3">
|
|
||||||
Shop 3
|
|
||||||
</option>
|
|
||||||
<option value="shop-4">
|
|
||||||
Shop 4
|
|
||||||
</option>
|
|
||||||
<option value="shop-5">
|
|
||||||
Shop 5
|
|
||||||
</option>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select
|
|
||||||
name="listing-id"
|
|
||||||
class="bg-background"
|
|
||||||
required
|
|
||||||
>
|
|
||||||
<option value="listing-1">
|
|
||||||
Listing 1
|
|
||||||
</option>
|
|
||||||
<option value="listing-2">
|
|
||||||
Listing 2
|
|
||||||
</option>
|
|
||||||
<option value="listing-3">
|
|
||||||
Listing 3
|
|
||||||
</option>
|
|
||||||
<option value="listing-4">
|
|
||||||
Listing 4
|
|
||||||
</option>
|
|
||||||
<option value="listing-5">
|
|
||||||
Listing 5
|
|
||||||
</option>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<input
|
|
||||||
class="p-[0.5em] border-medium border-border rounded-lg bg-background"
|
|
||||||
type="number"
|
|
||||||
min="1"
|
|
||||||
max="1000000000"
|
|
||||||
name="count"
|
|
||||||
value="0"
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
{{ component "button"
|
|
||||||
"Text" "Submit"
|
|
||||||
"Background" true
|
|
||||||
"Class" "m-0"
|
|
||||||
}}
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
{{ component "accordion"
|
|
||||||
"Name" "simulate"
|
|
||||||
"Class" `
|
|
||||||
mx-[1em]
|
|
||||||
mb-[1em]
|
|
||||||
`
|
|
||||||
"#accordion-header" "set-inventory-accordion-header"
|
|
||||||
"#accordion-body" "set-inventory-accordion-body"
|
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user