curtain-web-api 1.0.27 → 1.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -188,6 +188,7 @@ class CurtainWebAPI {
188
188
  this.user.access_token = response.data.access;
189
189
  this.user.refresh_token = response.data.refresh;
190
190
  this.user.loginStatus = true;
191
+ console.log(this.user.loginStatus);
191
192
  this.user.saveIntoDB().then();
192
193
  return this.getUserInfo();
193
194
  });
@@ -87,6 +87,47 @@ class User {
87
87
  });
88
88
  }
89
89
  saveIntoDB() {
90
+ this.db.get("user").catch((error) => {
91
+ if (error.name === "not_found") {
92
+ console.log(this.loginStatus);
93
+ return {
94
+ _id: "user",
95
+ access_token: this.access_token,
96
+ refresh_token: this.refresh_token,
97
+ username: this.username,
98
+ loginStatus: this.loginStatus,
99
+ isStaff: this.isStaff,
100
+ id: this.id,
101
+ totalCurtain: this.totalCurtain,
102
+ canDelete: this.canDelete,
103
+ curtainLinkLimit: this.curtainLinkLimit,
104
+ curtainLinkLimitExceeded: this.curtainLinkLimitExceeded,
105
+ lastAccessTokenUpdate: this.lastAccessTokenUpdate,
106
+ lastRefreshTokenUpdate: this.lastRefreshTokenUpdate
107
+ };
108
+ }
109
+ else {
110
+ throw error;
111
+ }
112
+ }).then((doc) => {
113
+ console.log(this.loginStatus);
114
+ return this.db.put({
115
+ _id: "user",
116
+ _rev: doc._rev,
117
+ access_token: this.access_token,
118
+ refresh_token: this.refresh_token,
119
+ username: this.username,
120
+ loginStatus: this.loginStatus,
121
+ isStaff: this.isStaff,
122
+ id: this.id,
123
+ totalCurtain: this.totalCurtain,
124
+ canDelete: this.canDelete,
125
+ curtainLinkLimit: this.curtainLinkLimit,
126
+ curtainLinkLimitExceeded: this.curtainLinkLimitExceeded,
127
+ lastAccessTokenUpdate: this.lastAccessTokenUpdate,
128
+ lastRefreshTokenUpdate: this.lastRefreshTokenUpdate
129
+ });
130
+ });
90
131
  return this.db.put({
91
132
  _id: "user",
92
133
  access_token: this.access_token,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "curtain-web-api",
3
- "version": "1.0.27",
3
+ "version": "1.0.28",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -172,6 +172,7 @@ export class CurtainWebAPI {
172
172
  this.user.access_token = response.data.access;
173
173
  this.user.refresh_token = response.data.refresh;
174
174
  this.user.loginStatus = true;
175
+ console.log(this.user.loginStatus)
175
176
  this.user.saveIntoDB().then();
176
177
  return this.getUserInfo();
177
178
  })
@@ -95,6 +95,46 @@ export class User {
95
95
  }
96
96
 
97
97
  saveIntoDB() {
98
+ this.db.get("user").catch((error) => {
99
+ if (error.name === "not_found") {
100
+ console.log(this.loginStatus)
101
+ return {
102
+ _id: "user",
103
+ access_token: this.access_token,
104
+ refresh_token: this.refresh_token,
105
+ username: this.username,
106
+ loginStatus: this.loginStatus,
107
+ isStaff: this.isStaff,
108
+ id: this.id,
109
+ totalCurtain: this.totalCurtain,
110
+ canDelete: this.canDelete,
111
+ curtainLinkLimit: this.curtainLinkLimit,
112
+ curtainLinkLimitExceeded: this.curtainLinkLimitExceeded,
113
+ lastAccessTokenUpdate: this.lastAccessTokenUpdate,
114
+ lastRefreshTokenUpdate: this.lastRefreshTokenUpdate
115
+ }
116
+ } else {
117
+ throw error
118
+ }
119
+ }).then((doc: any) => {
120
+ console.log(this.loginStatus)
121
+ return this.db.put({
122
+ _id: "user",
123
+ _rev: doc._rev,
124
+ access_token: this.access_token,
125
+ refresh_token: this.refresh_token,
126
+ username: this.username,
127
+ loginStatus: this.loginStatus,
128
+ isStaff: this.isStaff,
129
+ id: this.id,
130
+ totalCurtain: this.totalCurtain,
131
+ canDelete: this.canDelete,
132
+ curtainLinkLimit: this.curtainLinkLimit,
133
+ curtainLinkLimitExceeded: this.curtainLinkLimitExceeded,
134
+ lastAccessTokenUpdate: this.lastAccessTokenUpdate,
135
+ lastRefreshTokenUpdate: this.lastRefreshTokenUpdate
136
+ })
137
+ })
98
138
  return this.db.put({
99
139
  _id: "user",
100
140
  access_token: this.access_token,