commit 2bdc1d510c06dbaf97f40504e67e11b42f6c195d
parent 3ea8a32ca494bf06cae57061235cade4a520b59a
Author: triesap <137732411+triesap@users.noreply.github.com>
Date: Mon, 11 Nov 2024 05:17:03 +0000
client: update iclientdb add `trade_product_location` methods, models get one method
Diffstat:
2 files changed, 85 insertions(+), 5 deletions(-)
diff --git a/client/src/database/tauri.ts b/client/src/database/tauri.ts
@@ -1,5 +1,5 @@
-import { LocationGcsSchema, LocationGcsUpdateSchema, NostrProfileSchema, NostrProfileUpdateSchema, NostrRelaySchema, NostrRelayUpdateSchema, TradeProductSchema, TradeProductUpdateSchema, parse_location_gcs_form_fields, parse_location_gcs_list, parse_nostr_profile_form_fields, parse_nostr_profile_list, parse_nostr_relay_form_fields, parse_nostr_relay_list, parse_trade_product_form_fields, parse_trade_product_list, type ILocationGcsAdd, type ILocationGcsAddResolve, type ILocationGcsDelete, type ILocationGcsDeleteResolve, type ILocationGcsGet, type ILocationGcsGetResolve, type ILocationGcsUpdate, type ILocationGcsUpdateResolve, type IModelsQueryBindValueTuple, type IModelsQueryValue, type INostrProfileAdd, type INostrProfileAddResolve, type INostrProfileDelete, type INostrProfileDeleteResolve, type INostrProfileGet, type INostrProfileGetResolve, type INostrProfileRelayRelation, type INostrProfileRelayRelationResolve, type INostrProfileUpdate, type INostrProfileUpdateResolve, type INostrRelayAdd, type INostrRelayAddResolve, type INostrRelayDelete, type INostrRelayDeleteResolve, type INostrRelayGet, type INostrRelayGetResolve, type INostrRelayUpdate, type INostrRelayUpdateResolve, type ITradeProductAdd, type ITradeProductAddResolve, type ITradeProductDelete, type ITradeProductDeleteResolve, type ITradeProductGet, type ITradeProductGetResolve, type ITradeProductUpdate, type ITradeProductUpdateResolve, type LocationGcsFields, type LocationGcsFormFields, type NostrProfileFields, type NostrProfileFormFields, type NostrRelayFields, type NostrRelayFormFields, type TradeProductFields, type TradeProductFormFields } from "@radroots/models";
+import { LocationGcsSchema, LocationGcsUpdateSchema, NostrProfileSchema, NostrProfileUpdateSchema, NostrRelaySchema, NostrRelayUpdateSchema, TradeProductSchema, TradeProductUpdateSchema, parse_location_gcs, parse_location_gcs_form_fields, parse_location_gcs_list, parse_nostr_profile, parse_nostr_profile_form_fields, parse_nostr_profile_list, parse_nostr_relay, parse_nostr_relay_form_fields, parse_nostr_relay_list, parse_trade_product, parse_trade_product_form_fields, parse_trade_product_list, type ILocationGcsAdd, type ILocationGcsAddResolve, type ILocationGcsDelete, type ILocationGcsDeleteResolve, type ILocationGcsGet, type ILocationGcsGetOne, type ILocationGcsGetOneResolve, type ILocationGcsGetResolve, type ILocationGcsUpdate, type ILocationGcsUpdateResolve, type IModelsQueryBindValueTuple, type IModelsQueryValue, type INostrProfileAdd, type INostrProfileAddResolve, type INostrProfileDelete, type INostrProfileDeleteResolve, type INostrProfileGet, type INostrProfileGetOne, type INostrProfileGetOneResolve, type INostrProfileGetResolve, type INostrProfileRelayRelation, type INostrProfileRelayRelationResolve, type INostrProfileUpdate, type INostrProfileUpdateResolve, type INostrRelayAdd, type INostrRelayAddResolve, type INostrRelayDelete, type INostrRelayDeleteResolve, type INostrRelayGet, type INostrRelayGetOne, type INostrRelayGetOneResolve, type INostrRelayGetResolve, type INostrRelayUpdate, type INostrRelayUpdateResolve, type ITradeProductAdd, type ITradeProductAddResolve, type ITradeProductDelete, type ITradeProductDeleteResolve, type ITradeProductGet, type ITradeProductGetOne, type ITradeProductGetOneResolve, type ITradeProductGetResolve, type ITradeProductLocationRelation, type ITradeProductLocationRelationResolve, type ITradeProductUpdate, type ITradeProductUpdateResolve, type LocationGcsFields, type LocationGcsFormFields, type NostrProfileFields, type NostrProfileFormFields, type NostrRelayFields, type NostrRelayFormFields, type TradeProductFields, type TradeProductFormFields } from "@radroots/models";
import { err_msg, type ErrorMessage } from "@radroots/utils";
import { invoke } from "@tauri-apps/api/core";
import type { IClientDatabase, IClientDatabaseMessage } from "./types";
@@ -10,7 +10,7 @@ export class TauriClientDatabase implements IClientDatabase {
const error_msg = String(error);
return error_msg;
}
-
+
private handle_errors(scope: string, opts: any, e: any): ErrorMessage<IClientDatabaseMessage> {
const error = this.append_logs(scope, opts, e);
if (error.includes("UNIQUE constraint failed: location_gcs.geohash")) return err_msg("*-location-gcs-geohash-unique");
@@ -21,7 +21,7 @@ export class TauriClientDatabase implements IClientDatabase {
private filter_bind_value_fields(fields: IModelsQueryBindValueTuple[]): IModelsQueryBindValueTuple[] {
return fields.filter(([_, v]) => !!v);
}
-
+
private location_gcs_add_validate(fields: LocationGcsFormFields): LocationGcsFields | string[] {
const fields_r = Object.entries(fields).filter(([_, v]) => !!v).reduce((acc: Record<string, IModelsQueryValue>, i) => {
const [key, val] = parse_location_gcs_form_fields(i);
@@ -62,6 +62,20 @@ export class TauriClientDatabase implements IClientDatabase {
};
}
+ public async location_gcs_get_one(opts: ILocationGcsGetOne): Promise<ILocationGcsGetOneResolve<IClientDatabaseMessage>> {
+ try {
+ const response = await invoke<any>("model_location_gcs_get", { opts: { on: { ...opts } } });
+ if (typeof response === "string") return err_msg(response);
+ else if ("results" in response && Array.isArray(response.results) && response.results.length === 1) {
+ const result = parse_location_gcs(response.results[0]);
+ if (result) return { result };
+ }
+ return err_msg("*-result");
+ } catch (e) {
+ return this.handle_errors("model_location_gcs_get", opts, e);
+ };
+ }
+
public async location_gcs_delete(opts: ILocationGcsDelete): Promise<ILocationGcsDeleteResolve<IClientDatabaseMessage>> {
try {
const response = await invoke<any>("model_location_gcs_delete", { opts });
@@ -140,6 +154,20 @@ export class TauriClientDatabase implements IClientDatabase {
};
}
+ public async trade_product_get_one(opts: ITradeProductGetOne): Promise<ITradeProductGetOneResolve<IClientDatabaseMessage>> {
+ try {
+ const response = await invoke<any>("model_trade_product_get", { opts: { on: { ...opts } } });
+ if (typeof response === "string") return err_msg(response);
+ else if ("results" in response && Array.isArray(response.results) && response.results.length === 1) {
+ const result = parse_trade_product(response.results[0]);
+ if (result) return { result };
+ }
+ return err_msg("*-result");
+ } catch (e) {
+ return this.handle_errors("model_trade_product_get", opts, e);
+ };
+ }
+
public async trade_product_delete(opts: ITradeProductDelete): Promise<ITradeProductDeleteResolve<IClientDatabaseMessage>> {
try {
const response = await invoke<any>("model_trade_product_delete", { opts });
@@ -218,6 +246,20 @@ export class TauriClientDatabase implements IClientDatabase {
};
}
+ public async nostr_profile_get_one(opts: INostrProfileGetOne): Promise<INostrProfileGetOneResolve<IClientDatabaseMessage>> {
+ try {
+ const response = await invoke<any>("model_nostr_profile_get", { opts: { on: { ...opts } } });
+ if (typeof response === "string") return err_msg(response);
+ else if ("results" in response && Array.isArray(response.results) && response.results.length === 1) {
+ const result = parse_nostr_profile(response.results[0]);
+ if (result) return { result };
+ }
+ return err_msg("*-result");
+ } catch (e) {
+ return this.handle_errors("model_nostr_profile_get", opts, e);
+ };
+ }
+
public async nostr_profile_delete(opts: INostrProfileDelete): Promise<INostrProfileDeleteResolve<IClientDatabaseMessage>> {
try {
const response = await invoke<any>("model_nostr_profile_delete", { opts });
@@ -296,6 +338,20 @@ export class TauriClientDatabase implements IClientDatabase {
};
}
+ public async nostr_relay_get_one(opts: INostrRelayGetOne): Promise<INostrRelayGetOneResolve<IClientDatabaseMessage>> {
+ try {
+ const response = await invoke<any>("model_nostr_relay_get", { opts: { on: { ...opts } } });
+ if (typeof response === "string") return err_msg(response);
+ else if ("results" in response && Array.isArray(response.results) && response.results.length === 1) {
+ const result = parse_nostr_relay(response.results[0]);
+ if (result) return { result };
+ }
+ return err_msg("*-result");
+ } catch (e) {
+ return this.handle_errors("model_nostr_relay_get", opts, e);
+ };
+ }
+
public async nostr_relay_delete(opts: INostrRelayDelete): Promise<INostrRelayDeleteResolve<IClientDatabaseMessage>> {
try {
const response = await invoke<any>("model_nostr_relay_delete", { opts });
@@ -344,7 +400,7 @@ export class TauriClientDatabase implements IClientDatabase {
} catch (e) {
return this.handle_errors("model_nostr_profile_relay_set", opts, e);
};
- };
+ };
public async nostr_profile_relay_unset(opts: INostrProfileRelayRelation): Promise<INostrProfileRelayRelationResolve<IClientDatabaseMessage>> {
try {
@@ -356,4 +412,26 @@ export class TauriClientDatabase implements IClientDatabase {
return this.handle_errors("model_nostr_profile_relay_unset", opts, e);
};
};
+
+ public async trade_product_location_set(opts: ITradeProductLocationRelation): Promise<ITradeProductLocationRelationResolve<IClientDatabaseMessage>> {
+ try {
+ const response = await invoke<any>("model_trade_product_location_set", { opts });
+ if (response === true) return { pass: true };
+ else if (typeof response === "string") return err_msg(response);
+ return err_msg("*-result");
+ } catch (e) {
+ return this.handle_errors("model_trade_product_location_set", opts, e);
+ };
+ };
+
+ public async trade_product_location_unset(opts: ITradeProductLocationRelation): Promise<ITradeProductLocationRelationResolve<IClientDatabaseMessage>> {
+ try {
+ const response = await invoke<any>("model_trade_product_location_unset", { opts });
+ if (response === true) return { pass: true };
+ else if (typeof response === "string") return err_msg(response);
+ return err_msg("*-result");
+ } catch (e) {
+ return this.handle_errors("model_trade_product_location_unset", opts, e);
+ };
+ };
}
\ No newline at end of file
diff --git a/client/src/database/types.ts b/client/src/database/types.ts
@@ -1,4 +1,4 @@
-import type { ILocationGcsAdd, ILocationGcsAddResolve, ILocationGcsDelete, ILocationGcsDeleteResolve, ILocationGcsGet, ILocationGcsGetResolve, ILocationGcsUpdate, ILocationGcsUpdateResolve, INostrProfileAdd, INostrProfileAddResolve, INostrProfileDelete, INostrProfileDeleteResolve, INostrProfileGet, INostrProfileGetResolve, INostrProfileRelayRelation, INostrProfileRelayRelationResolve, INostrProfileUpdate, INostrProfileUpdateResolve, INostrRelayAdd, INostrRelayAddResolve, INostrRelayDelete, INostrRelayDeleteResolve, INostrRelayGet, INostrRelayGetResolve, INostrRelayUpdate, INostrRelayUpdateResolve, ITradeProductAdd, ITradeProductAddResolve, ITradeProductDelete, ITradeProductDeleteResolve, ITradeProductGet, ITradeProductGetResolve, ITradeProductUpdate, ITradeProductUpdateResolve } from "@radroots/models";
+import type { ILocationGcsAdd, ILocationGcsAddResolve, ILocationGcsDelete, ILocationGcsDeleteResolve, ILocationGcsGet, ILocationGcsGetResolve, ILocationGcsUpdate, ILocationGcsUpdateResolve, INostrProfileAdd, INostrProfileAddResolve, INostrProfileDelete, INostrProfileDeleteResolve, INostrProfileGet, INostrProfileGetResolve, INostrProfileRelayRelation, INostrProfileRelayRelationResolve, INostrProfileUpdate, INostrProfileUpdateResolve, INostrRelayAdd, INostrRelayAddResolve, INostrRelayDelete, INostrRelayDeleteResolve, INostrRelayGet, INostrRelayGetResolve, INostrRelayUpdate, INostrRelayUpdateResolve, ITradeProductAdd, ITradeProductAddResolve, ITradeProductDelete, ITradeProductDeleteResolve, ITradeProductGet, ITradeProductGetResolve, ITradeProductLocationRelation, ITradeProductLocationRelationResolve, ITradeProductUpdate, ITradeProductUpdateResolve } from "@radroots/models";
export type IClientDatabaseMessage =
| string
@@ -24,4 +24,6 @@ export type IClientDatabase = {
nostr_relay_update(opts: INostrRelayUpdate): Promise<INostrRelayUpdateResolve<IClientDatabaseMessage>>;
nostr_profile_relay_set(opts: INostrProfileRelayRelation): Promise<INostrProfileRelayRelationResolve<IClientDatabaseMessage>>;
nostr_profile_relay_unset(opts: INostrProfileRelayRelation): Promise<INostrProfileRelayRelationResolve<IClientDatabaseMessage>>;
+ trade_product_location_set(opts: ITradeProductLocationRelation): Promise<ITradeProductLocationRelationResolve<IClientDatabaseMessage>>;
+ trade_product_location_unset(opts: ITradeProductLocationRelation): Promise<ITradeProductLocationRelationResolve<IClientDatabaseMessage>>;
};
\ No newline at end of file