Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
srvpro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
srvpro
Commits
6967209c
Commit
6967209c
authored
Nov 15, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
still not finished
parent
07769f24
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
3 deletions
+61
-3
data-manager/DataManager.ts
data-manager/DataManager.ts
+48
-1
data-manager/entities/User.ts
data-manager/entities/User.ts
+5
-1
data-manager/entities/VipKey.ts
data-manager/entities/VipKey.ts
+8
-1
No files found.
data-manager/DataManager.ts
View file @
6967209c
...
@@ -10,6 +10,7 @@ import {DuelLog} from "./entities/DuelLog";
...
@@ -10,6 +10,7 @@ import {DuelLog} from "./entities/DuelLog";
import
{
Deck
}
from
"
./DeckEncoder
"
;
import
{
Deck
}
from
"
./DeckEncoder
"
;
import
{
DuelLogPlayer
}
from
"
./entities/DuelLogPlayer
"
;
import
{
DuelLogPlayer
}
from
"
./entities/DuelLogPlayer
"
;
import
{
User
}
from
"
./entities/User
"
;
import
{
User
}
from
"
./entities/User
"
;
import
{
VipKey
}
from
"
./entities/VipKey
"
;
interface
BasePlayerInfo
{
interface
BasePlayerInfo
{
name
:
string
;
name
:
string
;
...
@@ -304,7 +305,7 @@ export class DataManager {
...
@@ -304,7 +305,7 @@ export class DataManager {
async
getUser
(
key
:
string
)
{
async
getUser
(
key
:
string
)
{
const
repo
=
this
.
db
.
getRepository
(
User
);
const
repo
=
this
.
db
.
getRepository
(
User
);
try
{
try
{
const
user
=
await
repo
.
findOne
(
key
);
const
user
=
await
repo
.
findOne
(
key
,
{
relations
:
[
"
dialogues
"
]}
);
return
user
;
return
user
;
}
catch
(
e
)
{
}
catch
(
e
)
{
this
.
log
.
warn
(
`Failed to fetch user:
${
e
.
toString
()}
`
);
this
.
log
.
warn
(
`Failed to fetch user:
${
e
.
toString
()}
`
);
...
@@ -365,4 +366,50 @@ export class DataManager {
...
@@ -365,4 +366,50 @@ export class DataManager {
});
});
}
}
async
getVipKeys
(
keyType
:
number
)
{
const
repo
=
this
.
db
.
getRepository
(
VipKey
);
const
queryCondition
=
{
type
:
keyType
,
isUsed
:
0
}
try
{
const
keys
=
await
repo
.
find
(
queryCondition
);
return
keys
.
map
(
k
=>
k
.
toJSON
());
}
catch
(
e
)
{
this
.
log
.
warn
(
`Failed to fetch keys of keyType
${
keyType
}
:
${
e
.
toString
()}
`
);
return
[];
}
}
async
useVipKey
(
userKey
:
string
,
vipKeyText
:
string
)
{
let
user
=
await
this
.
getOrCreateUser
(
userKey
);
let
result
=
0
;
await
this
.
db
.
transaction
(
async
(
mdb
)
=>
{
try
{
const
vipKey
=
await
mdb
.
findOne
(
VipKey
,
{
key
:
vipKeyText
,
isUsed
:
0
});
if
(
!
vipKey
)
{
return
;
}
const
keyType
=
vipKey
.
type
;
const
previousDate
=
user
.
vipExpireDate
;
if
(
previousDate
&&
moment
().
isBefore
(
previousDate
))
{
user
.
vipExpireDate
=
moment
(
previousDate
).
add
(
keyType
,
"
d
"
).
toDate
();
}
else
{
user
.
vipExpireDate
=
moment
().
add
(
keyType
,
"
d
"
).
toDate
();
}
user
=
await
mdb
.
save
(
user
);
vipKey
.
isUsed
=
1
;
vipKey
.
usedBy
=
user
;
await
mdb
.
save
(
vipKey
);
result
=
previousDate
?
2
:
1
;
}
catch
(
e
)
{
this
.
log
.
warn
(
`Failed to use VIP key for user
${
userKey
}
${
vipKeyText
}
:
${
e
.
toString
()}
`
);
result
=
0
;
return
;
}
});
return
result
;
}
}
}
data-manager/entities/User.ts
View file @
6967209c
import
{
Column
,
Entity
,
Index
,
OneToMany
,
PrimaryColumn
}
from
"
typeorm
"
;
import
{
Column
,
Entity
,
Index
,
OneToMany
,
PrimaryColumn
}
from
"
typeorm
"
;
import
{
UserDialog
}
from
"
./UserDialog
"
;
import
{
UserDialog
}
from
"
./UserDialog
"
;
import
{
VipKey
}
from
"
./VipKey
"
;
@
Entity
()
@
Entity
()
export
class
User
{
export
class
User
{
...
@@ -11,7 +12,7 @@ export class User {
...
@@ -11,7 +12,7 @@ export class User {
@
Index
()
@
Index
()
@
Column
(
"
datetime
"
,
{
nullable
:
true
})
@
Column
(
"
datetime
"
,
{
nullable
:
true
})
vipExpireDate
:
string
;
vipExpireDate
:
Date
;
@
Column
(
"
text
"
,
{
nullable
:
true
})
@
Column
(
"
text
"
,
{
nullable
:
true
})
victory
:
string
;
victory
:
string
;
...
@@ -21,4 +22,7 @@ export class User {
...
@@ -21,4 +22,7 @@ export class User {
@
OneToMany
(()
=>
UserDialog
,
dialog
=>
dialog
.
user
)
@
OneToMany
(()
=>
UserDialog
,
dialog
=>
dialog
.
user
)
dialogues
:
UserDialog
[];
dialogues
:
UserDialog
[];
@
OneToMany
(()
=>
VipKey
,
vipKey
=>
vipKey
.
usedBy
)
usedKeys
:
VipKey
[];
}
}
data-manager/entities/VipKey.ts
View file @
6967209c
import
{
Column
,
Entity
,
Index
,
PrimaryGeneratedColumn
}
from
"
typeorm
"
;
import
{
Column
,
Entity
,
Index
,
ManyToOne
,
PrimaryGeneratedColumn
}
from
"
typeorm
"
;
import
{
User
}
from
"
./User
"
;
@
Entity
()
@
Entity
()
export
class
VipKey
{
export
class
VipKey
{
...
@@ -12,6 +13,12 @@ export class VipKey {
...
@@ -12,6 +13,12 @@ export class VipKey {
@
Column
(
"
int
"
,
{
unsigned
:
true
})
@
Column
(
"
int
"
,
{
unsigned
:
true
})
type
:
number
;
type
:
number
;
@
Column
(
"
tinyint
"
,
{
unsigned
:
true
})
isUsed
:
number
;
@
ManyToOne
(()
=>
User
,
user
=>
user
.
usedKeys
)
usedBy
:
User
;
toJSON
()
{
toJSON
()
{
return
{
key
:
this
.
key
,
type
:
this
.
type
};
return
{
key
:
this
.
key
,
type
:
this
.
type
};
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment