1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2025-02-09 08:18:44 +01:00

refs #100 Set order when save account record

This commit is contained in:
AkiraFukushima 2018-04-01 22:48:54 +09:00
parent 1527f1dcaf
commit 3839e6c3e8
2 changed files with 13 additions and 3 deletions

View File

@ -17,7 +17,7 @@ export default class Account {
listAccounts () {
return new Promise((resolve, reject) => {
this.db.find({accessToken: { $ne: '' }}, (err, docs) => {
this.db.find({accessToken: { $ne: '' }}).sort({ order: 1 }).exec((err, docs) => {
if (err) return reject(err)
if (empty(docs)) return reject(new EmptyRecordError('empty'))
resolve(docs)
@ -25,6 +25,15 @@ export default class Account {
})
}
countAuthorizedAccounts () {
return new Promise((resolve, reject) => {
this.db.count({accessToken: { $ne: '' }}, (err, count) => {
if (err) return reject(err)
resolve(count)
})
})
}
getAccount (id) {
return new Promise((resolve, reject) => {
this.db.findOne(

View File

@ -26,7 +26,7 @@ export default class Authentication {
this.clientId = res.client_id
this.clientSecret = res.client_secret
// TODO: Save order number
const count = await this.db.countAuthorizedAccounts()
const json = {
baseURL: this.baseURL,
domain: this.domain,
@ -34,7 +34,8 @@ export default class Authentication {
clientSecret: this.clientSecret,
accessToken: '',
username: '',
accountId: ''
accountId: '',
order: count + 1
}
await this.db.insertAccount(json)
const url = await Mastodon.getAuthorizationUrl(this.clientId, this.clientSecret, this.baseURL)