Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitba73ed2

Browse files
committed
added models
1 parent2d4d332 commitba73ed2

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
importBigNumberfrom"bignumber.js";
99
import{buildTradeMsg,flat}from"./utils";
1010
import{MONITORED_TOKENS}from"./data/token";
11+
import{Approve}from"./models";
1112

1213
constMain=async()=>{
1314
constoneInch=newOneInch()

‎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+
interfaceApproveAttrs{
6+
token:Token;
7+
}
8+
9+
// An interface that describes what attributes a transaction model should have
10+
interfaceApproveModelextendsModel<ApproveDoc>{
11+
build(attrs:ApproveAttrs):ApproveDoc;
12+
}
13+
14+
// An interface that descibes single transaction properties
15+
interfaceApproveDocextendsDocument{
16+
token:Token;
17+
}
18+
19+
// Creating transaction schema
20+
constapproveSchema=newSchema(
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+
returnnewApprove(attrs);
38+
};
39+
40+
// Creating transaction model
41+
constApprove=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+
interfaceUserAttrs{
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+
interfaceUserModelextendsModel<UserDoc>{
16+
build(attrs:UserAttrs):UserDoc
17+
}
18+
19+
// An interface that descibes single user properties
20+
interfaceUserDocextendsDocument{
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+
constuserSchema=newSchema({
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)=>{returnnewUser(attrs)})
47+
48+
// Creating user model
49+
constUser=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
exportinterfaceQuote{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp