flamerest 1.0.36 → 1.0.39

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.
Files changed (3) hide show
  1. package/REST.d.ts +3 -3
  2. package/REST.js +24 -6
  3. package/package.json +1 -1
package/REST.d.ts CHANGED
@@ -71,7 +71,7 @@ export function create<T>(table: string, values: object): Promise<T>
71
71
  * @param id
72
72
  * @param byFields Если указан, удаляет по этим параметрам
73
73
  */
74
- export function remove(table: string, id: number | string, byFields?: object)
74
+ export function remove(table: string, id: number | string, byFields?: object): Promise<boolean|Array<any>>
75
75
 
76
76
  /**
77
77
  * Редактировать значения
@@ -79,7 +79,7 @@ export function remove(table: string, id: number | string, byFields?: object)
79
79
  * @param ID
80
80
  * @param values
81
81
  */
82
- export function edit(table: string, ID: number | string, values: object)
82
+ export function edit<T>(table: string, ID: number | string, values: object): Promise<T>
83
83
 
84
84
  /**
85
85
  * Получить схемы всех таблиц
@@ -113,7 +113,7 @@ type Authorized = {
113
113
  name: string,
114
114
  role: string
115
115
  };
116
- errors: object|undefined;
116
+ errors: { [key: string]: any };
117
117
  }
118
118
 
119
119
  /**
package/REST.js CHANGED
@@ -398,7 +398,7 @@ class FLAMEREST {
398
398
  * @param id
399
399
  * @param byFields
400
400
  */
401
- remove(table, id = 0, byFields = null) {
401
+ async remove(table, id = 0, byFields = null) {
402
402
 
403
403
  // Нормализуем имена таблиц
404
404
  table = table.replace(/_/g, "");
@@ -406,7 +406,11 @@ class FLAMEREST {
406
406
  let params = {};
407
407
  if(byFields instanceof Object) params = byFields;
408
408
 
409
- return this.request(this.SERVER + '/api/' + this.version + '/' + table + '/delete?id=' + id, JSON.stringify(params), 'DELETE');
409
+ let resp = await this.request(this.SERVER + '/api/' + this.version + '/' + table + '/delete?id=' + id, JSON.stringify(params), 'DELETE');
410
+
411
+ if(resp.status === 204) return true;
412
+
413
+ return resp;
410
414
 
411
415
  }
412
416
 
@@ -443,12 +447,26 @@ class FLAMEREST {
443
447
  return new Promise((resolve, reject) => { resolve(JSON.parse(window.sessionStorage.getItem("crudschema"))) });
444
448
  }
445
449
 
446
- auth(username, password) {
447
- return this.request(this.SERVER + '/auth/auth', JSON.stringify({ login: username, password: password }), 'POST');
450
+ async auth(username, password) {
451
+
452
+ let resp = await this.request(this.SERVER + '/auth/auth', JSON.stringify({ login: username, password: password }), 'POST');
453
+
454
+ if(resp.errors) return resp;
455
+ if(resp.data.length === 0) {resp.errors = []; return resp;}
456
+
457
+ return resp.data;
458
+
448
459
  }
449
460
 
450
- signup(username, password) {
451
- return this.request(this.SERVER + '/auth/signup', JSON.stringify({ login: username, password: password }), 'POST');
461
+ async signup(username, password) {
462
+
463
+ let resp = await this.request(this.SERVER + '/auth/signup', JSON.stringify({ login: username, password: password }), 'POST');
464
+
465
+ if(resp.errors) return resp;
466
+ if(resp.data.length === 0) {resp.errors = []; return resp;}
467
+
468
+ return resp.data;
469
+
452
470
  }
453
471
 
454
472
  logout() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flamerest",
3
- "version": "1.0.36",
3
+ "version": "1.0.39",
4
4
  "description": "",
5
5
  "main": "REST.js",
6
6
  "typings": "./REST.d.ts",