Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 26, 2020
2 parents 8cd0ff8 + 0f68ab6 commit f4e41d9
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions packages/plugin-mongo/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,23 @@ extendDatabase(MongoDatabase, {
},

async setUser(userId, data) {
const $set = { ...data }
if ($set.timers) {
for (const key in $set.timers) {
if (key === '$date') $set['timers._date'] = $set.timers.$date
else $set[`timers.${key.replace(/\./gmi, '_')}`] = $set.timers[key]
const $set: any = { ...data }
delete $set.timers
delete $set.usage
if (data.timers) {
$set.timers = {}
for (const key in data.timers) {
if (key === '$date') $set.timer._date = data.timers.$date
else $set.timer[key.replace(/\./gmi, '_')] = data.timers[key]
}
}
if ($set.usage) {
for (const key in $set.usage) {
if (key === '$date') $set['usage._date'] = $set.usage.$date
else $set[`usage.${key.replace(/\./gmi, '_')}`] = $set.usage[key]
if (data.usage) {
$set.usage = {}
for (const key in data.usage) {
if (key === '$date') $set.usage._date = data.usage.$date
else $set.usage[key.replace(/\./gmi, '_')] = data.usage[key]
}
}
delete $set.timers
delete $set.usage
await this.user.updateOne({ _id: userId }, { $set }, { upsert: true })
},

Expand Down

0 comments on commit f4e41d9

Please sign in to comment.