Skip to content

Commit

Permalink
Fix CI Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mersho committed Aug 30, 2023
1 parent 0da0893 commit a9e6fcb
Show file tree
Hide file tree
Showing 9 changed files with 405 additions and 291 deletions.
399 changes: 203 additions & 196 deletions bot/messages.js → bot/messages.ts

Large diffs are not rendered by default.

56 changes: 0 additions & 56 deletions models/community.js

This file was deleted.

85 changes: 85 additions & 0 deletions models/community.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import mongoose, { Document, Schema, Types } from 'mongoose';

const arrayLimits = (val: any[]): boolean => {
return val.length > 0 && val.length <= 2;
};

const currencyLimits = (val: string): boolean => {
return val.length > 0 && val.length < 10;
};


export interface OrderChannel extends Document {
name: string;
type: string;
}

const OrderChannelSchema = new Schema<OrderChannel>({
name: { type: String, required: true, trim: true },
type: {
type: String,
enum: ['buy', 'sell', 'mixed'],
},
});

export interface usernameId extends Document {
id: string;
username: string;
}

const usernameIdSchema = new Schema<usernameId>({
id: { type: String, required: true },
username: { type: String, required: true, trim: true },
});

export interface Community extends Document {
name: string;
creator_id: string;
group: string;
order_channels: Types.DocumentArray<OrderChannel>;
fee: number;
earnings: number;
orders_to_redeem: number;
dispute_channel: string;
solvers: Types.DocumentArray<usernameId>;
banned_users: Types.DocumentArray<usernameId>;
public: boolean;
currencies: Array<string>;
created_at: Date;
nostr_public_key: string;
}

const CommunitySchema = new Schema<Community>({
name: {
type: String,
unique: true,
maxlength: 30,
trim: true,
required: true,
},
creator_id: { type: String },
group: { type: String, trim: true }, // group Id or public name
order_channels: {
// array of Id or public name of channels
type: [OrderChannelSchema],
validate: [arrayLimits, '{PATH} is not within limits'],
},
fee: { type: Number, min: 0, max: 100, default: 0 },
earnings: { type: Number, default: 0 }, // Sats amount to be paid to the community
orders_to_redeem: { type: Number, default: 0 }, // Number of orders calculated to be redeemed
dispute_channel: { type: String }, // Id or public name, channel to send new disputes
solvers: [usernameIdSchema], // users that are dispute solvers
banned_users: [usernameIdSchema], // users that are banned from the community
public: { type: Boolean, default: true },
currencies: {
type: [String],
required: true,
trim: true,
validate: [currencyLimits, '{PATH} is not within limits'],
},
created_at: { type: Date, default: Date.now },
nostr_public_key: { type: String },
});


module.exports = mongoose.model<Community>('Community', CommunitySchema);
9 changes: 0 additions & 9 deletions models/config.js

This file was deleted.

17 changes: 17 additions & 0 deletions models/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import mongoose, { Document, Schema } from 'mongoose';

export interface IConfig extends Document {
maintenance: boolean;
node_status: string;
node_uri: string;
}


const configSchema = new Schema<IConfig>({
maintenance: { type: Boolean, default: false },
node_status: { type: String, default: 'down' },
node_uri: { type: String },
});


module.exports = mongoose.model<IConfig>('Config', configSchema);
49 changes: 45 additions & 4 deletions models/order.js → models/order.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
const mongoose = require('mongoose');
import mongoose, { Document, Schema } from 'mongoose';

const OrderSchema = new mongoose.Schema({
export interface IOrder extends Document {
description?: string;
amount: number;
max_amount: number;
min_amount: number;
fee: number;
bot_fee: number;
community_fee: number;
routing_fee: number;
hash: string;
secret: string;
creator_id: string;
seller_id: string;
buyer_id: string;
buyer_invoice: string;
buyer_dispute: boolean
seller_dispute: boolean
buyer_cooperativecancel: boolean;
seller_cooperativecancel: boolean;
canceled_by: string
status: string;
type: string;
fiat_amount: number;
fiat_code: string;
payment_method: string;
created_at: Date;
invoice_held_at: Date;
taken_at: Date;
tg_chat_id: string;
tg_order_message: string;
tg_channel_message1: string | null;
range_parent_id: string;
price_from_api: boolean;
price_margin: number;
calculated: boolean;
admin_warned: boolean;
paid_hold_buyer_invoice_updated: boolean;
community_id: string;
is_public: boolean;
}

const orderSchema = new Schema<IOrder>({
description: { type: String, required: true },
amount: {
// amount in satoshis
Expand Down Expand Up @@ -79,7 +120,7 @@ const OrderSchema = new mongoose.Schema({
admin_warned: { type: Boolean, default: false }, // We set this to true when the bot warns admins the order is about to expire
paid_hold_buyer_invoice_updated: { type: Boolean, default: false }, // We set this to true when buyer executes /setinvoice on a order PAID_HOLD_INVOICE
community_id: { type: String },
is_public: { type: Boolean, default: true },
is_public: { type: Boolean, default: true }
});

module.exports = mongoose.model('Order', OrderSchema);
module.exports = mongoose.model<IOrder>('Order', orderSchema);
26 changes: 0 additions & 26 deletions models/pending_payment.js

This file was deleted.

43 changes: 43 additions & 0 deletions models/pending_payment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import mongoose, { Document, Schema } from 'mongoose';

export interface IPendingPayment extends Document {
description: string;
amount: number;
attempts: number;
paid: boolean;
is_invoice_expired: boolean;
payment_request: string;
hash: string;
created_at: Date;
paid_at: Date;
user_id: string;
order_id: string;
community_id: string;
}


const PendingPaymentSchema = new Schema<IPendingPayment>({
description: { type: String },
amount: {
// amount in satoshis
type: Number,
min: [1, 'Minimum amount is 1 sat'],
validate: {
validator: Number.isInteger,
message: '{VALUE} is not an integer value',
},
},
attempts: { type: Number, min: 0, default: 0 },
paid: { type: Boolean, default: false },
is_invoice_expired: { type: Boolean, default: false },
payment_request: { type: String },
hash: { type: String },
created_at: { type: Date, default: Date.now },
paid_at: { type: Date },
user_id: { type: String },
order_id: { type: String },
community_id: { type: String },
});


module.exports = mongoose.model<IPendingPayment>('PendingPayment', PendingPaymentSchema);
12 changes: 12 additions & 0 deletions util/fiatModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export interface Fiat {
symbol: string;
name: string;
symbol_native: string;
decimal_digits: number;
rounding: number;
code: string;
emoji: string;
name_plural: string;
price?: boolean;
locale?: string;
}

0 comments on commit a9e6fcb

Please sign in to comment.