增加group配置

This commit is contained in:
CounterFire2023 2024-04-18 15:39:06 +08:00
parent 441792a16f
commit b159ef465e
2 changed files with 28 additions and 1 deletions

View File

@ -21,6 +21,24 @@ const nftList = sourceList.map(o => {
}
})
if (process.env.NODE_ENV !== 'production') {
nftList.unshift({
projectName: 'Test',
link: 'https://x.com/sparky-chain',
contract: '0x50a8e60041a206acaa5f844a1104896224be6f38',
collection: 'Test Group01',
guild: '1222509817411665920',
role: '1230421511735738409',
tier: 2,
})
nftList.unshift({
projectName: 'Test',
link: 'https://x.com/sparky-chain',
contract: '0x50a8e60041a206acaa5f844a1104896224be6f38',
collection: 'Test Group02',
guild: '1222509817411665920',
role: '1230421511735738409',
tier: 2,
})
nftList.unshift({
projectName: 'Test',
link: 'https://x.com/sparky-chain',
@ -61,8 +79,9 @@ class NftController extends BaseController {
if (user) {
let records = await NFTHolderRecord.find({ user: user.id })
let recordSet = new Set(records.map(o => o.contract.toLowerCase()))
let groupSet = new Set(records.map(o => o.group))
for (let sub of list) {
list.status = recordSet.has(sub.contract.toLowerCase())
list.status = recordSet.has(sub.contract.toLowerCase()) || groupSet.has(sub.group) ? 1 : 0
}
}
return list
@ -130,6 +149,12 @@ class NftController extends BaseController {
throw new ZError(13, 'already claimed')
}
const cfg = nftMap.get(contract)
if (cfg.group) {
let groupRecord = await NFTHolderRecord.findOne({ user: user.id, group: cfg.group })
if (groupRecord) {
throw new ZError(16, 'already claimed')
}
}
const guild = cfg.guild || DEFAULT_GUILD
let rpcRes = await checkDiscordRole(user.address.toLowerCase(), guild, cfg.role)
console.log('check result:', rpcRes)

View File

@ -20,6 +20,8 @@ class NFTHolderRecordClass extends BaseModule {
public chain: number
@prop({ required: true })
public contract: string
@prop()
public group?: string
@prop({ type: () => [String], default: [] })
public tokenId?: string[]
@prop()