增加账号删除的功能

This commit is contained in:
CounterFire2023 2023-08-14 14:58:09 +08:00
parent 0141093817
commit d1f3fed196
5 changed files with 56 additions and 3 deletions

1
pm2_release.sh Executable file
View File

@ -0,0 +1 @@
pm2 start npm --name "wallet-svr" --log-date-format "YYYY-MM-DD HH:mm:ss" -- run "prod:api"

View File

@ -22,7 +22,7 @@ let errorRes = function (msg: string) {
* for Alchemy call
*/
class AlchemyOutController extends BaseController {
@role(ROLE_ANON)
// @role(ROLE_ANON)
// @router('post /pay/out/alchemy/buycb')
async alchemyCallback(req, res) {
let { orderNo, status, crypto, network, merchantOrderNo } = req.params

View File

@ -13,7 +13,7 @@ class MainController extends BaseController {
@router('post /wallet/account/reset')
async resetAccount(req, res) {
const user = req.user
let user = req.user
await user.updateOne({ $inc: { accountVersion: 1 } })
return {}
}

View File

@ -3,6 +3,7 @@ import { ZError } from 'common/ZError'
import { router } from 'decorators/router'
import { Wallet } from 'modules/Wallet'
import { WalletBackup } from 'modules/WalletBackup'
import { WalletExt } from 'modules/WalletExt'
import { customAlphabet } from 'nanoid'
import { genRandomString, sha3_256, sha512 } from 'utils/security.util'
@ -66,8 +67,19 @@ class WalletController extends BaseController {
return {}
}
@router('post /wallet/rest')
@router('post /wallet/reset')
async resetWalletInfo(req, res) {
let user = req.user
let record = await Wallet.findOne({ account: user.id })
if (!record) {
throw new ZError(11, 'no wallet found')
}
let data: any = record.toJson()
data.account = user.id
let recordBack = new WalletBackup(data)
await recordBack.save()
record.address = ''
await record.save()
return {}
}

View File

@ -0,0 +1,40 @@
import { getModelForClass, index, modelOptions, mongoose, prop, Severity } from '@typegoose/typegoose'
import { dbconn } from 'decorators/dbconn'
import { BaseModule } from './Base'
@dbconn()
@index({ account: 1 }, { unique: false })
@modelOptions({
schemaOptions: { collection: 'wallet_backup', timestamps: true },
})
class WalletBackupClass extends BaseModule {
@prop({ required: true })
public account!: string
/**
* master key
*/
@prop()
public key: string
@prop()
public address: string
/**
*
*/
@prop()
public salt: string
@prop({ required: true, default: true })
public nweRecord: boolean
public toJson() {
return {
key: this.key,
address: this.address,
salt: this.salt,
}
}
}
export const WalletBackup = getModelForClass(WalletBackupClass, { existingConnection: WalletBackupClass.db })