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 () { listAccounts () {
return new Promise((resolve, reject) => { 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 (err) return reject(err)
if (empty(docs)) return reject(new EmptyRecordError('empty')) if (empty(docs)) return reject(new EmptyRecordError('empty'))
resolve(docs) 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) { getAccount (id) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.db.findOne( this.db.findOne(

View File

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