Skip to content

Commit

Permalink
feat(settings) site setting resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
ceddybi committed Apr 10, 2024
1 parent e7f223c commit 619fdf4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { getSocialResolvers } from "@roadmanjs/social";
import { mediaRoadman } from './media/media.app';
import { walletRouter as moneroxWalletRouter } from "@roadmanjs/monerox";
import { DisputeAdminResolver, DisputesResolver } from './disputes';
import AdminSettingsResolver from './settings/settings.resolver.admin';

const resolvers = [
...getAuthResolvers(),
Expand All @@ -48,6 +49,7 @@ const resolvers = [
CountryResolver,
VendorResolver,
SettingsResolver,
AdminSettingsResolver,
TransactionDefaultResolver,
PgpResolver, UserAuthResolver, UserAuthPwResolver, NotificationResolver, BadgeResolver, DisputeAdminResolver, DisputesResolver
];
Expand Down
2 changes: 1 addition & 1 deletion src/order/order.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export class OrderResolver {
};

const { price: adPriceUsd } = ad;
const feePerc = siteSettings.feePrices.checkoutFeePerc;
const feePerc = siteSettings.feePrices?.checkoutFeePerc || 0;
const priceXQtyUsd = adPriceUsd * quantity;
const feeUsd = (feePerc / 100) * priceXQtyUsd;
const orderPriceTotalUsd = priceXQtyUsd + feeUsd;
Expand Down
23 changes: 19 additions & 4 deletions src/settings/settings.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Field, InputType, Model, ObjectType } from "couchset";

@InputType("WithdrawMinInput")
@ObjectType()
class WithdrawMin {
@Field(() => Number, { nullable: false })
Expand All @@ -10,6 +11,7 @@ class WithdrawMin {

};

@InputType("FeePricesInput")
@ObjectType()
export class FeePrices {
@Field(() => WithdrawMin, { nullable: false })
Expand All @@ -25,14 +27,15 @@ export class FeePrices {
@InputType("SiteSettingsInput")
@ObjectType()
export class SiteSettings {
@Field(() => String, { nullable: false })
@Field(() => String, { nullable: true })
id: string = "";

@Field(() => Number, { nullable: false })
@Field(() => Number, { nullable: true })
vendorBond: number = 600;

@Field(() => FeePrices, { nullable: false })
feePrices: FeePrices = null as any;
// @deprecated
@Field(() => FeePrices, { nullable: true })
feePrices?: FeePrices = null as any;

@Field(() => Number, { nullable: true })
vendorCount?: number = 0;
Expand All @@ -55,6 +58,18 @@ export class SiteSettings {
@Field(() => String, { nullable: true })
description?: string = "";

@Field(() => Number, { nullable: true })
WITHDRAW_FEE_PERC?: number = 0;

@Field(() => Number, { nullable: true })
CHECKOUT_FEE_PERC?: number = 0;

@Field(() => Number, { nullable: true })
XMR_WITHDRAW_MIN?: number = 0;

@Field(() => Number, { nullable: true })
BTC_WITHDRAW_MIN?: number = 0.000101;

@Field(() => Boolean, { nullable: true })
ENABLE_BTC?: boolean = false;

Expand Down
3 changes: 2 additions & 1 deletion src/settings/settings.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import { isAuth } from "@roadmanjs/auth";
@Resolver()
export class SettingsResolver {

// @deprecated
@Query(() => FeePrices, { nullable: false })
@UseMiddleware(isAuth)
async getFeePrices(): Promise<FeePrices> {
const siteSettings = await getSiteSettings(true);
return siteSettings?.feePrices ? siteSettings.feePrices : initSiteSettings.feePrices;
return (siteSettings?.feePrices ? siteSettings.feePrices : initSiteSettings.feePrices) as any;
}

@Query(() => SiteSettings, { nullable: false })
Expand Down

0 comments on commit 619fdf4

Please sign in to comment.