Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit ba73ed2

Browse files
committed
added models
1 parent 2d4d332 commit ba73ed2

File tree

5 files changed

+98
-1
lines changed

5 files changed

+98
-1
lines changed

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const chalkTable = require('chalk-table');
88
import BigNumber from "bignumber.js";
99
import { buildTradeMsg, flat } from "./utils";
1010
import { MONITORED_TOKENS } from "./data/token";
11+
import { Approve } from "./models";
1112

1213
const Main = async () => {
1314
const oneInch = new OneInch()

src/models/approve.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Model, Document, model, Schema } from "mongoose";
2+
import { Token } from "../types";
3+
4+
// An interface that describes attributes that a transaction should have
5+
interface ApproveAttrs {
6+
token: Token;
7+
}
8+
9+
// An interface that describes what attributes a transaction model should have
10+
interface ApproveModel extends Model<ApproveDoc> {
11+
build(attrs: ApproveAttrs): ApproveDoc;
12+
}
13+
14+
// An interface that descibes single transaction properties
15+
interface ApproveDoc extends Document {
16+
token: Token;
17+
}
18+
19+
// Creating transaction schema
20+
const approveSchema = new Schema(
21+
{
22+
token: {
23+
type: {
24+
name: String,
25+
symbol: String,
26+
address: String
27+
}, unique: true
28+
},
29+
},
30+
{
31+
timestamps: true,
32+
}
33+
);
34+
35+
// Statics
36+
approveSchema.statics.build = (attrs: ApproveAttrs) => {
37+
return new Approve(attrs);
38+
};
39+
40+
// Creating transaction model
41+
const Approve = model<ApproveDoc & ApproveModel>("Approve", approveSchema);
42+
43+
export { Approve, ApproveDoc };

src/models/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './approve'
2+
export * from './user'

src/models/user.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Schema, model, Model } from 'mongoose';
2+
3+
// An interface that describes attributes that a user should have
4+
interface UserAttrs {
5+
tg_id: number;
6+
first_name?: string;
7+
last_name?: string;
8+
username?: string;
9+
is_bot: boolean;
10+
is_active?: boolean;
11+
bot_name?: string;
12+
}
13+
14+
// An interface that describes what attributes a user model should have
15+
interface UserModel extends Model<UserDoc> {
16+
build(attrs: UserAttrs): UserDoc
17+
}
18+
19+
// An interface that descibes single user properties
20+
interface UserDoc extends Document {
21+
tg_id: number;
22+
first_name?: string;
23+
last_name?: string;
24+
username?: string;
25+
is_bot: boolean;
26+
is_active?: boolean;
27+
last_action?: string;
28+
created_at?: Date;
29+
bot_name?: string;
30+
}
31+
32+
// Creating user schema
33+
const userSchema = new Schema({
34+
tg_id: { type: Number },
35+
is_bot: { type: Boolean },
36+
first_name: { type: String },
37+
last_name: { type: String },
38+
username: { type: String },
39+
bot_name: { type: String },
40+
is_active: { type: Boolean, default: false },
41+
last_action: { type: String },
42+
created_at: { type: Date, default: Date.now }
43+
44+
})
45+
// Statics
46+
userSchema.static('build', (attrs: UserAttrs) => { return new User(attrs) })
47+
48+
// Creating user model
49+
const User = model<UserDoc & UserModel>('User', userSchema)
50+
51+
export { User, UserAttrs, UserDoc }

src/types/1inch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export interface Token {
22
symbol: string,
33
name: string,
44
address: string,
5-
decimals: number,
5+
decimals?: number,
66
logoURI?: string
77
}
88
export interface Quote {

0 commit comments

Comments
 (0)