20 lines
602 B
JavaScript
20 lines
602 B
JavaScript
const crypto = require('crypto')
|
|
|
|
const memberKey = (openid) =>
|
|
crypto.createHash('sha256').update(String(openid || '')).digest('hex')
|
|
|
|
const publicEntry = (entry) => {
|
|
if (!entry) return null
|
|
const { memberKey: _memberKey, openid: _openid, ...publicData } = entry
|
|
return publicData
|
|
}
|
|
|
|
const publicRanked = (ranked) => (ranked || []).map(publicEntry)
|
|
|
|
const findMyEntry = (ranked, key) => {
|
|
const item = (ranked || []).find(entry => entry.memberKey === key)
|
|
return item ? { ...publicEntry(item), isMe: true } : null
|
|
}
|
|
|
|
module.exports = { memberKey, publicEntry, publicRanked, findMyEntry }
|